Search in sources :

Example 1 with SBVConcatTailArrayBuilder

use of org.trie4j.tail.SBVConcatTailArrayBuilder in project trie4j by takawitter.

the class SaveLOUDSTrie method main.

public static void main(String[] args) throws Exception {
    TailPatriciaTrie trie1 = new TailPatriciaTrie();
    for (String s : new WikipediaTitles("data/jawiki-20120220-all-titles-in-ns0.gz")) {
        trie1.insert(s);
    }
    System.out.println(trie1.size() + "nodes.");
    SBVConcatTailArrayBuilder tailArray = new SBVConcatTailArrayBuilder(trie1.size());
    TailLOUDSTrie trie = new TailLOUDSTrie(trie1, tailArray);
    System.out.println(trie.size() + "nodes.");
    trie.freeze();
    OutputStream os = new FileOutputStream("louds.dat");
    try {
        ObjectOutputStream oos = new ObjectOutputStream(os);
        trie.writeExternal(oos);
        oos.flush();
    } finally {
        os.close();
    }
    os = new FileOutputStream("louds-bv.dat");
    try {
        ObjectOutputStream oos = new ObjectOutputStream(os);
        oos.writeObject(trie.getBvTree());
        oos.flush();
    } finally {
        os.close();
    }
    os = new FileOutputStream("louds-labels.dat");
    try {
        DataOutputStream dos = new DataOutputStream(os);
        for (char c : trie.getLabels()) {
            dos.writeChar(c);
        }
        dos.flush();
    } finally {
        os.close();
    }
    os = new FileOutputStream("louds-tails.dat");
    try {
        ObjectOutputStream dos = new ObjectOutputStream(os);
        dos.writeObject(tailArray);
        dos.flush();
    } finally {
        os.close();
    }
    os = new FileOutputStream("louds-tailIndex.dat");
    try {
        ObjectOutputStream oos = new ObjectOutputStream(os);
        oos.writeObject(tailArray);
        oos.flush();
    } finally {
        os.close();
    }
    os = new FileOutputStream("louds-term.dat");
    try {
        ObjectOutputStream dos = new ObjectOutputStream(os);
        dos.writeObject(trie.getTerm());
        dos.flush();
    } finally {
        os.close();
    }
}
Also used : TailPatriciaTrie(org.trie4j.patricia.TailPatriciaTrie) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) FileOutputStream(java.io.FileOutputStream) SBVConcatTailArrayBuilder(org.trie4j.tail.SBVConcatTailArrayBuilder) WikipediaTitles(org.trie4j.test.WikipediaTitles) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

DataOutputStream (java.io.DataOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 TailPatriciaTrie (org.trie4j.patricia.TailPatriciaTrie)1 SBVConcatTailArrayBuilder (org.trie4j.tail.SBVConcatTailArrayBuilder)1 WikipediaTitles (org.trie4j.test.WikipediaTitles)1