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

edu.berkeley.nlp.classify.Encoding Maven / Gradle / Ivy

Go to download

The Berkeley parser analyzes the grammatical structure of natural language using probabilistic context-free grammars (PCFGs).

The newest version!
package edu.berkeley.nlp.classify;

import java.io.Serializable;

import edu.berkeley.nlp.util.Indexer;


/**
 * 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 implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6349512704632759684L;
	Indexer featureIndexer;
	Indexer labelIndexer;

	public int getNumFeatures() {
		return featureIndexer.size();
	}
	
	public boolean hasFeature(F feature) {
		return featureIndexer.contains(feature);
	}

	public int getFeatureIndex(F feature) {
		return featureIndexer.indexOf(feature);
	}

	public F getFeature(int featureIndex) {
		return featureIndexer.getObject(featureIndex);
	}

	public int getNumLabels() {
		return labelIndexer.size();
	}

	public int getLabelIndex(L label) {
		return labelIndexer.indexOf(label);
	}

	public L getLabel(int labelIndex) {
		return labelIndexer.getObject(labelIndex);
	}

	public Encoding(Indexer featureIndexer, Indexer labelIndexer) {
		this.featureIndexer = featureIndexer;
		this.labelIndexer = labelIndexer;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy