Sha256: 11c7d17fc68ddb3b334fa9c0b25cfc19f999c2128bfb67d5c71abddc7661cdde

Contents?: true

Size: 1.33 KB

Versions: 27

Compression:

Stored size: 1.33 KB

Contents

require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
require 'rbbt/ner/ngram_prefix_dictionary'
require 'rbbt/util/tmpfile'

class TestNGramPrefixDictionary < Test::Unit::TestCase

  def test_match
    lexicon =<<-EOF
C1;aa;AA;bb b
C2;11;22;3 3;bb
    EOF

    TmpFile.with_file(lexicon) do |file|
      index = NGramPrefixDictionary.new(TSV.open(file, :flat, :sep => ';'), "test")

      matches = index.match(' asdfa dsf asdf aa asdfasdf ')
      assert matches.select{|m| m.code.include? 'C1'}.any?
    end
  end

  def test_case_insensitive_match
    lexicon =<<-EOF
C1;aa
C2;bb
    EOF

    TmpFile.with_file(lexicon) do |file|
      index = NGramPrefixDictionary.new(TSV.open(file, :flat, :sep => ';'), "test", true)

      matches = index.match('AA oo')
      assert matches.select{|m| m.code.include? 'C1'}.any?
      assert matches.include? 'AA'

      matches = index.match('AA')
      assert matches.select{|m| m.code.include? 'C1'}.any?
      assert matches.include? 'AA'

    end
  end


  def test_stream
    lexicon =<<-EOF
C1;aa;AA;bb b
C2;11;22;3 3;bb
    EOF

    TmpFile.with_file(lexicon.gsub(/;/,"\t")) do |file|
      index = NGramPrefixDictionary.new(file, "test")
      matches = index.match(' asdfa dsf asdf aa asdfasdf ')
      assert matches.select{|m| m.code.include? 'C1'}.any?
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rbbt-text-1.5.2 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.5.1 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.5.0 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.4.0 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.11 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.10 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.9 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.8 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.7 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.6 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.5 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.4 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.3 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.2 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.1 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.3.0 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.2.0 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.1.9 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.1.8 test/rbbt/ner/test_ngram_prefix_dictionary.rb
rbbt-text-1.1.7 test/rbbt/ner/test_ngram_prefix_dictionary.rb