Sha256: 85817b780cdd88b51f632747f1f6044c3881c3bccd0414476735a5e7fbabdf61

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module Sastrawi
  module Stemmer
    module Context
      module Visitor
        class PrefixDisambiguator
          attr_accessor :disambiguators

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

            add_disambiguators(disambiguators)
          end

          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(result, '')

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

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sastrawi-0.1.0.pre lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb