Java Code Examples for com.google.common.collect.Multisets#copyHighestCountFirst()

The following examples show how to use com.google.common.collect.Multisets#copyHighestCountFirst() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlotMachineSimulation.java    From levelup-java-exercises with Apache License 2.0 8 votes vote down vote up
/**
 * Method should return the number of times an occurrence of a reel
 * 
 * @param reels
 * @return
 */
static int determinePayOutPercentage(List<String> reels) {

	Multiset<String> reelCount = HashMultiset.create();
	reelCount.addAll(reels);

	// order the number of elements by the higest
	ImmutableMultiset<String> highestCountFirst = Multisets.copyHighestCountFirst(reelCount);

	int count = 0;
	for (Entry<String> entry : highestCountFirst.entrySet()) {
		count = entry.getCount();
		break;
	}
	return count;
}
 
Example 2
Source File: TimeGraphViewTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Test the line entries
 */
@Test
public void testTimeLine() {
    String lines = "pulse";
    resetTimeRange();
    SWTBotTimeGraph timegraph = fTimeGraph;
    assertEquals(0, timegraph.selection().columnCount());
    ImageHelper currentImage = ImageHelper.waitForNewImage(fBounds, null);
    SWTBotTimeGraphEntry entry = timegraph.getEntry(lines);
    // make sure it's visible
    entry = timegraph.getEntry(lines).select();
    ImageHelper.waitForNewImage(fBounds, currentImage);
    Rectangle rect = entry.absoluteLocation();
    ImageHelper image = ImageHelper.grabImage(rect);
    ImmutableMultiset<RGB> ms = Multisets.copyHighestCountFirst(image.getHistogram());
    int black = ms.count(new RGB(0, 0, 0));
    RGB bgColor = ms.elementSet().iterator().next();
    int bgCount = ms.count(bgColor);
    float actual = ((float) black) / (bgCount);
    assertEquals(0.113f, actual, 0.05f);
}
 
Example 3
Source File: Word2VecTrainer.java    From Word2VecJava with MIT License 6 votes vote down vote up
/** @return Tokens with their count, sorted by frequency decreasing, then lexicographically ascending */
private ImmutableMultiset<String> filterAndSort(final Multiset<String> counts) {
	// This isn't terribly efficient, but it is deterministic
	// Unfortunately, Guava's multiset doesn't give us a clean way to order both by count and element
	return Multisets.copyHighestCountFirst(
			ImmutableSortedMultiset.copyOf(
					Multisets.filter(
							counts,
							new Predicate<String>() {
								@Override
								public boolean apply(String s) {
									return counts.count(s) >= minFrequency;
								}
							}
					)
			)
	);
	
}
 
Example 4
Source File: CorpusAnalysis.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
public static ImmutableMultiset<Symbol> toRealisCounts(
    final ImmutableSet<TypeRoleFillerRealis> equivClasses) {
  return Multisets.copyHighestCountFirst(
      ImmutableMultiset.copyOf(Iterables.transform(equivClasses, Functions.compose(RealisSymbol, Realis))));
  /*
  final ImmutableMultimap<KBPRealis, TypeRoleFillerRealis> realisToEquivClass = Multimaps.index(equivClasses, TypeRoleFillerRealis.realisFunction());

  final List<ElementWithCount> elements = Lists.newArrayList();
  for(final Map.Entry<KBPRealis, Collection<TypeRoleFillerRealis>> entry : realisToEquivClass.asMap().entrySet()) {
    elements.add( ElementWithCount.from(entry.getKey(), entry.getValue().size()) );
  }

  Collections.sort(elements, ElementCount);
  return ImmutableList.copyOf(elements);
  */
}
 
Example 5
Source File: CorpusAnalysis.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
public static ImmutableMultiset<Symbol> toMentionTypeCounts(
    final ImmutableSet<TypeRoleFillerRealis> targetEquivClasses,
    final ImmutableMultimap<TypeRoleFillerRealis, AssessedResponse> equivClassToAssessedResponse) {
  final ImmutableMultiset.Builder<Symbol> mentionTypes = ImmutableMultiset.builder();

  for(final TypeRoleFillerRealis equivClass : targetEquivClasses) {
    final AssessedResponse assessedResponse = Collections.max(equivClassToAssessedResponse.get(equivClass), Old2014ID);

    if(assessedResponse.response().role() == TIME) {
      mentionTypes.add(TIME);
    }
    else {
      final Optional<FillerMentionType> mentionType =
          assessedResponse.assessment().mentionTypeOfCAS();
      if (mentionType.isPresent()) {
        mentionTypes.add(Symbol.from(mentionType.get().name()));
      }
    }
  }

  return Multisets.copyHighestCountFirst(mentionTypes.build());
}
 
Example 6
Source File: CorpusAnalysis.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
public static ImmutableMultiset<Symbol> toEventHopperCounts(final ImmutableSet<EventArgumentLinking> linkings) {
  final ImmutableMultiset.Builder<Symbol> ret = ImmutableMultiset.builder();

  for(final EventArgumentLinking eal : linkings) {
    for (final TypeRoleFillerRealisSet ef : eal.eventFrames()) {
      final ImmutableSet<Symbol> eventTypes = ImmutableSet.copyOf(FluentIterable.from(ef.asSet())
          .transform(type()));

      if(eventTypes.size()==1) {
        final Symbol eventType = FluentIterable.from(eventTypes).first().get();
        ret.add(eventType);
      }
      else {
        log.info("ERROR: a responseLinking set from document {} has multiple event types", eal.docID().toString());
      }
    }
  }

  return Multisets.copyHighestCountFirst(ret.build());
}
 
Example 7
Source File: CorpusAnalysis.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
public static ImmutableMultiset<Symbol> toNumberOfDocsPerEventType(
    final ImmutableSet<TypeRoleFillerRealis> equivClasses) {

  // for each docid, a set of event types
  final ImmutableMap<Symbol, ImmutableSet<Symbol>> eventTypesInEachDoc = getEventTypesInEachDoc(equivClasses);

  final ImmutableMultiset.Builder<Symbol> ret = ImmutableMultiset.builder();

  for(final Map.Entry<Symbol, ImmutableSet<Symbol>> entry : eventTypesInEachDoc.entrySet()) {
    for(final Symbol et : entry.getValue()) {
      ret.add(et);
    }
  }

  return Multisets.copyHighestCountFirst(ret.build());
}
 
Example 8
Source File: LinkArrayWritable.java    From wikireverse with MIT License 5 votes vote down vote up
public String getMostUsedArticleCasing() {
	HashMultiset<String> articleNames = HashMultiset.create();
	String result;

	for (Writable writable: super.get()) {
		LinkWritable link = (LinkWritable)writable;
		articleNames.add(link.getArticle().toString());
	}

	ImmutableMultiset<String> sorted = Multisets.copyHighestCountFirst(articleNames);
	result = (String)sorted.elementSet().toArray()[0];
	
	return result;
}
 
Example 9
Source File: CorpusAnalysis.java    From tac-kbp-eal with MIT License 4 votes vote down vote up
public static ImmutableMultiset<Symbol> toEventRoleCounts(
    final ImmutableSet<TypeRoleFillerRealis> equivClasses) {
  return Multisets.copyHighestCountFirst(
      ImmutableMultiset.copyOf(Iterables.transform(equivClasses, EventTypeRole)));
}