當前位置: 首頁>>代碼示例>>Java>>正文


Java Indexer類代碼示例

本文整理匯總了Java中edu.berkeley.nlp.util.Indexer的典型用法代碼示例。如果您正苦於以下問題:Java Indexer類的具體用法?Java Indexer怎麽用?Java Indexer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Indexer類屬於edu.berkeley.nlp.util包,在下文中一共展示了Indexer類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initPunctuations

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
private void initPunctuations(StateSetTreeList trainTrees) {
	punctuationSignatures = new Indexer<String>();
	isPunctuation = new boolean[nWords];
	Counter<String> punctSigCounter = new Counter<String>();
	for (int word = 0; word < nWords; word++) {
		isPunctuation[word] = isPunctuation(wordIndexer.get(word));
	}
	for (Tree<StateSet> tree : trainTrees) {
		getPunctuationSignatures(tree.getYield(), true, punctSigCounter);
	}

	Indexer<String> newPunctuationSignatures = new Indexer<String>();
	for (String sig : punctSigCounter.keySet()) {
		if (punctSigCounter.getCount(sig) >= minFeatureFrequency)
			newPunctuationSignatures.add(sig);
	}
	punctuationSignatures = newPunctuationSignatures;
	punctuationScores = new double[punctuationSignatures.size()][nClasses];
	ArrayUtil.fill(punctuationScores, 1);
	nFeatures += nClasses * punctuationScores.length;
}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:22,代碼來源:SpanPredictor.java

示例2: buildEncoding

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
private Encoding<F, L> buildEncoding(List<LabeledInstance<I, L>> data) {
	Indexer<F> featureIndexer = new Indexer<F>();
	Indexer<L> labelIndexer = new Indexer<L>();
	for (LabeledInstance<I, L> labeledInstance : data) {
		L label = labeledInstance.getLabel();
		Counter<F> features = featureExtractor
				.extractFeatures(labeledInstance.getInput());
		LabeledFeatureVector<F, L> labeledDatum = new BasicLabeledFeatureVector<F, L>(
				label, features);
		labelIndexer.getIndex(labeledDatum.getLabel());
		for (F feature : labeledDatum.getFeatures().keySet()) {
			featureIndexer.getIndex(feature);
		}
	}
	return new Encoding<F, L>(featureIndexer, labelIndexer);
}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:17,代碼來源:MaximumEntropyClassifier.java

示例3: SimpleLexicon

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
public SimpleLexicon(short[] numSubStates, double threshold) {
	this.numSubStates = numSubStates;
	this.threshold = threshold;
	this.wordIndexer = new Indexer<String>();
	this.numStates = numSubStates.length;
	this.isLogarithmMode = false;
	if (Corpus.myTreebank != Corpus.TreeBankType.WSJ
			|| Corpus.myTreebank == Corpus.TreeBankType.BROWN)
		unknownLevel = 4;

}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:12,代碼來源:SimpleLexicon.java

示例4: FeaturizedLexicon

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
public FeaturizedLexicon(short[] numSubStates, Featurizer featurizer) {
	this.numSubStates = numSubStates;
	this.wordIndexer = new Indexer<String>();
	this.numStates = numSubStates.length;
	this.isLogarithmMode = false;
	this.featurizer = featurizer;
	minimizer.setMaxIterations(20);
}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:9,代碼來源:FeaturizedLexicon.java

示例5: refeaturize

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
private void refeaturize() {
	indexedFeatures = new int[numStates][][][];
	featureIndex = new Indexer<String>();
	tagWordsWithFeatures = new int[numStates][];

	for (int tag = 0; tag < numStates; tag++) {
		IntegerIndexer tagIndexer = new IntegerIndexer(wordIndexer.size());
		indexedFeatures[tag] = new int[numSubStates[tag]][wordIndexer
				.size()][];
		// index all the features for each word seen with this tag.
		for (int globalWordIndex = 0; globalWordIndex < wordIndexer.size(); ++globalWordIndex) {
			String word = wordIndexer.getObject(globalWordIndex);
			List<String>[] features = featurizer.featurize(word, tag,
					numSubStates[tag], wordCounter[globalWordIndex],
					tagWordCounts[tag][globalWordIndex]);
			for (int state = 0; state < numSubStates[tag]; ++state) {
				int[] indices = new int[features[state].size()];
				for (int i = 0; i < indices.length; ++i) {
					indices[i] = featureIndex.getIndex(features[state]
							.get(i));
				}
				indexedFeatures[tag][state][globalWordIndex] = indices;

				if (features[state].size() > 0)
					tagIndexer.add(globalWordIndex);
			}
		}

		tagWordsWithFeatures[tag] = new int[tagIndexer.size()];
		for (int j = 0; j < tagIndexer.size(); ++j) {
			tagWordsWithFeatures[tag][j] = tagIndexer.get(j);
		}

	}

	if (featureWeights == null
			|| featureWeights.length != featureIndex.size()) {
		featureWeights = new double[featureIndex.size()];
	}
}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:41,代碼來源:FeaturizedLexicon.java

示例6: LabelFeatureWeightsManager

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
public LabelFeatureWeightsManager(FeatureManager featManager,
		Indexer<L> labels) {
	this.featManager = featManager;
	this.labels = labels;
	if (!featManager.isLocked()) {
		throw new IllegalArgumentException("Feature manager must be locked");
	}
}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:9,代碼來源:LabelFeatureWeightsManager.java

示例7: Encoding

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
public Encoding(Indexer<F> featureIndexer, SubIndexer<L> labelIndexer) {
	this.featureIndexer = featureIndexer;
	this.labelIndexer = labelIndexer;
}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:5,代碼來源:Encoding.java

示例8: SpanPredictor

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
public SpanPredictor(int nWords, StateSetTreeList trainTrees,
		Numberer tagNumberer, Indexer<String> wordIndexer) {
	this.useFirstAndLast = ConditionalTrainer.Options.useFirstAndLast;
	this.usePreviousAndNext = ConditionalTrainer.Options.usePreviousAndNext;
	this.useBeginAndEndPairs = ConditionalTrainer.Options.useBeginAndEndPairs;
	this.useSyntheticClass = ConditionalTrainer.Options.useSyntheticClass;
	this.usePunctuation = ConditionalTrainer.Options.usePunctuation;
	this.minFeatureFrequency = ConditionalTrainer.Options.minFeatureFrequency;

	this.wordIndexer = wordIndexer;
	this.nWords = nWords;
	this.nFeatures = 0;
	if (useSyntheticClass) {
		System.out
				.println("Distinguishing between real and synthetic classes.");
		stateClass = new int[tagNumberer.total()];
		for (int i = 0; i < tagNumberer.total(); i++) {
			String state = (String) tagNumberer.object(i);
			if (state.charAt(0) == '@')
				stateClass[i] = 1; // synthetic
		}
		nClasses = 2;
	} else {
		stateClass = new int[tagNumberer.total()];
		nClasses = 1;
	}
	if (useFirstAndLast) {
		firstWordScore = new double[nWords][nClasses];
		lastWordScore = new double[nWords][nClasses];
		ArrayUtil.fill(firstWordScore, 1);
		ArrayUtil.fill(lastWordScore, 1);
		this.nFeatures += 2 * nWords * nClasses;
	}
	if (usePreviousAndNext) {
		previousWordScore = new double[nWords][nClasses];
		nextWordScore = new double[nWords][nClasses];
		ArrayUtil.fill(previousWordScore, 1);
		ArrayUtil.fill(nextWordScore, 1);
		this.nFeatures += 2 * nWords * nClasses;
	}
	if (useBeginAndEndPairs) {
		initPairs(trainTrees);
	}
	if (usePunctuation) {
		initPunctuations(trainTrees);
	}
}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:48,代碼來源:SpanPredictor.java

示例9: Encoding

import edu.berkeley.nlp.util.Indexer; //導入依賴的package包/類
public Encoding(Indexer<F> featureIndexer, Indexer<L> labelIndexer) {
	this.featureIndexer = featureIndexer;
	this.labelIndexer = labelIndexer;
}
 
開發者ID:text-machine-lab,項目名稱:CliRel,代碼行數:5,代碼來源:Encoding.java


注:本文中的edu.berkeley.nlp.util.Indexer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。