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



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 59

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



45
46
47
48
49
50
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 45

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



52
53
54
55
56
57
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 52

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 72

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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 95

def remove_suffix(word)
  return word if ambiguous_with_suffices_ending_words?(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



37
38
39
40
41
42
43
# File 'lib/indonesian_stemmer/morphological_utility.rb', line 37

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