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

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

Introduction

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

Prototype

Set<E> elementSet();

Source Link

Document

Returns the set of distinct elements contained in this multiset.

Usage

From source file:org.apache.mahout.math.random.Multinomial.java

public Multinomial(Multiset<T> counts) {
    this();/*from   ww  w .j a va2  s .  c om*/
    Preconditions.checkArgument(!counts.isEmpty(), "Need some data to build sampler");
    rand = RandomUtils.getRandom();
    for (T t : counts.elementSet()) {
        add(t, counts.count(t));
    }
}

From source file:edu.uci.ics.sourcerer.tools.java.component.model.cluster.ClusterMatcher.java

public Set<ClusterVersion> getClusterVersions(Collection<FqnVersion> fqns) {
    Multimap<FqnVersion, ClusterVersion> map = fqnVersionsToClusterVersions.get();
    Multiset<ClusterVersion> set = HashMultiset.create();
    for (FqnVersion fqn : fqns) {
        set.addAll(map.get(fqn));/*from w  ww .  j av  a 2  s  . co  m*/
    }
    Set<ClusterVersion> result = new HashSet<>();
    for (ClusterVersion version : set.elementSet()) {
        if (set.count(version) == version.getFqns().size()) {
            result.add(version);
        }
    }
    return result;
}

From source file:com.github.fhirschmann.clozegen.lib.generators.FrequencyGapGenerator.java

@Override
public Optional<Gap> generate(final int count) {
    if (model.getMultiset().contains(token)) {
        int tokenCount = model.getMultiset().count(token);
        Multiset<String> ms = HashMultiset.create();

        // compute a multiset with counts(x) = |count(x) - count(token)|
        for (Entry<String> entry : model.getMultiset().entrySet()) {
            ms.add(entry.getElement(), Math.abs(entry.getCount() - tokenCount));
        }/*w w w .  ja va 2  s .c om*/

        if (ms.elementSet().size() < count - 1) {
            // not enough data to create as many answer options as requested
            return Optional.absent();
        } else {
            return Optional.of(
                    Gap.with(token, Lists.reverse(MultisetUtils.sortedElementList(ms)).subList(0, count - 1)));
        }
    } else {
        // we have no knowledge of the word in question
        return Optional.absent();
    }
}

From source file:com.mapr.storm.CounterBolt.java

/**
 * Records and then clears all pending counts if we have crossed a window boundary
 * or have a bunch of data accumulated or if forced.
 * @param force  If true, then windows and such are ignored and the data is pushed out regardless
 *///w w w.  j  a  va2  s. c  o  m
private void recordCounts(boolean force) {
    long currentRecordWindowStart = (now() / reportingInterval) * reportingInterval;
    if (lastRecordOutput == 0) {
        lastRecordOutput = currentRecordWindowStart;
    }

    final int bufferedTuples = tupleLog.get().size();
    if (force || currentRecordWindowStart > lastRecordOutput || bufferedTuples > maxBufferedTuples) {
        if (force) {
            logger.info("Forced recording");
        } else if (bufferedTuples > maxBufferedTuples) {
            logger.info("Recording due to max tuples");
        } else {
            logger.info("Recording due to time");
        }

        // atomic get and set avoids the need to locks and still avoids races
        // grabbing the entire queue at once avoids contention as we count the queue elements
        Queue<Tuple> oldLog = tupleLog.getAndSet(new LinkedBlockingQueue<Tuple>());

        Multiset<String> counts = HashMultiset.create();
        for (Tuple tuple : oldLog) {
            counts.add(tuple.getString(0) + "\t" + tuple.getString(1));
        }

        // record all keys
        for (String keyValue : counts.elementSet()) {
            final int n = counts.count(keyValue);
            outputCollector.emit(oldLog, new Values(keyValue, n));
            count.addAndGet(n);
        }
        logger.info(String.format("Logged %d events", count.get()));

        for (Tuple tuple : oldLog) {
            outputCollector.ack(tuple);
        }
        lastRecordOutput = currentRecordWindowStart;
    }
}

From source file:edu.cmu.cs.lti.ark.fn.identification.training.AlphabetCreationThreaded.java

private void conjoinAndWriteAlphabet(final Multiset<String> unconjoinedFeatures, final int minimumCount,
        File alphabetFile) throws IOException {
    final BufferedWriter output = Files.newWriter(alphabetFile, Charsets.UTF_8);
    final int unconjoinedSize = unconjoinedFeatures.elementSet().size();
    try {//from www.j av a2 s  . c  o m
        logger.info("Writing alphabet.");
        int numUnconjoined = 0;
        int numConjoined = 0;
        for (String unconjoinedFeature : unconjoinedFeatures.elementSet()) {
            if (unconjoinedFeatures.count(unconjoinedFeature) >= minimumCount) {
                final Set<String> conjoinedFeatureNames = featureExtractor.getConjoinedFeatureNames(allFrames,
                        unconjoinedFeature);
                numConjoined += conjoinedFeatureNames.size();
                for (String feature : conjoinedFeatureNames) {
                    output.write(String.format("%s\n", feature));
                }
            }
            numUnconjoined++;
            if (numUnconjoined % 50 == 0) {
                logger.info("Unconjoined: " + numUnconjoined + " of " + unconjoinedSize);
                logger.info("Conjoined: " + numConjoined);
            }
        }
        logger.info("Done writing alphabet.");
    } finally {
        closeQuietly(output);
    }
}

From source file:uk.ac.ebi.intact.editor.services.admin.report.AssignmentReportService.java

@Transactional(value = "jamiTransactionManager", propagation = Propagation.REQUIRED, readOnly = true)
public List<AssignmentInfo> calculatePublicationReviewerAssignments(Date fromDate, Date toDate) {
    List<AssignmentInfo> assignmentInfos = new ArrayList<AssignmentInfo>();

    Query query = getIntactDao().getEntityManager()
            .createQuery("select distinct p from IntactPublication p join p.lifecycleEvents as e where "
                    + "e.cvEvent.shortName = :cvEvent and e.when >= :dateFrom and e.when <= :dateTo and e.note is null");
    query.setParameter("cvEvent", LifeCycleEventType.READY_FOR_CHECKING.shortLabel());
    query.setParameter("dateFrom", fromDate);
    query.setParameter("dateTo", new DateTime(toDate).plusDays(1).minusSeconds(1).toDate());

    List<IntactPublication> pubs = query.getResultList();

    Multiset<String> multiset = HashMultiset.create();

    for (IntactPublication pub : pubs) {
        for (LifeCycleEvent event : pub.getLifecycleEvents()) {
            multiset.add(pub.getCurrentReviewer().getLogin());
        }//  ww  w.  ja  v a 2s  .  co  m
    }

    int total = multiset.size();

    for (String reviewer : multiset.elementSet()) {
        int count = multiset.count(reviewer);
        int percentage = count * 100 / total;
        assignmentInfos.add(new AssignmentInfo(reviewer, count, percentage));
    }

    return assignmentInfos;
}

From source file:uk.ac.ebi.intact.editor.services.admin.report.AssignmentReportService.java

@Transactional(value = "jamiTransactionManager", propagation = Propagation.REQUIRED, readOnly = true)
public List<AssignmentInfo> calculateComplexReviewerAssignments(Date fromDate, Date toDate) {
    List<AssignmentInfo> assignmentInfos = new ArrayList<AssignmentInfo>();

    Query query = getIntactDao().getEntityManager()
            .createQuery("select distinct c from IntactComplex c join c.lifecycleEvents as e where "
                    + "e.cvEvent.shortName = :cvEvent and e.when >= :dateFrom and e.when <= :dateTo and e.note is null");
    query.setParameter("cvEvent", LifeCycleEventType.READY_FOR_CHECKING.shortLabel());
    query.setParameter("dateFrom", fromDate);
    query.setParameter("dateTo", new DateTime(toDate).plusDays(1).minusSeconds(1).toDate());

    List<IntactComplex> complexes = query.getResultList();

    Multiset<String> multiset = HashMultiset.create();

    for (IntactComplex pub : complexes) {
        for (LifeCycleEvent event : pub.getLifecycleEvents()) {
            multiset.add(pub.getCurrentReviewer().getLogin());
        }//from w w w  .j ava  2 s  . c  o  m
    }

    int total = multiset.size();

    for (String reviewer : multiset.elementSet()) {
        int count = multiset.count(reviewer);
        int percentage = count * 100 / total;
        assignmentInfos.add(new AssignmentInfo(reviewer, count, percentage));
    }

    return assignmentInfos;
}

From source file:org.apache.mahout.knn.generate.Multinomial.java

public Multinomial(Multiset<T> counts, int width) {
    Preconditions.checkArgument(counts.size() > 0, "Need some data to build sampler");
    rand = RandomUtils.getRandom();/*  w  ww.  j a  v  a2 s.c om*/
    List<WeightedThing<T>> things = Lists.newArrayList();
    double n = counts.size();
    for (T t : counts.elementSet()) {
        things.add(new WeightedThing<T>(t, counts.count(t) / n));
    }
    init(width, things);
}

From source file:com.seajas.search.codex.service.social.SocialProfileService.java

protected List<MentionedDto> buildTwitterMentionedList(Multiset<Long> mentionedCounter) {
    List<MentionedDto> mentions = Lists.newArrayList();
    List<Long> ids = Lists.newArrayList(mentionedCounter.elementSet());
    List<TwitterProfile> twitterProfiles = socialFacade.getTwitterProfiles(ids);
    Map<Long, TwitterProfile> profileMap = Maps.newHashMap();
    for (TwitterProfile twitterProfile : twitterProfiles) {
        profileMap.put(twitterProfile.getId(), twitterProfile);
    }//from   w  w w  . j  av  a2  s  . c om

    List<String> profileImageUrls = Lists.newArrayList();
    for (Long mentionId : mentionedCounter.elementSet()) {
        int count = mentionedCounter.count(mentionId);

        TwitterProfile profile = profileMap.get(mentionId);
        if (profile != null) {
            SocialProfileDto socialProfileDto = SocialProfileDto.translate(profile);
            profileImageUrls.add(profile.getProfileImageUrl());
            mentions.add(new MentionedDto(socialProfileDto, count));
        }
    }

    if (!profileImageUrls.isEmpty()) {
        List<String> mediaUrls = this.storeImagesOnMediaServer(profileImageUrls);
        for (int i = 0; i < mentions.size(); i++) {
            mentions.get(i).getSocialProfile().setProfileImageMediaUrl(mediaUrls.get(i));
        }
    }

    return mentions;
}

From source file:org.dllearner.algorithms.pattern.OWLAxiomPatternFinder.java

private synchronized void addOntologyPatterns(URI physicalURI, OWLOntology ontology,
        Multiset<OWLAxiom> patterns) {
    int ontologyId = addOntology(physicalURI, ontology);
    for (OWLAxiom pattern : patterns.elementSet()) {
        try {//from   w w  w  .ja v a  2s.co m
            int patternId = addPattern(pattern);
            int occurrences = patterns.count(pattern);
            insertOntologyPatternPs.setInt(1, ontologyId);
            insertOntologyPatternPs.setInt(2, patternId);
            insertOntologyPatternPs.setInt(3, occurrences);
            insertOntologyPatternPs.execute();
        } catch (SQLException e) {
            System.err.println("Adding pattern\n" + pattern + "\nfailed." + e.getMessage());
        }
    }
}