use of com.hankcs.hanlp.algoritm.ahocorasick.trie.Emit in project HanLP by hankcs.
the class AhoCorasickDoubleArrayTrieTest method testTwoAC.
public void testTwoAC() throws Exception {
TreeMap<String, String> map = new TreeMap<String, String>();
IOUtil.LineIterator iterator = new IOUtil.LineIterator("data/dictionary/CoreNatureDictionary.mini.txt");
while (iterator.hasNext()) {
String line = iterator.next().split("\\s")[0];
map.put(line, line);
}
Trie trie = new Trie();
trie.addAllKeyword(map.keySet());
AhoCorasickDoubleArrayTrie<String> act = new AhoCorasickDoubleArrayTrie<String>();
act.build(map);
for (String key : map.keySet()) {
Collection<Emit> emits = trie.parseText(key);
Set<String> otherSet = new HashSet<String>();
for (Emit emit : emits) {
otherSet.add(emit.getKeyword() + emit.getEnd());
}
List<AhoCorasickDoubleArrayTrie<String>.Hit<String>> entries = act.parseText(key);
Set<String> mySet = new HashSet<String>();
for (AhoCorasickDoubleArrayTrie<String>.Hit<String> entry : entries) {
mySet.add(entry.value + (entry.end - 1));
}
assertEquals(otherSet, mySet);
}
}
use of com.hankcs.hanlp.algoritm.ahocorasick.trie.Emit in project HanLP by hankcs.
the class AhoCorasickDoubleArrayTrieTest method testAC.
public void testAC() throws Exception {
Trie trie = new Trie();
trie.addKeyword("hers");
trie.addKeyword("his");
trie.addKeyword("she");
trie.addKeyword("he");
Collection<Emit> emits = trie.parseText("ushers");
System.out.println(emits);
}
Aggregations