Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactor #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions lib/turkish_stemmer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@ def stem(original_word)
# Preprocess
return original_word if !proceed_to_stem?(original_word)

word = original_word.dup

# Process
stems = []
stems << nominal_verbs_suffix_machine { word }
stems << original_word
stems.flatten!.uniq!
stems << stems.map { |word| noun_suffix_machine { word }}
stems << original_word
stems.flatten!.uniq!
stems << stems.map { |word| derivational_suffix_machine { word }}

# Postprocess
# set of stem candidates
stems = [original_word, *nominal_verbs_suffix_machine(original_word.dup)]
noun_suffix_stems = stems.map(&method(:noun_suffix_machine)).flatten
stems.push(*noun_suffix_stems)
derivational_suffix_stems = stems.map(&method(:derivational_suffix_machine))
stems.push(*derivational_suffix_stems)
stems.uniq!

# Postprocess: filter and choose among the stem candidates
stem_post_process(stems, original_word)
end

Expand Down Expand Up @@ -349,20 +346,20 @@ def last_consonant!(word)
end

# Helper method. This is just a shortcut.
def nominal_verbs_suffix_machine
affix_morphological_stripper(yield, states: self::NOMINAL_VERB_STATES,
def nominal_verbs_suffix_machine(term)
affix_morphological_stripper(term, states: self::NOMINAL_VERB_STATES,
suffixes: self::NOMINAL_VERB_SUFFIXES)
end

# Helper method. This is just a shortcut.
def noun_suffix_machine
affix_morphological_stripper(yield, states: self::NOUN_STATES,
def noun_suffix_machine(term)
affix_morphological_stripper(term, states: self::NOUN_STATES,
suffixes: self::NOUN_SUFFIXES)
end

# Helper method
def derivational_suffix_machine
affix_morphological_stripper(yield, states: self::DERIVATIONAL_STATES,
def derivational_suffix_machine(term)
affix_morphological_stripper(term, states: self::DERIVATIONAL_STATES,
suffixes: self::DERIVATIONAL_SUFFIXES)
end

Expand Down