/** This is a shorthand for keySet.iterator(). It's not really clear that * this method should be here, as the Map interface has no such shortcut, * but it's used in a number of places, and I've left it in for now. * Use is discouraged. * * @return An Iterator over the keys in the Counter. */ @Override public Iterator<E> iterator() { return keySet().iterator(); }
/** * Displays the cumulative results of the evaluation. */ public void display(PrintWriter pw) { pw.println("*********Final " + summaryName + " eval stats by antecedent category***********"); Set<OUT> keys = Generics.newHashSet(); keys.addAll(guessed.keySet()); keys.addAll(gold.keySet()); displayHelper(keys, pw, guessed, guessedCorrect, gold, goldCorrect); pw.println("Finished final " + summaryName + " eval stats."); }
/** * Displays the results of the previous Collection pair evaluation. */ public void displayLast(PrintWriter pw) { Set<OUT> keys = Generics.newHashSet(); keys.addAll(previousGuessed.keySet()); keys.addAll(previousGold.keySet()); displayHelper(keys, pw, previousGuessed, previousGuessedCorrect, previousGold, previousGoldCorrect); }
/** * Need to sort the counter by feature keys and dump it * */ public static void printSVMLightFormat(PrintWriter pw, ClassicCounter<Integer> c, int classNo) { Integer[] features = c.keySet().toArray(new Integer[c.keySet().size()]); Arrays.sort(features); StringBuilder sb = new StringBuilder(); sb.append(classNo); sb.append(' '); for (int f: features) { sb.append(f + 1).append(':').append(c.getCount(f)).append(' '); } pw.println(sb.toString()); }
private static <T> void display(ClassicCounter<T> c, int num, PrintWriter pw) { List<T> rules = new ArrayList<>(c.keySet()); Collections.sort(rules, Counters.toComparatorDescending(c)); int rSize = rules.size(); if (num > rSize) { num = rSize; } for (int i = 0; i < num; i++) { pw.println(rules.get(i) + " " + c.getCount(rules.get(i))); } }
public void dumpStats() { System.out.println("%% Counts of nonterminals:"); List<String> biggestCounts = new ArrayList<>(nonTerms.keySet()); Collections.sort(biggestCounts, Counters.toComparatorDescending(nonTerms)); for (String str : biggestCounts) { System.out.println(str + ": " + nonTerms.getCount(str)); } }
private static <T> void display(ClassicCounter<T> c, PrintWriter pw) { List<T> cats = new ArrayList<>(c.keySet()); Collections.sort(cats, Counters.toComparatorDescending(c)); for (T ob : cats) { pw.println(ob + " " + c.getCount(ob)); } }
public double probabilityOf(E object) { if (object == null) { throw new RuntimeException("You cannot ask for the probability of null."); } if (sampled.keySet().contains(object)) { return sampled.getCount(object) / sampled.totalCount(); } else { return 0.0; } }
private void addAllInterningAndPrefixingRVF(ClassicCounter<String> accumulator, ClassicCounter<String> addend, String prefix) { assert prefix != null; for (String protoFeat : addend.keySet()) { double count = addend.getCount(protoFeat); if ( ! prefix.isEmpty()) { protoFeat = prefix + protoFeat; } if (globalFlags.intern) { protoFeat = protoFeat.intern(); } accumulator.incrementCount(protoFeat, count); } }
@Override public Set<K2> secondKeySet() { Set<K2> result = Generics.newHashSet(); for (K1 k1 : firstKeySet()) { for (K2 k2 : getCounter(k1).keySet()) { result.add(k2); } } return result; }
private static ClassicCounter<List<String>> removeLowCountPaths(ClassicCounter<List<String>> paths, double thresh) { ClassicCounter<List<String>> result = new ClassicCounter<>(); int numRetained = 0; for (List<String> path : paths.keySet()) { double count = paths.getCount(path); if (count >= thresh) { result.setCount(path, count); numRetained++; } } System.out.println("retained " + numRetained); return result; }
public void printStateCounts() { log.info(); log.info("Annotated state counts"); Set<String> keys = annotatedStateCounts.keySet(); List<String> keyList = new ArrayList<>(keys); Collections.sort(keyList); for (String s : keyList) { log.info(s + "\t" + annotatedStateCounts.getCount(s)); } }
/** */ @Override public double getCount(K1 o1, K2 o2) { ClassicCounter<K2> c = getCounter(o1); if (c.totalCount() == 0.0 && !c.keySet().contains(o2)) { return defaultReturnValue(); } return c.getCount(o2); }
public static <T> TransducerGraph createGraphFromPaths(ClassicCounter<List<T>> pathCounter, int markovOrder) { TransducerGraph graph = new TransducerGraph(); // empty for (List<T> path : pathCounter.keySet()) { double count = pathCounter.getCount(path); addOnePathToGraph(path, count, markovOrder, graph); } return graph; }
@Override public MLEDependencyGrammar formResult() { wordIndex.addToIndex(Lexicon.UNKNOWN_WORD); ChineseSimWordAvgDepGrammar dg = new ChineseSimWordAvgDepGrammar(tlpParams, directional, useDistance, useCoarseDistance, op.trainOptions.basicCategoryTagsInDependencyGrammar, op, wordIndex, tagIndex); if (lex == null) { throw new RuntimeException("Attempt to create ChineseSimWordAvgDepGrammar before Lexicon!!!"); } else { dg.setLex(lex); } for (IntDependency dependency : dependencyCounter.keySet()) { dg.addRule(dependency, dependencyCounter.getCount(dependency)); } return dg; }
@Override public DependencyGrammar formResult() { wordIndex.addToIndex(Lexicon.UNKNOWN_WORD); MLEDependencyGrammar dg = new MLEDependencyGrammar(tlpParams, directional, useDistance, useCoarseDistance, basicCategoryTagsInDependencyGrammar, op, wordIndex, tagIndex); for (IntDependency dependency : dependencyCounter.keySet()) { dg.addRule(dependency, dependencyCounter.getCount(dependency)); } return dg; }
public ClassicCounter<Pair<K1, K2>> flatten() { ClassicCounter<Pair<K1, K2>> result = new ClassicCounter<>(); result.setDefaultReturnValue(defaultValue); for (K1 key1 : firstKeySet()) { ClassicCounter<K2> inner = getCounter(key1); for (K2 key2 : inner.keySet()) { result.setCount(new Pair<>(key1, key2), inner.getCount(key2)); } } return result; }
public void printRuleCounts() { log.info(); for (Tree t : annotatedRuleCounts.keySet()) { log.info(annotatedRuleCounts.getCount(t) + "\t" + t.label().value() + " -->"); for (Tree dtr : t.getChildrenAsList()) { log.info(" "); log.info(dtr.label().value()); } log.info(); } }