Example usage for com.google.common.collect Multiset entrySet

List of usage examples for com.google.common.collect Multiset entrySet

Introduction

In this page you can find the example usage for com.google.common.collect Multiset entrySet.

Prototype

Set<Entry<E>> entrySet();

Source Link

Document

Returns a view of the contents of this multiset, grouped into Multiset.Entry instances, each providing an element of the multiset and the count of that element.

Usage

From source file:org.sonar.core.util.MultiSets.java

/**
 * Returns a copy of {@code multiset} as a {@link List} whose iteration order is
 * highest count first, with ties broken by the iteration order of the original multiset.
 *///from ww w  .  j  av  a 2s. c om
public static <E> List<Multiset.Entry<E>> listOrderedByHighestCounts(Multiset<E> multiset) {
    return DECREASING_COUNT_ORDERING.sortedCopy(multiset.entrySet());
}

From source file:com.addthis.hydra.data.filter.value.ValueFilterGrepTags.java

private static ValueMap multisetToValueMap(Multiset<String> matches) {
    ValueMap valueMap = ValueFactory.createMap();
    for (Multiset.Entry<String> match : matches.entrySet()) {
        valueMap.put(match.getElement(), ValueFactory.create(match.getCount()));
    }// www .  j  a v  a2  s.co m
    return valueMap;
}

From source file:edu.byu.nlp.util.Multisets2.java

public static <T> MinMaxTracker<Integer> getMinMax(Multiset<T> mset) {
    MinMaxTracker<Integer> tracker = MinMaxTracker.create();
    for (com.google.common.collect.Multiset.Entry<T> entry : mset.entrySet()) {
        tracker.offer(entry.getCount(), entry.getElement());
    }/*from   w  ww . jav  a 2s  .c o  m*/
    return tracker;
}

From source file:edu.byu.nlp.util.Multisets2.java

public static <T> ArgMinMaxTracker<Integer, T> getArgMinMax(RandomGenerator rnd, int topk, Multiset<T> mset) {
    ArgMinMaxTracker<Integer, T> tracker = ArgMinMaxTracker.create(rnd, topk);
    for (com.google.common.collect.Multiset.Entry<T> entry : mset.entrySet()) {
        tracker.offer(entry.getCount(), entry.getElement());
    }/*from   ww w.j  a v  a  2s  . co m*/
    return tracker;
}

From source file:com.github.fhirschmann.clozegen.lib.multiset.WriteMultisets.java

/**
 * Writes a multiset to a file. The elements will be written to a tab-separated
 * file with the string representation of the elements on the left-hand side and
 * the corresponding counts on the right-hand side.
 *
 * @param multiset the multiset to write from
 * @param minFrequency the minimum frequency a word must have in order to be written
 * @param file the file to write to//ww w  .  j av a  2 s. c  om
 * @throws IOException on errors opening/writing to the file
 */
public static void writeMultiSet(final Multiset<String> multiset, final int minFrequency, final File file)
        throws IOException {
    final BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));

    for (Multiset.Entry<String> entry : multiset.entrySet()) {
        if (entry.getCount() >= minFrequency) {
            writeMultiSetLine(bufferedWriter, entry.getElement().toString(), entry.getCount());
        }
    }
    bufferedWriter.close();
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.particlefilter.ParticleFilter.java

public static double getEffectiveSampleSize(Multiset<Particle> particles)
        throws BadProbabilityParticleFilterException {
    double Wnorm = 0.0;
    for (final Multiset.Entry<Particle> p : particles.entrySet()) {
        final double weight = p.getElement().getWeight();
        Wnorm += weight * p.getCount();/*from w  ww  . j a va  2  s  .  c  om*/
    }

    if (Wnorm == 0)
        return 0d;

    double Wvar = 0.0;
    for (final Multiset.Entry<Particle> p : particles.entrySet()) {
        final double weight = p.getElement().getWeight();
        Wvar += FastMath.pow(weight / Wnorm, 2) * p.getCount();
    }

    if (Double.isInfinite(Wvar) || Double.isNaN(Wvar))
        throw new BadProbabilityParticleFilterException("effective sample size numerical error: Wvar=" + Wvar);

    return 1 / Wvar;
}

From source file:org.sonar.api.utils.KeyValueFormat.java

public static String format(Multiset multiset) {
    return formatEntries(multiset.entrySet(), newToStringConverter());
}

From source file:org.sonar.api.utils.KeyValueFormat.java

/**
 * @since 2.7/*from   w w  w  .jav  a  2 s  .co m*/
 */
public static <K> String format(Multiset<K> multiset, Converter<K> keyConverter) {
    return formatEntries(multiset.entrySet(), keyConverter);
}

From source file:edu.cornell.cs.nlp.spf.test.ccg.lambda.SingleSentencePartialCreditTestingStatistics.java

private static PartialCreditTriplet partialCompare(LogicalExpression gold, LogicalExpression label) {
    final Multiset<Pair<? extends LogicalExpression, ? extends LogicalExpression>> goldPairs = GetPredConstPairs
            .of(gold);/*from   w  w  w. j a va2  s.  c  o m*/
    final Multiset<Pair<? extends LogicalExpression, ? extends LogicalExpression>> labelPairs;
    if (label == null) {
        labelPairs = HashMultiset.create();
    } else {
        labelPairs = GetPredConstPairs.of(label);
    }

    // The "intersection" of the gold and label pair sets = the number of
    // matches
    final Multiset<Pair<? extends LogicalExpression, ? extends LogicalExpression>> intersection = HashMultiset
            .create();

    for (final Entry<Pair<? extends LogicalExpression, ? extends LogicalExpression>> entry : goldPairs
            .entrySet()) {
        intersection.setCount(entry.getElement(),
                Math.min(entry.getCount(), labelPairs.count(entry.getElement())));
    }

    return new PartialCreditTriplet(goldPairs.size(), labelPairs.size(), intersection.size());
}

From source file:org.joda.beans.ser.GuavaSerIteratorFactory.java

/**
 * Gets an iterator wrapper for {@code Multiset}.
 * /* ww  w  . j  a v a 2 s .  c o  m*/
 * @param multiset  the collection, not null
 * @param declaredType  the declared type, not null
 * @param valueType  the value type, not null
 * @param valueTypeTypes  the generic parameters of the value type
 * @return the iterator, not null
 */
@SuppressWarnings("rawtypes")
public static final SerIterator multiset(final Multiset<?> multiset, final Class<?> declaredType,
        final Class<?> valueType, final List<Class<?>> valueTypeTypes) {
    return new SerIterator() {
        private final Iterator it = multiset.entrySet().iterator();
        private Multiset.Entry current;

        @Override
        public String metaTypeName() {
            return "Multiset";
        }

        @Override
        public boolean metaTypeRequired() {
            return Multiset.class.isAssignableFrom(declaredType) == false;
        }

        @Override
        public SerCategory category() {
            return SerCategory.COUNTED;
        }

        @Override
        public int size() {
            return multiset.entrySet().size();
        }

        @Override
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public void next() {
            current = (Multiset.Entry) it.next();
        }

        @Override
        public int count() {
            return current.getCount();
        }

        @Override
        public Class<?> valueType() {
            return valueType;
        }

        @Override
        public List<Class<?>> valueTypeTypes() {
            return valueTypeTypes;
        }

        @Override
        public Object value() {
            return current.getElement();
        }
    };
}