use of org.trie4j.Trie in project trie4j by takawitter.
the class LongsConstantTimeSelect0TailLOUDSTrieWithConcatTailArrayTest method test.
@Test
public void test() throws Exception {
String[] words = { "こんにちは", "さようなら", "おはよう", "おおきなかぶ", "おおやまざき" };
Trie trie = new PatriciaTrie();
for (String w : words) trie.insert(w);
Trie lt = new TailLOUDSTrie(trie);
// Algorithms.dump(lt.getRoot(), new OutputStreamWriter(System.out));
for (String w : words) {
Assert.assertTrue(w, lt.contains(w));
}
Assert.assertFalse(lt.contains("おやすみなさい"));
StringBuilder b = new StringBuilder();
Node[] children = lt.getRoot().getChildren();
for (Node n : children) {
char[] letters = n.getLetters();
b.append(letters[0]);
}
Assert.assertEquals("おこさ", b.toString());
}
use of org.trie4j.Trie in project trie4j by takawitter.
the class TailLOUDSTrieWithConcatTailArrayTest method test.
@Test
public void test() throws Exception {
String[] words = { "こんにちは", "さようなら", "おはよう", "おおきなかぶ", "おおやまざき" };
Trie lt = trieWithWords(words);
// Algorithms.dump(lt.getRoot(), new OutputStreamWriter(System.out));
for (String w : words) {
Assert.assertTrue(w, lt.contains(w));
}
Assert.assertFalse(lt.contains("おやすみなさい"));
StringBuilder b = new StringBuilder();
Node[] children = lt.getRoot().getChildren();
for (Node n : children) {
char[] letters = n.getLetters();
b.append(letters[0]);
}
Assert.assertEquals("おこさ", b.toString());
}
use of org.trie4j.Trie in project trie4j by takawitter.
the class LongsTailLOUDSPPTrieWithSuffixTrieDenseTailArrayWikipediaSerializeTest method secondTrie.
@Override
protected Trie secondTrie(Trie firstTrie) {
Trie t = new TailLOUDSTrie(firstTrie, new LOUDSPPBvTree(new LongsRank0OnlySuccinctBitVector(), new LongsSuccinctBitVector()), new SuffixTrieDenseTailArrayBuilder());
t.trimToSize();
return t;
}
use of org.trie4j.Trie in project trie4j by takawitter.
the class TailLOUDSPPTrieWithConcatTailArrayTest method test_save_load.
@Test
public void test_save_load() throws Exception {
String[] words = { "こんにちは", "さようなら", "おはよう", "おおきなかぶ", "おおやまざき" };
Trie trie = new PatriciaTrie(words);
TailLOUDSTrie lt = new TailLOUDSTrie(trie, new LOUDSPPBvTree(trie.nodeSize()));
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
lt.writeExternal(oos);
oos.flush();
lt = new TailLOUDSTrie(new PatriciaTrie(), new LOUDSPPBvTree());
lt.readExternal(new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())));
for (String w : words) {
Assert.assertTrue(lt.contains(w));
}
Assert.assertFalse(lt.contains("おやすみなさい"));
}
StringBuilder b = new StringBuilder();
Node[] children = lt.getRoot().getChildren();
for (Node n : children) {
char[] letters = n.getLetters();
b.append(letters[0]);
}
Assert.assertEquals("おこさ", b.toString());
}
use of org.trie4j.Trie in project trie4j by takawitter.
the class DoubleArrayTest method test_getNode_traverse.
@Test
public void test_getNode_traverse() throws Exception {
Trie t = trieWithWords("hello", "helloworld", "hi", "howsgoing", "hell", "helloworld2", "world");
StringWriter sw = new StringWriter();
PrintWriter w = new PrintWriter(sw);
print(t.getRoot(), 0, w);
String expected = StreamUtil.readAsString(getClass().getResourceAsStream("DoubleArrayTest_dump_expected.txt"), "UTF-8");
String actual = sw.toString();
Assert.assertEquals(expected, actual);
}
Aggregations