当前位置: 首页>>代码示例>>Java>>正文


Java ImmutableMultiset.Builder方法代码示例

本文整理汇总了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());
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:27,代码来源:FibonacciQueueTest.java

示例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();
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:41,代码来源:DerivedQuerySelector2016.java

示例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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:ListenerCallQueueTest.java

示例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();
        }
    };
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:29,代码来源:CommonUtil.java

示例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();
}
 
开发者ID:AlexLandau,项目名称:ggp-tournament,代码行数:9,代码来源:SwissFormat2Runner.java

示例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();
}
 
开发者ID:DimitrisAndreou,项目名称:memory-measurer,代码行数:8,代码来源:ElementCostOfDataStructures.java

示例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;
  };
}
 
开发者ID:atomix,项目名称:atomix,代码行数:8,代码来源:TranscodingAsyncConsistentMultimap.java

示例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();
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:17,代码来源:CollectionUtils.java

示例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();
}
 
开发者ID:google,项目名称:guava,代码行数:8,代码来源:ListenerCallQueueTest.java

示例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));
}
 
开发者ID:googlegenomics,项目名称:dataflow-java,代码行数:41,代码来源:VerifyBamId.java

示例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;
    };
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:8,代码来源:TranscodingAsyncConsistentMultimap.java

示例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();
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:12,代码来源:GavinJobExecution.java

示例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();
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:80,代码来源:CorefAnnotation.java

示例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();
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:63,代码来源:DerivedQuerySelector2016.java

示例15: supplier

import com.google.common.collect.ImmutableMultiset; //导入方法依赖的package包/类
@Override
public Supplier<ImmutableMultiset.Builder<T>> supplier() {
  return ImmutableMultiset::builder;
}
 
开发者ID:atomix,项目名称:atomix,代码行数:5,代码来源:TranscodingAsyncConsistentMultimap.java


注:本文中的com.google.common.collect.ImmutableMultiset.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。