public class Lexicon extends Object
Modifier and Type | Field and Description |
---|---|
gnu.trove.map.hash.TIntIntHashMap |
featureCounts |
static String |
GLOBAL_BIAS |
Constructor and Description |
---|
Lexicon(boolean hasBias,
boolean storeStrings)
Create a new lexicon object
|
Lexicon(InputStream in)
Load a lexicon from the inputstream.
|
Lexicon(InputStream in,
boolean loadStrings) |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(String f) |
void |
countFeature(int featureId)
Increment the count for featureId.
|
protected int |
getFeatureHash(String featureName)
A hash function from feature names to integers.
|
int |
getFeatureId(String feature)
a more intuitive method for adding a feature.
|
Pair<int[],float[]> |
getFeatureVector(Map<String,Float> featureMap)
generate a feature id representation from a feature vector with associated weights
|
Lexicon |
getPrunedLexicon(int threshold)
prunes the lexicon by removing features with less than threshold many counts
|
int |
lookupId(String featureName)
Get the internal id for this feature
|
String |
lookupName(int id)
Get the feature corresponding to the name.
|
void |
previewFeature(String f)
Add a new feature to this lexicon
|
Pair<int[],float[]> |
pruneFeaturesByCount(int[] idx,
float[] fs,
int threshold) |
void |
save(String file)
Saves the feature to id mapping.
|
int |
size()
The number of features in this lexicon
|
void |
writeIntegerToFeatureStringFormat(PrintStream out) |
public static final String GLOBAL_BIAS
public final gnu.trove.map.hash.TIntIntHashMap featureCounts
public Lexicon(boolean hasBias, boolean storeStrings)
hasBias
- Include a default entry in the lexicon for GLOBAL_BIAS?storeStrings
- Store strings in the lexicon? Useful for debugging at the expense of much
more memory consumptionpublic Lexicon(InputStream in) throws IOException
IOException
public Lexicon(InputStream in, boolean loadStrings) throws IOException
IOException
public int lookupId(String featureName)
public String lookupName(int id)
public void countFeature(int featureId)
public int getFeatureId(String feature)
feature
- Feature value to put in lexiconpublic void previewFeature(String f)
public boolean contains(String f)
public int size()
protected int getFeatureHash(String featureName)
public Pair<int[],float[]> getFeatureVector(Map<String,Float> featureMap)
featureMap
- public Pair<int[],float[]> pruneFeaturesByCount(int[] idx, float[] fs, int threshold)
public void writeIntegerToFeatureStringFormat(PrintStream out) throws IOException
IOException
public void save(String file) throws IOException
IOException
public Lexicon getPrunedLexicon(int threshold)
Copyright © 2017. All rights reserved.