![JAR search and dependency download from the Maven repository](/logo.png)
edu.berkeley.nlp.discPCFG.Encoding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of berkeleyparser Show documentation
Show all versions of berkeleyparser Show documentation
The Berkeley parser analyzes the grammatical structure of natural language using probabilistic context-free grammars (PCFGs).
The newest version!
/**
*
*/
package edu.berkeley.nlp.discPCFG;
import edu.berkeley.nlp.util.Indexer;
import edu.berkeley.nlp.util.SubIndexer;
/**
* The Encoding maintains correspondences between the various representions of the data, labels, and features. The
* external representations of labels and features are object-based. The functions getLabelIndex() and
* getFeatureIndex() can be used to translate those objects to integer representatiosn: numbers between 0 and
* getNumLabels() or getNumFeatures() (exclusive). The inverses of this map are the getLabel() and getFeature()
* functions.
*/
public class Encoding {
Indexer featureIndexer;
SubIndexer labelIndexer;
public int getNumFeatures() {
return featureIndexer.size();
}
public int getFeatureIndex(F feature) {
return featureIndexer.indexOf(feature);
}
public F getFeature(int featureIndex) {
return featureIndexer.get(featureIndex);
}
/** Number of labels (not total number of substates) */
public int getNumLabels() {
return labelIndexer.size();
}
/** Total number of substates */
public int getNumSubLabels() {
return labelIndexer.totalSize();
}
public int getLabelIndex(L label) {
return labelIndexer.indexOf(label);
}
public int getLabelSubindexBegin(int labelIndex) {
return labelIndexer.subindexBegin(labelIndex);
}
public int getLabelSubindexEnd(int labelIndex) {
return labelIndexer.subindexEnd(labelIndex);
}
public L getLabel(int labelIndex) {
return labelIndexer.get(labelIndex);
}
public Encoding(Indexer featureIndexer, SubIndexer labelIndexer) {
this.featureIndexer = featureIndexer;
this.labelIndexer = labelIndexer;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy