public Iterator<E> iterator() { return keySet().iterator(); }
TagCount(IntCounter<String> tagCounts) { for (String tag : tagCounts.keySet()) { map.put(tag, tagCounts.getIntCount(tag)); } getTagsCache = map.keySet().toArray(new String[map.keySet().size()]); sumCache = calculateSumCache(); }
/** * Finds and returns the key in this Counter with the largest count. * Ties are broken by comparing the objects using the given tie breaking * Comparator, favoring Objects that are sorted to the front. This is useful * if the keys are numeric and there is a bias to prefer smaller or larger * values, and can be useful in other circumstances where random tie-breaking * is not desirable. Returns null if this Counter is empty. */ public E argmax(Comparator<E> tieBreaker) { int max = Integer.MIN_VALUE; E argmax = null; for (E key : keySet()) { int count = getIntCount(key); if (argmax == null || count > max || (count == max && tieBreaker.compare(key, argmax) < 0)) { max = count; argmax = key; } } return argmax; }
/** * A simple String representation of this TwoDimensionalCounter, which has * the String representation of each key pair * on a separate line, followed by the count for that pair. * The items are tab separated, so the result is a tab-separated value (TSV) * file. Iff none of the keys contain spaces, it will also be possible to * treat this as whitespace separated fields. */ @Override public String toString() { StringBuilder buff = new StringBuilder(); for (K1 key1 : map.keySet()) { IntCounter<K2> c = getCounter(key1); for (K2 key2 : c.keySet()) { double score = c.getCount(key2); buff.append(key1).append("\t").append(key2).append("\t").append(score).append("\n"); } } return buff.toString(); }
/** * 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 Set<K2> secondKeySet() { Set<K2> result = Generics.newHashSet(); for (K1 k1 : firstKeySet()) { for (K2 k2 : getCounter(k1).keySet()) { result.add(k2); } } return result; }
public Counter<Integer> lengthAccuracies() { Set<Integer> keys = Generics.newHashSet(); keys.addAll(lengthLabelsCorrect.keySet()); keys.addAll(lengthLabelsIncorrect.keySet()); Counter<Integer> results = new ClassicCounter<>(); for (Integer key : keys) { results.setCount(key, lengthLabelsCorrect.getCount(key) / (lengthLabelsCorrect.getCount(key) + lengthLabelsIncorrect.getCount(key))); } return results; }
/** */ public int getCount(K1 o1, K2 o2) { IntCounter<K2> c = getCounter(o1); if (c.totalCount() == 0 && !c.keySet().contains(o2)) { return defaultReturnValue(); } return c.getIntCount(o2); }
public void buildStateIndex() { stateIndex = new HashIndex<>(); for (String key : stateSplitCounts.keySet()) { for (int i = 0; i < stateSplitCounts.getIntCount(key); ++i) { stateIndex.addToIndex(state(key, i)); } } }
/** * Produces a new ConditionalCounter. * * @return a new ConditionalCounter, where order of indices is reversed */ @SuppressWarnings({"unchecked"}) public static <K1,K2> TwoDimensionalIntCounter<K2,K1> reverseIndexOrder(TwoDimensionalIntCounter<K1,K2> cc) { // the typing on the outerMF is violated a bit, but it'll work.... TwoDimensionalIntCounter<K2,K1> result = new TwoDimensionalIntCounter<>( (MapFactory) cc.outerMF, (MapFactory) cc.innerMF); for (K1 key1 : cc.firstKeySet()) { IntCounter<K2> c = cc.getCounter(key1); for (K2 key2 : c.keySet()) { int count = c.getIntCount(key2); result.setCount(key2, key1, count); } } return result; }
public IntCounter<Pair<K1, K2>> flatten() { IntCounter<Pair<K1, K2>> result = new IntCounter<>(); result.setDefaultReturnValue(defaultValue); for (K1 key1 : firstKeySet()) { IntCounter<K2> inner = getCounter(key1); for (K2 key2 : inner.keySet()) { result.setCount(new Pair<>(key1, key2), inner.getIntCount(key2)); } } return result; }
Set<String> reducedTags = lemmaReducedTagCounter.getCounter(lemma).keySet(); if (reducedTags.size() > 1) { System.out.printf("%s --> %s%n", word, lemma); for (String reducedTag : reducedTags) { int count = lemmaReducedTagCounter.getCount(lemma, reducedTag); String posTags = setToString(reducedTagTagCounter.getCounter(lemma+reducedTag).keySet()); System.out.printf("\t%s\t%d\t%s%n", reducedTag, count, posTags); for (String tag : tags) { System.out.println(tag); Set<String> reducedTags = tagReducedTagCounter.getCounter(tag).keySet(); for (String reducedTag : reducedTags) { int count = tagReducedTagCounter.getCount(tag, reducedTag);
for (int tagId : wordTag.getCounter(wordId).keySet()) { lexRules.add(new IntTaggedWord(wordId, tagId)); lexRules.add(new IntTaggedWord(nullWord, tagId));
for (TaggedWord word : datumCounter.keySet()) { int count = datumCounter.getIntCount(word); if (trainOnLowCount && count > trainCountThreshold) {
/** * 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 Set<K2> secondKeySet() { Set<K2> result = Generics.newHashSet(); for (K1 k1 : firstKeySet()) { for (K2 k2 : getCounter(k1).keySet()) { result.add(k2); } } return result; }
public Counter<Integer> lengthAccuracies() { Set<Integer> keys = Generics.newHashSet(); keys.addAll(lengthLabelsCorrect.keySet()); keys.addAll(lengthLabelsIncorrect.keySet()); Counter<Integer> results = new ClassicCounter<>(); for (Integer key : keys) { results.setCount(key, lengthLabelsCorrect.getCount(key) / (lengthLabelsCorrect.getCount(key) + lengthLabelsIncorrect.getCount(key))); } return results; }
public void buildStateIndex() { stateIndex = new HashIndex<>(); for (String key : stateSplitCounts.keySet()) { for (int i = 0; i < stateSplitCounts.getIntCount(key); ++i) { stateIndex.addToIndex(state(key, i)); } } }
public IntCounter<Pair<K1, K2>> flatten() { IntCounter<Pair<K1, K2>> result = new IntCounter<>(); result.setDefaultReturnValue(defaultValue); for (K1 key1 : firstKeySet()) { IntCounter<K2> inner = getCounter(key1); for (K2 key2 : inner.keySet()) { result.setCount(new Pair<>(key1, key2), inner.getIntCount(key2)); } } return result; }