com.google.common.collect.Multiset#addAll ( )源码实例Demo

下面列出了com.google.common.collect.Multiset#addAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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;
}
 
源代码2 项目: entity-fishing   文件: EntityScorer.java
public ScorerContext context(List<String> words) {
    Multiset<String> counter = TreeMultiset.create();
    counter.addAll(words);

    int word_dim = kb.getEmbeddingsSize();
    // word_vecs is the concatenation of all word vectors of the word list
    float[] word_vecs = new float[counter.size() * word_dim];
    IntArrayList word_counts = new IntArrayList();
    int n_words = 0;

    for(Multiset.Entry<String> entry : counter.entrySet()) {
        short[] vector = kb.getWordEmbeddings(entry.getElement());
        if (vector != null) {
            word_counts.add(entry.getCount());
            for (int i=0; i<kb.getEmbeddingsSize(); i++) {
                word_vecs[n_words * word_dim + i] = vector[i];
            }
            n_words += 1;
        }
    }
    word_counts.trim();

    return create_context(word_vecs, word_counts.elements());
}
 
源代码3 项目: pyramid   文件: NgramEnumerator.java
private static void add(List<String> source, Multiset<Ngram> multiset, String field, int slop, List<Integer> template){
    Multiset<Ngram> multiSetForDoc = ConcurrentHashMultiset.create();
    for (int i=0;i<source.size();i++){
        if(i+template.get(template.size()-1)<source.size()){
            List<String> list = new ArrayList<>();
            for (int j: template){
                list.add(source.get(i+j));
            }
            Ngram ngram = new Ngram();
            ngram.setNgram(Ngram.toNgramString(list));
            ngram.setSlop(slop);
            ngram.setField(field);
            ngram.setInOrder(true);
            multiSetForDoc.setCount(ngram,1);
        }
    }
     multiset.addAll(multiSetForDoc);
}
 
源代码4 项目: gef   文件: BindingUtils.java
/**
 * Creates a unidirectional content binding from the given source
 * {@link Multiset} to the given target {@link ObservableMultiset}.
 *
 * @param <E>
 *            The element type of the given {@link Multiset} and
 *            {@link ObservableMultiset}.
 * @param source
 *            The {@link Multiset} whose content to update when the given
 *            {@link ObservableMultiset} changes.
 * @param target
 *            The {@link ObservableMultiset} whose content is to be
 *            observed.
 */
public static <E> void bindContent(Multiset<E> source,
		ObservableMultiset<? extends E> target) {
	if (source == null) {
		throw new NullPointerException("Cannot bind null value.");
	}
	if (target == null) {
		throw new NullPointerException("Cannot bind to null value.");
	}
	if (source == target) {
		throw new IllegalArgumentException("Cannot bind source to itself.");
	}

	if (source instanceof ObservableMultiset) {
		// ensure we use an atomic operation in case the source multiset is
		// observable.
		((ObservableMultiset<E>) source).replaceAll(target);
	} else {
		source.clear();
		source.addAll(target);
	}

	final UnidirectionalMultisetContentBinding<E> contentBinding = new UnidirectionalMultisetContentBinding<>(
			source);
	// clear any previous bindings
	target.removeListener(contentBinding);
	// add new binding as listener
	target.addListener(contentBinding);
}
 
源代码5 项目: api-mining   文件: PAMCore.java
/**
 * This method scans the input database to calculate the support of single
 * items.
 *
 * @param inputFile
 *            the input file
 * @return a multiset for storing the support of each singleton
 */
public static Multiset<Sequence> scanDatabaseToDetermineFrequencyOfSingleItems(final File inputFile)
		throws IOException {

	final Multiset<Sequence> singletons = HashMultiset.create();

	// for each line (transaction) until the end of file
	final LineIterator it = FileUtils.lineIterator(inputFile, "UTF-8");
	while (it.hasNext()) {

		final String line = it.nextLine();
		// if the line is a comment, is empty or is a
		// kind of metadata
		if (line.isEmpty() == true || line.charAt(0) == '#' || line.charAt(0) == '%' || line.charAt(0) == '@') {
			continue;
		}

		// split the line into items
		final String[] lineSplit = line.split(" ");
		// for each item
		final HashSet<Sequence> seenItems = new HashSet<>();
		for (final String itemString : lineSplit) {
			final int item = Integer.parseInt(itemString);
			if (item >= 0) { // ignore end of itemset/sequence tags
				final Sequence seq = new Sequence(item);
				PAMCore.recursiveSetOccurrence(seq, seenItems); // set
																// occurrence
				seenItems.add(seq); // add item to seen
			}
		}
		singletons.addAll(seenItems); // increase the support of the items
	}

	// close the input file
	LineIterator.closeQuietly(it);

	return singletons;
}
 
源代码6 项目: jpmml-sklearn   文件: KMeans.java
@Override
public ClusteringModel encodeModel(Schema schema){
	int[] shape = getClusterCentersShape();

	int numberOfClusters = shape[0];
	int numberOfFeatures = shape[1];

	List<? extends Number> clusterCenters = getClusterCenters();
	List<Integer> labels = getLabels();

	Multiset<Integer> labelCounts = HashMultiset.create();

	if(labels != null){
		labelCounts.addAll(labels);
	}

	List<Cluster> clusters = new ArrayList<>();

	for(int i = 0; i < numberOfClusters; i++){
		Cluster cluster = new Cluster(PMMLUtil.createRealArray(CMatrixUtil.getRow(clusterCenters, numberOfClusters, numberOfFeatures, i)))
			.setId(String.valueOf(i))
			.setSize((labelCounts.size () > 0 ? labelCounts.count(i) : null));

		clusters.add(cluster);
	}

	ComparisonMeasure comparisonMeasure = new ComparisonMeasure(ComparisonMeasure.Kind.DISTANCE, new SquaredEuclidean())
		.setCompareFunction(CompareFunction.ABS_DIFF);

	ClusteringModel clusteringModel = new ClusteringModel(MiningFunction.CLUSTERING, ClusteringModel.ModelClass.CENTER_BASED, numberOfClusters, ModelUtil.createMiningSchema(schema.getLabel()), comparisonMeasure, ClusteringModelUtil.createClusteringFields(schema.getFeatures()), clusters)
		.setOutput(ClusteringModelUtil.createOutput(FieldName.create("Cluster"), DataType.DOUBLE, clusters));

	return clusteringModel;
}
 
源代码7 项目: angelix   文件: Main.java
private static Multiset<Node> selectComponents(Expression expression, Set<ProgramVariable> contextVariables) {
    Multiset<Node> components = HashMultiset.create();

    components.addAll(expression.getAllComponents());
    components.addAll(contextVariables);

    components.add(Library.AND);
    components.add(Library.OR);
    components.add(Library.NOT);

    components.add(Library.LE);
    components.add(Library.LT);
    components.add(Library.GT);
    components.add(Library.GE);
    components.add(Library.EQ);
    components.add(Library.NEQ);

    components.add(Library.ADD);
    components.add(Library.SUB);
    components.add(Library.MINUS);

    components.add(Library.ID(IntType.TYPE));
    components.add(Library.ID(BoolType.TYPE));

    components.add(Parameter.mkInt("parameter"));

    return components;
}
 
源代码8 项目: txtUML   文件: BaseTest.java
protected static <T> void assertEqualsAsMultisets(
		Collection<T> expectedCollection, Collection<T> actualCollection) {

	Multiset<T> expecteds = HashMultiset.create();
	Multiset<T> actuals = HashMultiset.create();

	expecteds.addAll(expectedCollection);
	actuals.addAll(actualCollection);

	assertCollectionEquals(expecteds, actuals);
}
 
源代码9 项目: glowroot   文件: SyntheticResultJsonService.java
private ImmutableList<SyntheticMonitor> getAllSyntheticMonitors(String agentRollupId,
        long from, long to) throws Exception {
    Map<String, String> syntheticMonitorIds =
            syntheticResultRepository.getSyntheticMonitorIds(agentRollupId, from, to);
    Multiset<String> multiset = HashMultiset.create();
    multiset.addAll(syntheticMonitorIds.values());
    List<SyntheticMonitor> syntheticMonitors = Lists.newArrayList();
    for (Map.Entry<String, String> entry : syntheticMonitorIds.entrySet()) {
        String id = entry.getKey();
        String display = entry.getValue();
        if (multiset.count(entry.getValue()) > 1) {
            display += " (" + id + ")";
        }
        syntheticMonitors.add(ImmutableSyntheticMonitor.of(id, display));
    }
    if (to > clock.currentTimeMillis()) {
        // so that new synthetic monitors will show up right away
        List<SyntheticMonitorConfig> configs =
                configRepository.getSyntheticMonitorConfigs(agentRollupId);
        for (SyntheticMonitorConfig config : configs) {
            if (!syntheticMonitorIds.containsKey(config.getId())) {
                syntheticMonitors.add(ImmutableSyntheticMonitor.of(config.getId(),
                        MoreConfigDefaults.getDisplayOrDefault(config)));
            }
        }
    }
    return new SyntheticMonitorOrdering().immutableSortedCopy(syntheticMonitors);
}
 
源代码10 项目: gef   文件: MultisetExpression.java
@Override
public boolean addAll(Collection<? extends E> c) {
	final Multiset<E> multiset = get();
	return (multiset == null) ? EMPTY_MULTISET.addAll(c)
			: multiset.addAll(c);
}
 
源代码11 项目: gef   文件: ObservableMultisetTests.java
@Test
public void replaceAll() {
	// initialize multiset with some values
	observable.add(1, 1);
	observable.add(2, 2);
	observable.add(3, 3);
	observable.add(4, 4);

	// prepare backup multiset
	Multiset<Integer> backupMultiset = HashMultiset.create();
	backupMultiset.add(1, 1);
	backupMultiset.add(2, 2);
	backupMultiset.add(3, 3);
	backupMultiset.add(4, 4);
	check(observable, backupMultiset);

	// register listeners
	registerListeners();

	// replaceAll
	invalidationListener.expect(1);
	multisetChangeListener.addAtomicExpectation();
	multisetChangeListener.addElementaryExpection(2, 1, 0); // decrease
															// count
	multisetChangeListener.addElementaryExpection(4, 4, 0); // remove
	multisetChangeListener.addElementaryExpection(3, 0, 3); // increase
															// count
	multisetChangeListener.addElementaryExpection(5, 0, 5); // add

	Multiset<Integer> toReplace = HashMultiset.create();
	toReplace.add(1);
	toReplace.add(2, 1);
	toReplace.add(3, 6);
	toReplace.add(5, 5);

	observable.replaceAll(toReplace);
	backupMultiset.clear();
	backupMultiset.addAll(toReplace);
	check(observable, backupMultiset);
	checkListeners();

	// replace with same contents (should not have any effect)
	invalidationListener.expect(0);
	observable.replaceAll(toReplace);
	check(observable, backupMultiset);
	checkListeners();
}