Search in sources :

Example 6 with Trie

use of org.trie4j.Trie in project trie4j by takawitter.

the class Issue_031 method test_TailDoubleArray.

@Test
public void test_TailDoubleArray() throws Throwable {
    Trie trie = new PatriciaTrie();
    insertLines(trie, FILE_NAME);
    Trie da = new TailDoubleArray(trie);
    Assert.assertFalse(trie.contains("you"));
    Assert.assertFalse(da.contains("you"));
}
Also used : MapTailDoubleArray(org.trie4j.doublearray.MapTailDoubleArray) TailDoubleArray(org.trie4j.doublearray.TailDoubleArray) PatriciaTrie(org.trie4j.patricia.PatriciaTrie) MapPatriciaTrie(org.trie4j.patricia.MapPatriciaTrie) MapTrie(org.trie4j.MapTrie) PatriciaTrie(org.trie4j.patricia.PatriciaTrie) Trie(org.trie4j.Trie) MapPatriciaTrie(org.trie4j.patricia.MapPatriciaTrie) Test(org.junit.Test)

Example 7 with Trie

use of org.trie4j.Trie in project trie4j by takawitter.

the class Issue_031 method test_DoubleArray.

@Test
public void test_DoubleArray() throws Throwable {
    Trie trie = new PatriciaTrie();
    insertLines(trie, FILE_NAME);
    Trie da = new DoubleArray(trie);
    Assert.assertFalse(trie.contains("you"));
    Assert.assertFalse(da.contains("you"));
}
Also used : PatriciaTrie(org.trie4j.patricia.PatriciaTrie) MapPatriciaTrie(org.trie4j.patricia.MapPatriciaTrie) MapTrie(org.trie4j.MapTrie) PatriciaTrie(org.trie4j.patricia.PatriciaTrie) Trie(org.trie4j.Trie) MapPatriciaTrie(org.trie4j.patricia.MapPatriciaTrie) MapTailDoubleArray(org.trie4j.doublearray.MapTailDoubleArray) TailDoubleArray(org.trie4j.doublearray.TailDoubleArray) MapDoubleArray(org.trie4j.doublearray.MapDoubleArray) DoubleArray(org.trie4j.doublearray.DoubleArray) Test(org.junit.Test)

Example 8 with Trie

use of org.trie4j.Trie in project trie4j by takawitter.

the class LongsTailLOUDSTrieWithConcatTailArrayTest method test.

@Test
public void test() throws Exception {
    String[] words = { "こんにちは", "さようなら", "おはよう", "おおきなかぶ", "おおやまざき" };
    Trie lt = trieWithWords(words);
    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());
}
Also used : Node(org.trie4j.Node) Trie(org.trie4j.Trie) AbstractTermIdTrieTest(org.trie4j.AbstractTermIdTrieTest) Test(org.junit.Test)

Example 9 with Trie

use of org.trie4j.Trie in project trie4j by takawitter.

the class TailLOUDSTrieWithSuffixTrieTailArrayTest method test_save_load2.

@Test
public void test_save_load2() throws Exception {
    String[] words = { "こんにちは", "さようなら", "おはよう", "おおきなかぶ", "おおやまざき" };
    Trie trie = new PatriciaTrie();
    for (String w : words) trie.insert(w);
    TailLOUDSTrie lt = new TailLOUDSTrie(trie);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(lt);
    oos.flush();
    lt = (TailLOUDSTrie) new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
    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());
}
Also used : PatriciaTrie(org.trie4j.patricia.PatriciaTrie) Node(org.trie4j.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Trie(org.trie4j.Trie) PatriciaTrie(org.trie4j.patricia.PatriciaTrie) ObjectInputStream(java.io.ObjectInputStream) AbstractTermIdTrieTest(org.trie4j.AbstractTermIdTrieTest) Test(org.junit.Test)

Example 10 with Trie

use of org.trie4j.Trie in project trie4j by takawitter.

the class TailPatriciaTrieWithSuffixTrieTailBuilderTest method investigate.

public void investigate() throws Exception {
    Trie t = new TailPatriciaTrie(new SuffixTrieTailBuilder());
    int start = 0;
    int end = 5;
    int i = 0;
    for (String word : new WikipediaTitles()) {
        if (i >= end)
            break;
        if (i >= start) {
            t.insert(word);
            System.out.println(word);
        }
        i++;
    }
    i = 0;
    for (String word : new WikipediaTitles()) {
        if (i >= end)
            break;
        if (i >= start)
            Assert.assertTrue(i + "th word: " + word, t.contains(word));
        i++;
    }
}
Also used : WikipediaTitles(org.trie4j.test.WikipediaTitles) Trie(org.trie4j.Trie) SuffixTrieTailBuilder(org.trie4j.tail.builder.SuffixTrieTailBuilder)

Aggregations

Trie (org.trie4j.Trie)21 Test (org.junit.Test)15 PatriciaTrie (org.trie4j.patricia.PatriciaTrie)11 Node (org.trie4j.Node)10 AbstractTermIdTrieTest (org.trie4j.AbstractTermIdTrieTest)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 LOUDSPPBvTree (org.trie4j.louds.bvtree.LOUDSPPBvTree)5 WikipediaTitles (org.trie4j.test.WikipediaTitles)5 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4 SuffixTrieDenseTailArrayBuilder (org.trie4j.tail.SuffixTrieDenseTailArrayBuilder)4 LapTimer (org.trie4j.test.LapTimer)4 PrintWriter (java.io.PrintWriter)3 MapTrie (org.trie4j.MapTrie)3 MapPatriciaTrie (org.trie4j.patricia.MapPatriciaTrie)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AbstractImmutableTrieTest (org.trie4j.AbstractImmutableTrieTest)2 NodeVisitor (org.trie4j.NodeVisitor)2 LongsRank0OnlySuccinctBitVector (org.trie4j.bv.LongsRank0OnlySuccinctBitVector)2