Class: Brstemmer::Stemmer
- Inherits:
-
Object
- Object
- Brstemmer::Stemmer
- Defined in:
- lib/brstemmer.rb
Instance Method Summary collapse
- #apply_rules_by_name(name) ⇒ Object
-
#apply_suffix(suffix, size, replaced = '', excpts) ⇒ Object
@params: suffix => Suffix to remove size => Minimal size of stem replaced => Replace suffix excpt => Exceptions words or suffix list.
-
#initialize(word) ⇒ Stemmer
constructor
A new instance of Stemmer.
- #render ⇒ Object
Constructor Details
#initialize(word) ⇒ Stemmer
Returns a new instance of Stemmer.
519 520 521 522 523 524 525 |
# File 'lib/brstemmer.rb', line 519 def initialize word @suffix_removed = false @word = word @rules = RULES.freeze self end |
Instance Method Details
#apply_rules_by_name(name) ⇒ Object
540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/brstemmer.rb', line 540 def apply_rules_by_name(name) rules = @rules.detect { |rule| rule[:properties][:name] == name } rules[:rules].each do |rule| if rule[2].nil? self.apply_suffix rule[0], rule[1], rule[3] else self.apply_suffix rule[0], rule[1], rule[2], rule[3] end end @word end |
#apply_suffix(suffix, size, replaced = '', excpts) ⇒ Object
@params:
suffix => Suffix to remove
size => Minimal size of stem
replaced => Replace suffix
excpt => Exceptions words or suffix list
558 559 560 561 562 563 564 565 566 |
# File 'lib/brstemmer.rb', line 558 def apply_suffix(suffix, size, replaced='', excpts) aux_word = @word if @word =~ /#{suffix}$/ @word.gsub!(/#{suffix}$/, replaced) if (not excpts.nil? and excpts.detect { |expt| @word == expt }.nil? or excpts.nil?) and @word.length - suffix.length >= size end @suffix_removed = true if aux_word != @word end |
#render ⇒ Object
527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/brstemmer.rb', line 527 def render @word.downcase! self.apply_rules_by_name('plural_reduction') if @word[-1] == 's' self.apply_rules_by_name('adverb_reduction') self.apply_rules_by_name('feminine_reduction') if @word[-1] == 'a' or @word[-1] == "ã" self.apply_rules_by_name('augmentative_reduction') self.apply_rules_by_name('noun_reduction') self.apply_rules_by_name('verb_reduction') unless @suffix_removed self.apply_rules_by_name('vowel_reduction') unless @suffix_removed self.apply_rules_by_name('accent_reduction') end |