All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bigml.mimir.nlp.Dictionary Maven / Gradle / Ivy

There is a newer version: 0.8.3
Show newest version
package org.bigml.mimir.nlp;

import java.util.HashMap;

import org.trie4j.doublearray.DoubleArray;
import org.trie4j.patricia.PatriciaTrie;

/**
 * A map giving a integer index for each of the constituent terms.  Uses an
 * underlying Trie to speed up calls to containsKey.
 *
 * @author [email protected]
 *
 */
public class Dictionary extends HashMap {
    private static final long serialVersionUID = 2894218006856951940L;

    private DoubleArray termSet = null;

    public Dictionary(Iterable terms) {
        PatriciaTrie pt = new PatriciaTrie();

        int i = 0;
        for (String t : terms) {
            put(t, i++);
            pt.insert(t);
        }

        termSet = new DoubleArray(pt);
    }

    @Override
    public boolean containsKey(Object o) {
        return termSet.contains((String)o);
    }

    public String[] getTerms() {
        String[] terms = new String[size()];
        for (String t : keySet()) terms[get(t)] = t;
        return terms;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy