List of usage examples for com.google.common.collect Sets intersection
public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2)
From source file:org.dllearner.learningproblems.ScoreThreeValued.java
private void computeClassificationMatrix() { posAsNeg = Sets.intersection(posExamples, negClassified); negAsPos = Sets.intersection(negExamples, posClassified); posAsNeut = Sets.intersection(posExamples, neutClassified); neutAsPos = Sets.intersection(neutExamples, posClassified); neutAsNeg = Sets.intersection(neutExamples, negClassified); negAsNeut = Sets.intersection(negExamples, neutClassified); // die 3 Berechnungen sind nicht so wichtig fr die Punktzahl, d.h. falls // es Performance bringt, dann kann man sie auch ausgliedern posAsPos = Sets.intersection(posExamples, posClassified); negAsNeg = Sets.intersection(negExamples, negClassified); neutAsNeut = Sets.intersection(neutExamples, neutClassified); }
From source file:edu.cmu.lti.oaqa.baseqa.answer.score.scorers.TypeCoercionAnswerScorer.java
@Override public Map<String, Double> score(JCas jcas, Answer answer) { Set<CandidateAnswerOccurrence> caos = TypeUtil.getCandidateAnswerVariants(answer).stream() .map(TypeUtil::getCandidateAnswerOccurrences).flatMap(Collection::stream).collect(toSet()); List<Set<String>> typesList = caos.stream().map(cao -> offset2ctypes.get(TypeUtil.annotationOffset(cao))) .collect(toList());// ww w.ja v a 2 s . com ImmutableMap.Builder<String, Double> feat2value = ImmutableMap.builder(); atLimits.stream().filter(limit -> limit <= ats.size()).forEach(limit -> { Set<String> limitedLats = ImmutableSet.copyOf(ats.subList(0, limit)); double[] typecorRatios = typesList.stream().mapToDouble(types -> { int overlap = Sets.intersection(limitedLats, types).size(); int maxOverlap = Math.min(limitedLats.size(), types.size()); return Scorer.safeDividedBy(overlap, maxOverlap); }).toArray(); feat2value.putAll(Scorer.generateSummaryFeatures(typecorRatios, "type-coercion-" + limit, "avg", "max", "min", "pos-ratio", "one-ratio", "any-one")); }); return feat2value.build(); }
From source file:com.buaa.cfs.utils.JvmPauseMonitor.java
private String formatMessage(long extraSleepTime, Map<String, GcTimes> gcTimesAfterSleep, Map<String, GcTimes> gcTimesBeforeSleep) { Set<String> gcBeanNames = Sets.intersection(gcTimesAfterSleep.keySet(), gcTimesBeforeSleep.keySet()); List<String> gcDiffs = Lists.newArrayList(); for (String name : gcBeanNames) { GcTimes diff = gcTimesAfterSleep.get(name).subtract(gcTimesBeforeSleep.get(name)); if (diff.gcCount != 0) { gcDiffs.add("GC pool '" + name + "' had collection(s): " + diff.toString()); }//from w w w .j a v a2 s . c o m } String ret = "Detected pause in JVM or host machine (eg GC): " + "pause of approximately " + extraSleepTime + "ms\n"; if (gcDiffs.isEmpty()) { ret += "No GCs detected"; } else { ret += Joiner.on("\n").join(gcDiffs); } return ret; }
From source file:org.dishevelled.venn.model.VennModelImpl.java
/** * Create and return a new intersection view. * * @return a new intersection view/* www. j av a 2 s. c om*/ */ private Set<E> createIntersection() { Set<E> rv = this.sets.get(0); for (Set<E> set : sets) { rv = Sets.intersection(rv, set); } return rv; }
From source file:org.apache.usergrid.persistence.query.ir.result.IntersectionIterator.java
private Set<ScanColumn> merge(Set<ScanColumn> current, ResultIterator child) { Set<ScanColumn> results = new LinkedHashSet<ScanColumn>(pageSize); while (results.size() < pageSize) { if (!child.hasNext()) { // we've iterated to the end, reset for next pass child.reset();/* w ww .j a v a 2s. c om*/ return results; } final Set<ScanColumn> childResults = child.next(); final Set<ScanColumn> intersection = Sets.intersection(current, childResults); results.addAll(intersection); } return results; }
From source file:org.diqube.execution.steps.RowIdAndStep.java
@Override protected void execute() { List<Long> newRowIds = new ArrayList<>(); Long rowId;//from w ww.jav a 2 s .c om while ((rowId = leftRowIds.poll()) != null) leftUnmatchedRowIds.add(rowId); while ((rowId = rightRowIds.poll()) != null) rightUnmatchedRowIds.add(rowId); for (Long rowIdOnBothSides : Sets.intersection(leftUnmatchedRowIds, rightUnmatchedRowIds)) if (!rowIdsPolpulatedAlready.contains(rowIdOnBothSides)) newRowIds.add(rowIdOnBothSides); if (newRowIds.size() > 0) { rowIdsPolpulatedAlready.addAll(newRowIds); leftUnmatchedRowIds.removeAll(newRowIds); rightUnmatchedRowIds.removeAll(newRowIds); Long[] rowIdArray = newRowIds.stream().toArray(l -> new Long[l]); forEachOutputConsumerOfType(RowIdConsumer.class, c -> c.consume(rowIdArray)); logger.trace("Reported {} new matching rows", rowIdArray.length); } if (leftSourceIsEmpty.get() && rightSourceIsEmpty.get() && leftRowIds.isEmpty() && rightRowIds.isEmpty()) { forEachOutputConsumerOfType(GenericConsumer.class, c -> c.sourceIsDone()); doneProcessing(); } }
From source file:org.kuali.rice.xml.ingest.RiceConfigUtils.java
public static void override(Properties oldProps, Properties newProps) { SortedSet<String> commonKeys = Sets .newTreeSet(Sets.intersection(newProps.stringPropertyNames(), oldProps.stringPropertyNames())); if (commonKeys.size() == 0) { return;//from www . j a v a2 s. co m } logger.debug("{} keys in common", commonKeys.size()); for (String commonKey : commonKeys) { String oldValue = oldProps.getProperty(commonKey); String newValue = newProps.getProperty(commonKey); if (!newValue.equals(oldValue)) { Object[] args = { commonKey, toLogMsg(commonKey, oldValue), toLogMsg(commonKey, newValue) }; logger.info("Overriding - [{}]=[{}]->[{}]", args); oldProps.setProperty(commonKey, newValue); } } }
From source file:org.caleydo.view.histogram.v2.ADistributionElement.java
@Override public String getLabel(Pick pick) { int bucket = pick.getObjectID(); StringBuilder b = new StringBuilder(); final DistributionEntry entry = data.get(bucket); b.append(String.format("%s: %f (%.2f%%)", entry.getLabel(), entry.getValue() * data.size(), entry.getValue() * 100));// w w w . j a v a2s.c om for (SelectionType selectionType : SELECTIONTYPES) { Set<Integer> elements = data.getElements(selectionType); if (elements.isEmpty()) continue; Set<Integer> ids = entry.getIDs(); int scount = Sets.intersection(elements, ids).size(); if (scount > 0) b.append(String.format("\n %s: %d (%.2f%%)", selectionType.getType(), scount, scount * 100f / ids.size())); } return b.toString(); }
From source file:grakn.core.graql.reasoner.plan.QueryCollectionBase.java
private boolean isQueryReachable(ReasonerQueryImpl query, Collection<ReasonerQueryImpl> target) { Set<Variable> queryVars = getAllNeighbours(query).stream().flatMap(q -> q.getVarNames().stream()) .collect(Collectors.toSet()); return target.stream().anyMatch(tq -> !Sets.intersection(tq.getVarNames(), queryVars).isEmpty()); }
From source file:com.collective.celos.ci.testing.fixtures.compare.RecursiveFsObjectComparer.java
private FixObjectCompareResult checkDirFileList(Map<String, FixFsObject> expectedChldrn, Map<String, FixFsObject> actualChldrn) { Set<String> expectedDiff = Sets.difference(expectedChldrn.keySet(), actualChldrn.keySet()); Set<String> actualDiff = Sets.difference(actualChldrn.keySet(), expectedChldrn.keySet()); List<String> filesWithDifferentTypes = Lists.newArrayList(); for (String key : Sets.intersection(expectedChldrn.keySet(), actualChldrn.keySet())) { FixFsObject expected = expectedChldrn.get(key); FixFsObject actual = actualChldrn.get(key); if (expected.isFile() != actual.isFile()) { String message = getWrongTypeDesc(key, expected, actual); filesWithDifferentTypes.add(message); }//from ww w . j av a 2 s.c om } if (expectedDiff.isEmpty() && actualDiff.isEmpty() && filesWithDifferentTypes.isEmpty()) { return FixObjectCompareResult.SUCCESS; } else { StrBuilder strBuilder = new StrBuilder(); appendMessages(expectedDiff, strBuilder, "Files found only in expected set: "); appendMessages(actualDiff, strBuilder, "Files found only in result set: "); appendMessages(filesWithDifferentTypes, strBuilder, "Files have different types: "); return FixObjectCompareResult.failed(strBuilder.toString()); } }