org.bigml.mimir.nlp.Dictionary Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mimir Show documentation
Show all versions of mimir Show documentation
Java/Clojure Prediction Code for BigML
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