Class: Sastrawi::Stemmer::Context::Visitor::PrefixDisambiguator

Inherits:
Object
  • Object
show all
Defined in:
lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(disambiguators = []) ⇒ PrefixDisambiguator

Returns a new instance of PrefixDisambiguator.



8
9
10
11
12
# File 'lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb', line 8

def initialize(disambiguators = [])
  @disambiguators = []

  add_disambiguators(disambiguators)
end

Instance Attribute Details

#disambiguatorsObject (readonly)

Returns the value of attribute disambiguators.



6
7
8
# File 'lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb', line 6

def disambiguators
  @disambiguators
end

Instance Method Details

#add_disambiguator(disambiguator) ⇒ Object



39
40
41
# File 'lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb', line 39

def add_disambiguator(disambiguator)
  @disambiguators.push(disambiguator)
end

#add_disambiguators(disambiguators) ⇒ Object



33
34
35
36
37
# File 'lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb', line 33

def add_disambiguators(disambiguators)
  disambiguators.each do |disambiguator|
    add_disambiguator(disambiguator)
  end
end

#visit(context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb', line 14

def visit(context)
  result = nil

  @disambiguators.each do |disambiguator|
    result = disambiguator.disambiguate(context.current_word)

    break if context.dictionary.contains?(result)
  end

  return if result.nil?

  removed_part = context.current_word.sub(/#{Regexp.quote(result)}/, '')

  removal = Removal.new(self, context.current_word, result, removed_part, 'DP')

  context.add_removal(removal)
  context.current_word = result
end