Class: MiniSearch::Stemmer::Portuguese

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_search/stemmer/portuguese.rb

Overview

Implementation of the algorithm for the RSLP Stemmer which was presented by the paper ‘A Stemming Algorithm for the Portuguese Language’.

In Proceedings of the SPIRE Conference, Laguna de San Raphael, Chile, November 13-15, 2001, written by Viviane Moreira Orengo and Christian Huyck.

More info: www.inf.ufrgs.br/~viviane/rslp/index.htm Datasets got from: www.kaggle.com/nltkdata/rslp-stemmer

Instance Method Summary collapse

Constructor Details

#initializePortuguese

Returns a new instance of Portuguese.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mini_search/stemmer/portuguese.rb', line 13

def initialize
  @rules_sets = {
    'plural_reduction' => plural_reduction,
    'feminine_reduction' => feminine_reduction,
    'augmentative_diminutive_reduction' => augmentative_diminutive_reduction,
    'adverb_reduction' => adverb_reduction,
    'noun_suffix_reduction' => noun_suffix_reduction,
    'verb_suffix_reduction' => verb_suffix_reduction,
    'vowel_removal' => vowel_removal
  }
end

Instance Method Details

#stem(word) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mini_search/stemmer/portuguese.rb', line 25

def stem(word)
  if word.end_with?('s')
    word = apply_rule('plural_reduction', word)
  end

  if word.end_with?('a')
    word = apply_rule('feminine_reduction', word)
  end

  word = apply_rule('augmentative_diminutive_reduction', word)

  word = apply_rule('adverb_reduction', word)

  prev_word = word
  word = apply_rule('noun_suffix_reduction', word)

  if word == prev_word
    prev_word = word
    word = apply_rule('verb_suffix_reduction', word)

    if word == prev_word
      word = apply_rule('vowel_removal', word)
    end
  end

  word
end