/** * Sets each value of target to be target[k]+ * value*(num-of-times-it-occurs-in-collection) if the key is present in the arg * collection. */ public static <E> void addInPlace(Counter<E> target, Collection<E> arg, double value) { for (E key : arg) { target.incrementCount(key, value); } }
/** * Sets each value of target to be target[k]+ * num-of-times-it-occurs-in-collection if the key is present in the arg * collection. */ public static <E> void addInPlace(Counter<E> target, Collection<E> arg) { for (E key : arg) { target.incrementCount(key, 1); } }
private static StringBuilder maybeIncrementCounter(StringBuilder inProgressMisc, Counter<String> miscCounter) { if (inProgressMisc.length() > 0) { miscCounter.incrementCount(inProgressMisc.toString()); inProgressMisc = new StringBuilder(); } return inProgressMisc; }
public Counter<K> uncompress(CompressedFeatureVector cvf) { Counter<K> c = new ClassicCounter<>(); for (int i = 0; i < cvf.keys.size(); i++) { c.incrementCount(inverse.get(cvf.keys.get(i)), cvf.values.get(i)); } return c; }
/** * Sets each value of target to be target[k]+arg[k] for all keys k in arg. */ public static <E> void addInPlace(Counter<E> target, Counter<E> arg) { for (Map.Entry<E, Double> entry : arg.entrySet()) { double count = entry.getValue(); if (count != 0) { target.incrementCount(entry.getKey(), count); } } }
/** * Increments all keys in a Counter by a specific value. */ public static <E> void addInPlace(Counter<E> target, double value) { for (E key : target.keySet()) { target.incrementCount(key, value); } }
@Override public void update(String feature, double gradient) { counter.incrementCount(feature, getCounterIncrement(gradient)); }
private static Counter<String> addSuffix(Counter<String> features, String suffix) { Counter<String> withSuffix = new ClassicCounter<>(); for (Map.Entry<String, Double> e : features.entrySet()) { withSuffix.incrementCount(e.getKey() + suffix, e.getValue()); } return withSuffix; }
private void updateCounters(Rule rule, Counter<String> symWeights, Counter<String> symCounts) { String label = stateIndex.get(rule.parent()); String basicCat = basicCategory(label); symWeights.incrementCount(basicCat, Math.exp(rule.score())); symCounts.incrementCount(basicCat); }
private void countMentionTypes(CoreMap sent) { List<EntityMention> mentions = sent.get(MachineReadingAnnotations.EntityMentionsAnnotation.class); if(mentions != null){ for(EntityMention m: mentions){ mentionTypeCounts.incrementCount(m.getMentionType()); } } }
private void countNameRelations(CoreMap sent) { List<RelationMention> mentions = sent.get(MachineReadingAnnotations.RelationMentionsAnnotation.class); if(mentions != null){ for(RelationMention m: mentions) { List<EntityMention> args = m.getEntityMentionArgs(); if(args.size() == 2 && args.get(0).getMentionType().equals("NAM") && args.get(1).getMentionType().equals("NAM")){ nameRelationCounts.incrementCount(m.getType() + "." + m.getSubType()); } } } }
/** * Returns the counter with keys modified according to function F. If two keys are same after the transformation, their values get added up. */ public static <T1, T2> Counter<T2> transformWithValuesAdd(Counter<T1> c, Function<T1, T2> f) { Counter<T2> c2 = new ClassicCounter<>(); for (T1 key : c.keySet()) { c2.incrementCount(f.apply(key), c.getCount(key)); } return c2; }
public Counter<E> logProbs(int position) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, logProb(position, i)); } return c; }
private static Counter<String> getFeatures(ClustererDoc doc, Pair<Integer, Integer> mentionPair, Counter<Pair<Integer, Integer>> scores) { Counter<String> features = new ClassicCounter<>(); if (!scores.containsKey(mentionPair)) { mentionPair = new Pair<>(mentionPair.second, mentionPair.first); } double score = scores.getCount(mentionPair); features.incrementCount("max", score); return features; }
public Counter<E> condLogProbsGivenPrevious(int position, int[] prevlabels) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, condLogProbGivenPrevious(position, i, prevlabels)); } return c; }
public Counter<E> condLogProbsGivenPrevious(int position, E[] prevlabels) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, condLogProbGivenPrevious(position, label, prevlabels)); } return c; }
public Counter<E> condLogProbsGivenNext(int position, int[] nextlabels) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, condLogProbGivenNext(position, i, nextlabels)); } return c; }
public Counter<E> condLogProbsGivenNext(int position, E[] nextlabels) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, condLogProbGivenNext(position, label, nextlabels)); } return c; }
public Counter<E> probs(int position) { Counter<E> c = new ClassicCounter<>(); for (int i = 0, sz = classIndex.size(); i < sz; i++) { E label = classIndex.get(i); c.incrementCount(label, prob(position, i)); } return c; }
public Counter<F> justificationOf(Counter<F> features){ Counter<F> fWts = new ClassicCounter<>(); for (F feature : features.keySet()) { int f = featureIndex.indexOf(feature); if (f >= 0) { fWts.incrementCount(feature,weights[f]*features.getCount(feature)); } } return fWts; } /**