Sha256: f80d58669d7cfbaba190487d37b1036ebd24eab4a6c57a28c12ecd418569be9c

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module Sastrawi
  module Stemmer
    module Context
      module Visitor
        class PrefixDisambiguator
          attr_reader :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(/#{Regexp.quote(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

5 entries across 5 versions & 1 rubygems

Version Path
sastrawi-0.1.4 lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb
sastrawi-0.1.3 lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb
sastrawi-0.1.2 lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb
sastrawi-0.1.1 lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb
sastrawi-0.1.0 lib/sastrawi/stemmer/context/visitor/prefix_disambiguator.rb