DictionaryNameFinder implements TokenNameFinder { public Span[] find(String[] textTokenized) { List<Span> namesFound = new LinkedList<Span>(); for (int offsetFrom = 0; offsetFrom < textTokenized.length; offsetFrom++) { Span nameFound = null; String tokensSearching[] = new String[] {}; for (int offsetTo = offsetFrom; offsetTo < textTokenized.length; offsetTo++) { int lengthSearching = offsetTo - offsetFrom + 1; if (lengthSearching > mDictionary.getMaxTokenCount()) { break; } else { tokensSearching = new String[lengthSearching]; System.arraycopy(textTokenized, offsetFrom, tokensSearching, 0, lengthSearching); StringList entryForSearch = new StringList(tokensSearching); if (mDictionary.contains(entryForSearch)) { nameFound = new Span(offsetFrom, offsetTo + 1, type); } } } if (nameFound != null) { namesFound.add(nameFound); offsetFrom += (nameFound.length() - 1); } } return namesFound.toArray(new Span[namesFound.size()]); } DictionaryNameFinder(Dictionary dictionary, String type);  DictionaryNameFinder(Dictionary dictionary); Span[] find(String[] textTokenized); void clearAdaptiveData();  }
@Test public void testSingleTokeNameAtSentenceStart() { String sentence = "Max a b c d"; SimpleTokenizer tokenizer = SimpleTokenizer.INSTANCE; String tokens[] = tokenizer.tokenize(sentence); Span names[] = mNameFinder.find(tokens); assertTrue(names.length == 1); assertTrue(names[0].getStart() == 0 && names[0].getEnd() == 1); }
@Test public void testSingleTokeNameInsideSentence() { String sentence = "a b Max c d"; SimpleTokenizer tokenizer = SimpleTokenizer.INSTANCE; String tokens[] = tokenizer.tokenize(sentence); Span names[] = mNameFinder.find(tokens); assertTrue(names.length == 1); assertTrue(names[0].getStart() == 2 && names[0].getEnd() == 3); }
@Test public void testSingleTokeNameAtSentenceEnd() { String sentence = "a b c Max"; SimpleTokenizer tokenizer = SimpleTokenizer.INSTANCE; String tokens[] = tokenizer.tokenize(sentence); Span names[] = mNameFinder.find(tokens); assertTrue(names.length == 1); assertTrue(names[0].getStart() == 3 && names[0].getEnd() == 4); }
@Test public void testLastMatchingTokenNameIsChoosen() { String sentence[] = {"a", "b", "c", "Vanessa"}; Span names[] = mNameFinder.find(sentence); assertTrue(names.length == 1); assertTrue(names[0].getStart() == 3 && names[0].getEnd() == 4); }
@Test public void testLongerTokenNameIsPreferred() { String sentence[] = {"a", "b", "c", "Vanessa", "Williams"}; Span names[] = mNameFinder.find(sentence); assertTrue(names.length == 1); assertTrue(names[0].getStart() == 3 && names[0].getEnd() == 5); }
@Test public void testCaseSensitivity() { String sentence[] = {"a", "b", "c", "vanessa", "williams"}; Span names[] = mNameFinder.find(sentence); assertTrue(names.length == 1); assertTrue(names[0].getStart() == 3 && names[0].getEnd() == 5); }
@Test public void testCaseLongerEntry() { String sentence[] = {"a", "b", "michael", "jordan"}; Span names[] = mNameFinder.find(sentence); assertTrue(names.length == 1); assertTrue(names[0].length() == 2); }