本文整理汇总了Java中edu.berkeley.nlp.util.Counter.getCount方法的典型用法代码示例。如果您正苦于以下问题:Java Counter.getCount方法的具体用法?Java Counter.getCount怎么用?Java Counter.getCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.berkeley.nlp.util.Counter
的用法示例。
在下文中一共展示了Counter.getCount方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: relax
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private void relax(Counter<Edge<V>> pathCosts,
Map<Edge<V>, V> intermediateStates,
Map<V, List<Edge<V>>> closedUnaryRulesByChild,
Map<V, List<Edge<V>>> closedUnaryRulesByParent, Edge<V> unaryRule,
V intermediateState, double newScore) {
if (intermediateState != null
&& (intermediateState.equals(unaryRule.getParent()) || intermediateState
.equals(unaryRule.getChild())))
return;
boolean isNewRule = !pathCosts.containsKey(unaryRule);
double oldScore = (isNewRule ? Double.NEGATIVE_INFINITY : pathCosts
.getCount(unaryRule));
if (oldScore > newScore)
return;
if (isNewRule) {
CollectionUtils.addToValueList(closedUnaryRulesByChild,
unaryRule.getChild(), unaryRule);
CollectionUtils.addToValueList(closedUnaryRulesByParent,
unaryRule.getParent(), unaryRule);
}
pathCosts.setCount(unaryRule, newScore);
intermediateStates.put(unaryRule, intermediateState);
}
示例2: initPunctuations
import edu.berkeley.nlp.util.Counter; //导入方法依赖的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;
}
示例3: trainClassifier
import edu.berkeley.nlp.util.Counter; //导入方法依赖的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);
}
示例4: calculate
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
@Override
protected Pair<Double, double[]> calculate(double[] x) {
weights = x;
double objective = 0.0;
double[] gradient = new double[dimension()];
for (Pair<I, Double> datum : trainingData) {
I input = datum.getFirst();
Counter<Feature> featCounts = getFeatures(input);
double guessResponse = getScore(featCounts);
double goldResponse = datum.getSecond();
double diff = (guessResponse - goldResponse);
objective += 0.5 * diff * diff;
for (Feature feat : featCounts.keySet()) {
double count = featCounts.getCount(feat);
gradient[feat.getIndex()] += count * diff;
}
}
// TODO Auto-generated method stub
return Pair.newPair(objective, gradient);
}
示例5: dotProduct
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private double dotProduct(Counter<F> features, int labelIndex, double[] w) {
double val = 0.0;
for (F feature : features.keySet()) {
if (encoding.hasFeature(feature)) {
int featureIndex = encoding.getFeatureIndex(feature);
int linearIndex = il.getLinearIndex(featureIndex, labelIndex);
val += features.getCount(feature) * w[linearIndex];
}
}
return val;
}
示例6: combinePathCosts
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
/**
* @param pathCosts
* @param incomingRule
* @param outgoingRule
* @return
*/
private double combinePathCosts(Counter<Edge<V>> pathCosts,
Edge<V> incomingRule, Edge<V> outgoingRule) {
return this.sumInsteadOfMultipy ? (pathCosts.getCount(incomingRule) + pathCosts
.getCount(outgoingRule))
: (pathCosts.getCount(incomingRule) * pathCosts
.getCount(outgoingRule));
}
示例7: getFeatures
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private Counter<Feature> getFeatures(I input) {
Counter<String> strCounts = featureExtractor.extractFeatures(input);
Counter<Feature> featCounts = new Counter<Feature>();
for (String f : strCounts.keySet()) {
double count = strCounts.getCount(f);
Feature feat = featureManager.getFeature(f);
featCounts.setCount(feat, count);
}
return featCounts;
}
示例8: getScore
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
private double getScore(Counter<Feature> featureCounts) {
double score = 0.0;
for (Feature feat : featureCounts.keySet()) {
double count = featureCounts.getCount(feat);
score += count * weights[feat.getIndex()];
}
return score;
}
示例9: getResponse
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
public double getResponse(I input) {
Counter<String> featCounts = featureExtractor.extractFeatures(input);
double score = 0.0;
for (String f : featCounts.keySet()) {
double count = featCounts.getCount(f);
Feature feat = featureManager.getFeature(f);
score += count * weights[feat.getIndex()];
}
return score;
}