本文整理汇总了Java中edu.berkeley.nlp.util.CounterMap类的典型用法代码示例。如果您正苦于以下问题:Java CounterMap类的具体用法?Java CounterMap怎么用?Java CounterMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CounterMap类属于edu.berkeley.nlp.util包,在下文中一共展示了CounterMap类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trainClassifier
import edu.berkeley.nlp.util.CounterMap; //导入依赖的package包/类
public ProbabilisticClassifier<I, L> trainClassifier(
List<LabeledInstance<I, L>> trainingData) {
CounterMap<L, F> featureProbs = new CounterMap<L, F>();
Counter<F> backoffProbs = new Counter<F>();
Counter<L> labelProbs = new Counter<L>();
for (LabeledInstance<I, L> instance : trainingData) {
L label = instance.getLabel();
labelProbs.incrementCount(label, 1.0);
I inst = instance.getInput();
Counter<F> featCounts = featureExtractor.extractFeatures(inst);
for (F feat : featCounts.keySet()) {
double count = featCounts.getCount(feat);
backoffProbs.incrementCount(feat, count);
featureProbs.incrementCount(label, feat, count);
}
}
featureProbs.normalize();
labelProbs.normalize();
backoffProbs.normalize();
return new NaiveBayesClassifier<I, F, L>(featureProbs,
backoffProbs, labelProbs, featureExtractor);
}
示例2: CorpusStatistics
import edu.berkeley.nlp.util.CounterMap; //导入依赖的package包/类
/**
* Count statistics for a collection of StateSet trees.
*/
public CorpusStatistics(Numberer tagNumberer,
Collection<Tree<StateSet>> trees) {
counts = new int[tagNumberer.objects().size()];
this.trees = trees;
unaryRuleCounter = new Counter<UnaryRule>();
binaryRuleCounter = new Counter<BinaryRule>();
contexts = new int[tagNumberer.objects().size()];
posCounter = new CounterMap<Integer, String>();
}
示例3: Grammar
import edu.berkeley.nlp.util.CounterMap; //导入依赖的package包/类
/**
* Rather than calling some all-in-one constructor that takes a list of
* trees as training data, you call Grammar() to create an empty grammar,
* call tallyTree() repeatedly to include all the training data, then call
* optimize() to take it into account.
*
* @param oldGrammar
* This is the previous grammar. We use this to copy the split
* trees that record how each state is split recursively. These
* parameters are intialized if oldGrammar is null.
*/
@SuppressWarnings("unchecked")
public Grammar(short[] nSubStates, boolean findClosedPaths,
Smoother smoother, Grammar oldGrammar, double thresh) {
this.tagNumberer = Numberer.getGlobalNumberer("tags");
this.findClosedPaths = findClosedPaths;
this.smoother = smoother;
this.threshold = thresh;
unaryRuleCounter = new UnaryCounterTable(nSubStates);
binaryRuleCounter = new BinaryCounterTable(nSubStates);
symbolCounter = new CounterMap<Integer, Integer>();
numStates = (short) nSubStates.length;
numSubStates = nSubStates;
bSearchRule = new BinaryRule((short) 0, (short) 0, (short) 0);
uSearchRule = new UnaryRule((short) 0, (short) 0);
logarithmMode = false;
if (oldGrammar != null) {
splitTrees = oldGrammar.splitTrees;
} else {
splitTrees = new Tree[numStates];
boolean hasAnySplits = false;
for (int tag = 0; !hasAnySplits && tag < numStates; tag++) {
hasAnySplits = hasAnySplits || numSubStates[tag] > 1;
}
for (int tag = 0; tag < numStates; tag++) {
ArrayList<Tree<Short>> children = new ArrayList<Tree<Short>>(
numSubStates[tag]);
if (hasAnySplits) {
for (short substate = 0; substate < numSubStates[tag]; substate++) {
children.add(substate, new Tree<Short>(substate));
}
}
splitTrees[tag] = new Tree<Short>((short) 0, children);
}
}
init();
}
示例4: NaiveBayesClassifier
import edu.berkeley.nlp.util.CounterMap; //导入依赖的package包/类
public NaiveBayesClassifier(CounterMap<L, F> featureProbs,
Counter<F> backoffProbs, Counter<L> labelProbs,
FeatureExtractor<I, F> featureExtractor) {
super();
this.featureProbs = featureProbs;
this.backoffProbs = backoffProbs;
this.labelProbs = labelProbs;
this.featureExtractor = featureExtractor;
}
示例5: clearCounts
import edu.berkeley.nlp.util.CounterMap; //导入依赖的package包/类
public void clearCounts() {
unaryRuleCounter = new UnaryCounterTable(numSubStates);
binaryRuleCounter = new BinaryCounterTable(numSubStates);
symbolCounter = new CounterMap<Integer, Integer>();
}