本文整理汇总了Java中com.google.common.collect.ImmutableMultiset.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableMultiset.Builder方法的具体用法?Java ImmutableMultiset.Builder怎么用?Java ImmutableMultiset.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.ImmutableMultiset
的用法示例。
在下文中一共展示了ImmutableMultiset.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLotsOfRandomInserts
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Test
public void testLotsOfRandomInserts() {
int lots = 50000;
final FibonacciQueue<Integer> queue = FibonacciQueue.create();
// Insert lots of random numbers.
final ImmutableMultiset.Builder<Integer> insertedBuilder = ImmutableMultiset.builder();
final Random random = new Random();
for (int i = 0; i < lots; i++) {
int r = random.nextInt();
insertedBuilder.add(r);
queue.add(r);
}
final Multiset<Integer> inserted = insertedBuilder.build();
assertEquals(lots, queue.size());
// Ensure it contains the same multiset of values that we put in
assertEquals(inserted, ImmutableMultiset.copyOf(queue));
// Ensure the numbers come out in increasing order.
final List<Integer> polled = Lists.newLinkedList();
while (!queue.isEmpty()) {
polled.add(queue.poll());
}
assertTrue(Ordering.<Integer>natural().isOrdered(polled));
// Ensure the same multiset of values came out that we put in
assertEquals(inserted, ImmutableMultiset.copyOf(polled));
assertEquals(0, queue.size());
}
示例2: indexArgsToEventHopper
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
private ImmutableSetMultimap<RoleAndID, DocAndHopper> indexArgsToEventHopper(final Symbol docID,
final EREDocument ereDoc, final ImmutableMultiset.Builder<String> allEREEventTypes) {
final ImmutableSetMultimap.Builder<RoleAndID, DocAndHopper> argsToDocEventsB =
ImmutableSetMultimap.builder();
for (final EREEvent ereEvent : ereDoc.getEvents()) {
boolean loggedType = false;
for (final EREEventMention ereEventMention : ereEvent.getEventMentions()) {
for (final EREArgument ereEventArg : ereEventMention.getArguments()) {
if (ereEventArg instanceof EREEntityArgument) {
final Optional<EREEntity> entityFiller = ((EREEntityArgument) ereEventArg).ereEntity();
if (entityFiller.isPresent()) {
final Optional<Symbol> mappedEventType =
ScoringUtils.mapERETypesToDotSeparated(ontologyMapper, ereEventMention);
final Optional<Symbol> mappedEventRole =
ontologyMapper.eventRole(Symbol.from(ereEventArg.getRole()));
if (mappedEventType.isPresent() && mappedEventRole.isPresent()) {
if (!loggedType) {
// we only want to log events which meet the criteria above, but we only
// want to count each document event once
allEREEventTypes.add(mappedEventType.get().asString());
loggedType = true;
}
argsToDocEventsB.put(
RoleAndID.of(
mappedEventType.get().asString(),
mappedEventRole.get().asString(), entityFiller.get().getID()),
DocAndHopper.of(docID.asString(), ereEvent.getID(),
mappedEventType.get().asString()));
}
}
}
}
}
}
return argsToDocEventsB.build();
}
示例3: multiset
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
private static <T> ImmutableMultiset<T> multiset(Map<T, Integer> counts) {
ImmutableMultiset.Builder<T> builder = ImmutableMultiset.builder();
for (Map.Entry<T, Integer> entry : counts.entrySet()) {
builder.addCopies(entry.getKey(), entry.getValue());
}
return builder.build();
}
示例4: toImmutableMultiset
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public static <T> Collector<T, ?, ImmutableMultiset<T>> toImmutableMultiset() {
return new Collector<T, ImmutableMultiset.Builder<T>, ImmutableMultiset<T>>() {
@Override
public Supplier<ImmutableMultiset.Builder<T>> supplier() {
return ImmutableMultiset::builder;
}
@Override
public BiConsumer<ImmutableMultiset.Builder<T>, T> accumulator() {
return ImmutableMultiset.Builder::add;
}
@Override
public BinaryOperator<ImmutableMultiset.Builder<T>> combiner() {
return (b1, b2) -> b1.addAll(b2.build());
}
@Override
public Function<ImmutableMultiset.Builder<T>, ImmutableMultiset<T>> finisher() {
return ImmutableMultiset.Builder::build;
}
@Override
public Set<Characteristics> characteristics() {
return ImmutableSet.of();
}
};
}
示例5: toImmutableSetEntriedMultiset
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
private static <T> ImmutableMultiset<ImmutableSet<T>> toImmutableSetEntriedMultiset(
Multiset<Set<T>> multiset) {
ImmutableMultiset.Builder<ImmutableSet<T>> builder = ImmutableMultiset.builder();
for (Entry<Set<T>> entry : multiset.entrySet()) {
builder.addCopies(ImmutableSet.copyOf(entry.getElement()), entry.getCount());
}
return builder.build();
}
示例6: construct
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public ImmutableMultiset construct(int entries) {
ImmutableMultiset.Builder builder = ImmutableMultiset.builder();
for (int i = 0; i < entries; i++) {
builder.add(newEntry());
}
return builder.build();
}
示例7: combiner
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public BinaryOperator<ImmutableMultiset.Builder<T>> combiner() {
return (a, b) -> {
a.addAll(b.build());
return a;
};
}
示例8: transformedCopy
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
/**
* Returns a new Multiset resulting from transforming each element of the input Multiset by a
* function. If two or more elements are mapped to the same value by the function, their counts
* will be summed in the new Multiset.
*/
public static <A, B> ImmutableMultiset<B> transformedCopy(Multiset<A> ms,
Function<A, B> func) {
final ImmutableMultiset.Builder<B> ret = ImmutableMultiset.builder();
for (final Multiset.Entry<A> entry : ms.entrySet()) {
final B transformedElement = func.apply(entry.getElement());
ret.addCopies(transformedElement, entry.getCount());
}
return ret.build();
}
示例9: multiset
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
private static <T> ImmutableMultiset<T> multiset(Map<T, Integer> counts) {
ImmutableMultiset.Builder<T> builder = ImmutableMultiset.builder();
for (Entry<T, Integer> entry : counts.entrySet()) {
builder.addCopies(entry.getKey(), entry.getValue());
}
return builder.build();
}
示例10: processElement
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) throws Exception {
AlleleFreq af = null;
af = c.element().getValue().getOnly(refFreqTag, null);
if (af == null || af.getAltBases() == null) {
// no ref stats
return;
}
if (af.getAltBases().size() != 1) {
throw new IllegalArgumentException("Wrong number (" + af.getAltBases().size() + ") of"
+ " alternate bases for Position " + c.element().getKey());
}
Iterable<ReadBaseQuality> reads = c.element().getValue().getAll(readCountsTag);
ImmutableMultiset.Builder<ReadQualityCount> rqSetBuilder = ImmutableMultiset.builder();
for (ReadBaseQuality r : reads) {
ReadQualityCount.Base b;
if (af.getRefBases().equals(r.getBase())) {
b = ReadQualityCount.Base.REF;
} else if (af.getAltBases().get(0).equals(r.getBase())) {
b = ReadQualityCount.Base.NONREF;
} else {
b = ReadQualityCount.Base.OTHER;
}
ReadQualityCount rqc = new ReadQualityCount();
rqc.setBase(b);
rqc.setQuality(r.getQuality());
rqSetBuilder.add(rqc);
}
ReadCounts rc = new ReadCounts();
rc.setRefFreq(af.getRefFreq());
for (Multiset.Entry<ReadQualityCount> entry : rqSetBuilder.build().entrySet()) {
ReadQualityCount rq = entry.getElement();
rq.setCount(entry.getCount());
rc.addReadQualityCount(rq);
}
c.output(KV.of(c.element().getKey(), rc));
}
示例11: combiner
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public BinaryOperator<ImmutableMultiset.Builder<T>> combiner() {
return (a, b) -> {
a.addAll(b.build());
return a;
};
}
示例12: getLineTypes
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public Multiset<LineType> getLineTypes()
{
ImmutableMultiset.Builder<LineType> builder = ImmutableMultiset.builder();
builder.addCopies(COMMENT, getInt(COMMENTS));
builder.addCopies(VCF, getInt(VCFS));
builder.addCopies(CADD, getInt(CADDS));
builder.addCopies(ERROR, getInt(ERRORS));
builder.addCopies(INDEL_NOCADD, getInt(INDELS_NOCADD));
builder.addCopies(SKIPPED, getInt(SKIPPEDS));
return builder.build();
}
示例13: copyMerging
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
public CorefAnnotation copyMerging(CorefAnnotation toMerge) {
checkArgument(docId == toMerge.docId());
// (1) initialize our mapping of CASes to coref indices with the
// mappings seen in *baseline*. This is used to track the mappings during
// construction, but ret (below) is used to construct the result
final Map<KBPString, Integer> newCASToCoref = Maps.newHashMap(CASesToIDs);
final Builder ret = strictCopyBuilder();
// the next empty index for adding a new coref cluster
// this potentially could fail due to overflow, but the chances are tiny and
// the stakes are low, so we won't worry about it
int nextIndex = newCASToCoref.isEmpty() ? 1 : (1 + Collections.max(newCASToCoref.values()));
// (2) gather a map of coref IDs to the CASes in the corresponding cluster
// from *additional*
final Multimap<Integer, KBPString> additionalCorefToCAS = toMerge.idToCASes;
for (final Map.Entry<KBPString, Integer> newCorefRelation : toMerge.CASesToIDs.entrySet()) {
final int corefId = newCorefRelation.getValue();
final KBPString CAS = newCorefRelation.getKey();
if (!newCASToCoref.containsKey(CAS)) {
// this CAS was not previously coreffed
final StringBuilder msg = new StringBuilder();
// use the baseline cluster which contains most clustermates of CAS
// in "additional"
final Collection<KBPString> clusterMates = additionalCorefToCAS.get(
corefId);
msg.append("\t\tFor CAS ").append(CAS).append(" no coref ID was found in baseline. It has ")
.append(clusterMates.size()).append(" clustermates\n");
// We use an ImmutableMultiset to have deterministic iteration order
// and therefore deterministic tie-breaking if two clusters tie
// on clustermate count
final ImmutableMultiset.Builder<Integer> bCorefIDsOfClusterMatesInBaseline =
ImmutableMultiset.builder();
for (final KBPString clusterMate : clusterMates) {
final Integer corefForClusterMate = newCASToCoref.get(clusterMate);
if (corefForClusterMate != null) {
// we don't have to worry about iterating over the target CAS itself
// because we know it will never pass this check
bCorefIDsOfClusterMatesInBaseline.add(corefForClusterMate);
msg.append("\t\t\t").append(clusterMate).append(" ---> ")
.append(corefForClusterMate).append("\n");
} else {
msg.append("\t\t\t").append(clusterMate).append(" ---> unknown\n");
}
}
final ImmutableMultiset<Integer> corefIDsOfClusterMatesInBaseline =
bCorefIDsOfClusterMatesInBaseline.build();
final int newCorefIdx;
if (!corefIDsOfClusterMatesInBaseline.isEmpty()) {
// we know this will be non-null due to the above check
newCorefIdx = getFirst(copyHighestCountFirst(corefIDsOfClusterMatesInBaseline), null);
msg.append("\t\tMapping to dominant cluster mate cluster ").append(newCorefIdx)
.append("\n");
} else {
// if we had no clustermates with known coref indices, start a new cluster.
// When it comes time to assign coref to our clustermates, if any,
// then we know they will have at least one clustermate with a known coref ID
newCorefIdx = nextIndex;
nextIndex = nextFreeIndex(nextIndex, newCASToCoref);
msg.append("\t\tMapping to new cluster ").append(newCorefIdx).append("\n");
}
log.info(msg.toString());
newCASToCoref.put(CAS, newCorefIdx);
ret.corefCAS(CAS, newCorefIdx);
}
}
for (final KBPString unannotatedCAS : toMerge.unannotated) {
ret.addUnannotatedCAS(unannotatedCAS);
}
return ret.build();
}
示例14: gatherEntryPointsFound
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
private ImmutableSetMultimap<String, EntryPoint> gatherEntryPointsFound(
final ImmutableSet<Symbol> docIDsToScore, final File baseSystemDir,
final Set<String> systemsToUse, final ImmutableMap<Symbol, File> goldDocIDToFileMap,
final CoreNLPXMLLoader coreNLPXMLLoader,
final ImmutableMap<Symbol, File> coreNLPProcessedRawDocs) throws IOException {
final ImmutableSetMultimap.Builder<String, EntryPoint> entryPointsFoundBySystemB =
ImmutableSetMultimap.builder();
// we log the distribution of event types in the corpus for diagnostic purposes
final ImmutableMultiset.Builder<String> allEREEventTypes = ImmutableMultiset.builder();
for (Symbol docID : docIDsToScore) {
// EvalHack - 2016 dry run contains some files for which Serif spuriously adds this document ID
docID = Symbol.from(docID.asString().replace("-kbp", ""));
final EREDocument ereDoc = getEREDocument(docID, goldDocIDToFileMap);
final CoreNLPDocument coreNLPDoc =
coreNLPXMLLoader.loadFrom(coreNLPProcessedRawDocs.get(docID));
final EREAligner ereAligner = EREAligner.create(ereDoc, Optional.of(coreNLPDoc),
ontologyMapper);
// build an index of RoleAndIds to hoppers for lookup in the loop below
final ImmutableSetMultimap<RoleAndID, DocAndHopper> argsToDocEvents =
indexArgsToEventHopper(docID, ereDoc, allEREEventTypes);
for (final String system : systemsToUse) {
final File systemDir = new File(baseSystemDir, system);
try (final SystemOutputStore systemOutput = KBPEA2016OutputLayout.get().open(systemDir)) {
final ImmutableSet.Builder<RoleAndID> alignedEREArgs = ImmutableSet.builder();
// first, gather all document-level arguments which this system found which can
// be aligned to ERE
final Iterable<Response> responses = FluentIterable
.from(systemOutput.read(docID).arguments().responses())
.filter(BANNED_ROLES_FILTER)
.filter(Predicates.compose(not(in(BANNED_EVENTS)), type()));
for (final Response response : responses) {
final Optional<ScoringCorefID> argID =
ereAligner.argumentForResponse(response);
// query entry points can only be entities, not value fillers
if (argID.isPresent() && argID.get().scoringEntityType().isEntityType()) {
alignedEREArgs.add(RoleAndID.of(response.type().asString(), response.role().asString(),
argID.get().withinTypeID()));
}
}
// second, map these to document-level hoppers
for (final RoleAndID alignedArg : alignedEREArgs.build()) {
for (final DocAndHopper docAndHopper : argsToDocEvents.get(alignedArg)) {
entryPointsFoundBySystemB.put(system, EntryPoint.of(docAndHopper, alignedArg));
}
}
}
}
}
log.info("Distribution of event types in ERE: {}",
Multisets.copyHighestCountFirst(allEREEventTypes.build()));
return entryPointsFoundBySystemB.build();
}
示例15: supplier
import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public Supplier<ImmutableMultiset.Builder<T>> supplier() {
return ImmutableMultiset::builder;
}