當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。