Module: IndonesianStemmer::MorphologicalUtility::InstanceMethods

Defined in:
lib/indonesian_stemmer/morphological_utility.rb

Instance Method Summary collapse

Instance Method Details

#remove_first_order_prefix(word) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 109

def remove_first_order_prefix(word)
  @number_of_syllables ||= total_syllables(word)

  previous_word = word.dup
  remove_and_substitute_characters_matching_collection(
      word, collection_for(:special_first_order_prefix), :start )
  return word if previous_word != word

  remove_characters_matching_collection( word,
                                        collection_for(:first_order_prefix),
                                        :start )
end

#remove_particle(word) ⇒ Object



95
96
97
98
99
100
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 95

def remove_particle(word)
  @number_of_syllables ||= total_syllables(word)
  remove_characters_matching_collection(word,
                                        collection_for(:particle),
                                        :end )
end

#remove_possessive_pronoun(word) ⇒ Object



102
103
104
105
106
107
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 102

def remove_possessive_pronoun(word)
  @number_of_syllables ||= total_syllables(word)
  remove_characters_matching_collection(word,
                                        collection_for(:possessive_pronoun),
                                        :end )
end

#remove_second_order_prefix(word) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 122

def remove_second_order_prefix(word)
  @number_of_syllables ||= total_syllables(word)
  word_size = word.size

  if SPECIAL_SECOND_ORDER_PREFIX_WORDS.include?(word)
    @flags ||= REMOVED_BER if word[0..1] == 'be'
    reduce_syllable
    slice_word_at_position(word, 3, :start)
    return word
  end

  if starts_with?(word, word_size, 'be') && word_size > 4 && !is_vowel?(word[2]) && word[3..4] == 'er'
    @flags ||= REMOVED_BER
    reduce_syllable
    slice_word_at_position(word, 2, :start)
    return word
  end

  remove_characters_matching_collection(word,
                                        collection_for(:non_special_second_order_prefix),
                                        :start)
end

#remove_suffix(word) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 145

def remove_suffix(word)
  @number_of_syllables ||= total_syllables(word)

  SUFFIX_CHARACTERS.each do |character|
    constants_to_check = case character
    when 'kan'
      [REMOVED_KE, REMOVED_PENG, REMOVED_PE]
    when 'an'
      [REMOVED_DI, REMOVED_MENG, REMOVED_TER]
    when 'i'
      [REMOVED_BER, REMOVED_KE, REMOVED_PENG]
    end

    if ends_with?(word, word.size, character) &&
          constants_to_check.all? { |c| (@flags & c) == 0 }
      reduce_syllable
      slice_word_at_position(word, character.size, :end)
      return word
    end
  end

  word
end

#total_syllables(word) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 87

def total_syllables(word)
  result = 0
  word.size.times do |i|
    result += 1 if is_vowel?(word[i])
  end
  result
end