本文整理汇总了Java中edu.berkeley.nlp.util.Counter.incrementCount方法的典型用法代码示例。如果您正苦于以下问题:Java Counter.incrementCount方法的具体用法?Java Counter.incrementCount怎么用?Java Counter.incrementCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.berkeley.nlp.util.Counter
的用法示例。
在下文中一共展示了Counter.incrementCount方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: main
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
public static void main(String[] args) {
List<String> elem1 = CollectionUtils.makeList("a", "b", "c");
List<String> elem2 = CollectionUtils.makeList("a", "b");
Pair<List<String>, Double> d1 = Pair.newPair(elem1, 3.0);
Pair<List<String>, Double> d2 = Pair.newPair(elem2, 2.0);
FeatureExtractor<List<String>, String> featExtractor = new FeatureExtractor<List<String>, String>() {
public Counter<String> extractFeatures(List<String> instance) {
Counter<String> counts = new Counter<String>();
for (String elem : instance) {
counts.incrementCount(elem, 1.0);
}
// TODO Auto-generated method stub
return counts;
}
};
LinearRegression.Factory<List<String>> factory = new LinearRegression.Factory<List<String>>(
featExtractor);
List<Pair<List<String>, Double>> datums = CollectionUtils.makeList(d1,
d2);
LinearRegression<List<String>> linearRegressionModel = factory
.train(datums);
double guess = linearRegressionModel.getResponse(elem1);
System.out.println("guess: " + guess);
}
示例3: main
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
public static void main(String[] args) {
Counter<String> counter = new Counter<String>();
System.out.println(counter);
counter.incrementCount("planets", 7);
System.out.println(counter);
counter.incrementCount("planets", 1);
System.out.println(counter);
counter.setCount("suns", 1);
System.out.println(counter);
counter.setCount("aliens", 0);
System.out.println(counter);
System.out.println(counter.toString(2));
System.out.println("Total: " + counter.totalCount());
}
示例4: tallyWordFeatures
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
/**
* @param word
* @param ixCounter
*/
private void tallyWordFeatures(String word, Counter<String> ixCounter) {
int length = word.length();
if (length > 4) {
for (int i = 1; i < 4; i++) {
// String prefix = "PREF-"+word.substring(0,i);
// featureIndexer.add(prefix);
// ixCounter.incrementCount(prefix, 1.0);
String suffix = "SUFF-" + word.substring(length - i);
featureIndexer.add(suffix);
ixCounter.incrementCount(suffix, 1.0);
}
}
}
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:18,代码来源:HierarchicalFullyConnectedAdaptiveLexiconWithFeatures.java
示例5: getPunctuationSignatures
import edu.berkeley.nlp.util.Counter; //导入方法依赖的package包/类
public int[][] getPunctuationSignatures(List<StateSet> sentence,
boolean update, Counter<String> punctSigCounter) {
int length = sentence.size();
String[] masked = new String[length];
for (int i = 0; i < length; i++) {
StateSet thisStateSet = sentence.get(i);
masked[i] = (thisStateSet.wordIndex > 0 && isPunctuation[thisStateSet.wordIndex]) ? thisStateSet
.getWord() : X;
}
int[][] result = new int[length][length + 1];
ArrayUtil.fill(result, -1);
for (int start = 0; start <= length - minSpanLength; start++) {
StringBuilder sb = new StringBuilder();
String prev = "";
if (start <= 1)
sb.append("<S>");
int nWordsBefore = 0;
if (start > 0) {
appendItem(sb, masked[start - 1], nWordsBefore);
}
sb.append("[");
nWordsBefore = appendItem(sb, masked[start], 0);
for (int end = start + minSpanLength; end <= length; end++) {
nWordsBefore = appendItem(sb, masked[end - 1], nWordsBefore);
prev = sb.toString();
sb.append("]");
if (end < length) {
appendItem(sb, masked[end], 0);
}
if (end < length - 1) {
sb.append("<E>");
}
String sig = sb.toString();
if (update) {
punctuationSignatures.add(sig);
punctSigCounter.incrementCount(sig, 1.0);
}
result[start][end] = punctuationSignatures.indexOf(sig);
sb = new StringBuilder(prev);
}
}
return result;
}