/** * Adds 1 to the count for the given key. If the key hasn't been seen * before, it is assumed to have count 0, and thus this method will set * its count to 1. * <p> * To increment the count by a value other than 1, use * {@link #incrementCount(Object,int)}. * <p> * To set a count to a specific value instead of incrementing it, use * {@link #setCount(Object,int)}. */ @Override public double incrementCount(E key) { return incrementCount(key, 1); }
/** * Subtracts the given count from the current count for the given key. * If the key hasn't been seen before, it is assumed to have count 0, and * thus this method will set its count to the negative of the given amount. * Negative increments are equivalent to calling {@code incrementCount}. * <p> * To more conveniently decrement the count by 1, use * {@link #decrementCount(Object)}. * <p> * To set a count to a specifc value instead of decrementing it, use * {@link #setCount(Object,int)}. */ public int decrementCount(E key, int count) { return incrementCount(key, -count); }
/** * Adds the given count to the current counts for each of the given keys. * If any of the keys haven't been seen before, they are assumed to have * count 0, and thus this method will set their counts to the given * amount. Negative increments are equivalent to calling {@code decrementCounts}. * <p> * To more conveniently increment the counts of a collection of objects by * 1, use {@link #incrementCounts(Collection)}. * <p> * To set the counts of a collection of objects to a specific value instead * of incrementing them, use {@link #setCounts(Collection,int)}. */ public void incrementCounts(Collection<E> keys, int count) { for (E key : keys) { incrementCount(key, count); } }
public void setVar(Object var, String string) { String oldString = varsToStrings.put(var,string); if(oldString != null && ! oldString.equals(string)) throw new RuntimeException("Error -- can't setVar to a different string -- old: " + oldString + " new: " + string); numVarsSet.incrementCount(var); }
public void setVar(String var, String string) { String oldString = varsToStrings.put(var,string); if(oldString != null && ! oldString.equals(string)) throw new RuntimeException("Error -- can't setVar to a different string -- old: " + oldString + " new: " + string); numVarsSet.incrementCount(var); }
public void train(List<TaggedWord> sentence, double weight) { for (TaggedWord word : sentence) { String wordString = word.word(); wordCounter.incrementCount(wordString, weight); } }
/** */ public void incrementCount(K1 o1, K2 o2, int count) { IntCounter<K2> c = getCounter(o1); c.incrementCount(o2, count); total += count; }
@Override public double incrementCount(E key, double value) { incrementCount(key, (int)value); return getCount(key); }
@Override protected void markBoundary() { if (inCorrect) { inCorrect=false; correctGuesses.incrementCount(getTypeLabel(prevCorrect)); } prevGuess = null; prevCorrect = null; }
/** * Count all the internal labels in all the trees, and set their * initial state counts to 1. */ public void countOriginalStates() { originalStates.clear(); for (Tree tree : trees) { countOriginalStates(tree); } for (String state : originalStates) { stateSplitCounts.incrementCount(state, 1); } }
protected void addGuess(L guess, L label, boolean addUnknownLabels) { if (label == null) { noLabel++; return; } if (addUnknownLabels) { if (labelIndex == null) { labelIndex = new HashIndex<>(); } labelIndex.add(guess); labelIndex.add(label); } if (guess.equals(label)) { correctGuesses.incrementCount(label); tokensCorrect++; } if (!guess.equals(negLabel)) { foundGuessed.incrementCount(guess); } if (!label.equals(negLabel)) { foundCorrect.incrementCount(label); } tokensCount++; }
/** * Adds the counts in the given Counter to the counts in this Counter. * <p> * To copy the values from another Counter rather than adding them, use */ public void addAll(IntCounter<E> counter) { for (E key : counter.keySet()) { int count = counter.getIntCount(key); incrementCount(key, count); } }
public Object aggregate(Class key, List<? extends CoreMap> in) { if (in == null) return null; IntCounter<Object> counter = new IntCounter<>(); for (CoreMap cm:in) { Object obj = cm.get(key); if (obj != null && (ignoreSet == null || !ignoreSet.contains(obj))) { counter.incrementCount(obj); } } if (counter.size() > 0) { return counter.argmax(); } else { return null; } } }
public void applyFeatureCountThreshold(Collection<String> data, int thresh) { IntCounter c = new IntCounter(); for (String datum : data) { for (String feat : makeFeatures(datum)) { c.incrementCount(feat); } } threshedFeatures = c.keysAbove(thresh); log.info((c.size() - threshedFeatures.size()) + " word features removed due to thresholding."); }
/** * Add the given sentence to the statistics counted. Can * be called multiple times with different sentences. */ @Override public void train(List<TaggedWord> sentence, double weight) { featExtractor.train(sentence, weight); for (TaggedWord word : sentence) { datumCounter.incrementCount(word, weight); tagsForWord.add(word.word(), word.tag()); } }
protected int countLengthAccuracy(Tree tree) { if (tree.isLeaf()) { return 0; } Integer gold = RNNCoreAnnotations.getGoldClass(tree); Integer predicted = RNNCoreAnnotations.getPredictedClass(tree); int length; if (tree.isPreTerminal()) { length = 1; } else { length = 0; for (Tree child : tree.children()) { length += countLengthAccuracy(child); } } if (gold >= 0) { if (gold.equals(predicted)) { lengthLabelsCorrect.incrementCount(length); } else { lengthLabelsIncorrect.incrementCount(length); } } return length; }
wordTagCounts.put(word, tagCounts); tagCounts.incrementCount(tag, 1);
int tokenEnd = m.get(CoreAnnotations.TokenEndAnnotation.class) - sentTokenStart; int length = tokenEnd - tokenStart; mentionTokenLengthCounter.incrementCount(length); npt2 = npt; } else { mentionTreePretermNonPretermNoMatchLabelCounter.incrementCount(t.label().value()); logger.info("NPT: Tree span is " + span + ", tree node is " + npt); logger.info("NPT: Mention span is " + tokenStart + " " + (tokenEnd - 1) + ", mention is " + m); mentionTreeLabelCounter.incrementCount(t.label().value()); mentionTreeNonPretermLabelCounter.incrementCount(npt.label().value()); mentionTreeMixedLabelCounter.incrementCount(npt2.label().value()); Label tlabel = t.label(); if (tlabel instanceof CoreLabel) { nerMentionTokenLengthCounter.incrementCount(length);
if (prevCorrectEnded && prevGuessEnded && prevGuess.typeMatches(prevCorrect)) { inCorrect=false; correctGuesses.incrementCount(getTypeLabel(prevCorrect)); } else if (prevCorrectEnded != prevGuessEnded || !guess.typeMatches(correct)) { inCorrect=false; foundCorrect.incrementCount(getTypeLabel(correct)); foundGuessed.incrementCount(getTypeLabel(guess));
continue; tagCounter.incrementCount(word.tag()); if (trainByType) { count = 1;