List of usage examples for com.google.common.collect SetMultimap putAll
boolean putAll(@Nullable K key, Iterable<? extends V> values);
From source file:org.gradle.internal.component.external.model.ivy.RealisedIvyModuleResolveMetadataSerializationHelper.java
private SetMultimap<String, String> readDependencyConfigurationMapping(Decoder decoder) throws IOException { int size = decoder.readSmallInt(); SetMultimap<String, String> result = LinkedHashMultimap.create(); for (int i = 0; i < size; i++) { String from = decoder.readString(); Set<String> to = readStringSet(decoder); result.putAll(from, to); }/* w w w. j ava 2s . c o m*/ return result; }
From source file:org.dragoneronca.nlp.wol.graph_building.SimilarityBasedProcessor.java
@Override public void processSenseSet(SenseSet senseSet) { TAGGER.tagSenses(senseSet.getSenses().iterator()); int expectedContexts = senseSet.getSenses().size() + (senseSet.getSenseRelations().size() * 4); SetMultimap<Sense, Tuple> senseContexts = LinkedHashMultimap.create(expectedContexts, 8); for (Sense sense : senseSet.getSenses()) { senseContexts.putAll(sense, getGlossContext(sense.getTaggedGloss())); }//from www . j a v a 2 s .c o m linkSensesFromSenseRelations(senseSet, senseContexts); linkSensesFromTerms(senseSet, senseContexts); }
From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.TypeCoercionCollectiveAnswerScorer.java
@Override public void prepare(JCas jcas) { answers = TypeUtil.getRankedAnswers(jcas); // create offset to concept types index SetMultimap<String, String> offset2ctypes = HashMultimap.create(); for (Concept concept : TypeUtil.getConcepts(jcas)) { for (ConceptMention cmention : TypeUtil.getConceptMentions(concept)) { Set<String> ctypes = TypeUtil.getConceptTypes(cmention.getConcept()).stream() .map(ConceptType::getAbbreviation).collect(toSet()); offset2ctypes.putAll(TypeUtil.annotationOffset(cmention), ctypes); }//from w ww . j a v a2 s . c o m } // create answer to concepty types index SetMultimap<Answer, String> answer2ctypes = HashMultimap.create(); for (Answer answer : answers) { for (CandidateAnswerVariant cav : TypeUtil.getCandidateAnswerVariants(answer)) { for (CandidateAnswerOccurrence cao : TypeUtil.getCandidateAnswerOccurrences(cav)) { Set<String> ctypes = offset2ctypes.get(TypeUtil.annotationOffset(cao)); answer2ctypes.putAll(answer, ctypes); } } } // build pariwise similarity matrices typecors = HashBasedTable.create(); ntypecors = HashBasedTable.create(); types = HashBasedTable.create(); ImmutableSet<Answer> answerSet = ImmutableSet.copyOf(answers); for (List<Answer> pair : Sets.cartesianProduct(answerSet, answerSet)) { Answer a1 = pair.get(0); Answer a2 = pair.get(1); if (a1.equals(a2)) continue; Set<String> overlapTypes = Sets.intersection(answer2ctypes.get(a1), answer2ctypes.get(a2)); if (overlapTypes.size() > 0) { typecors.put(a1, a2, (double) overlapTypes.size()); ntypecors.put(a1, a2, (double) overlapTypes.size() / answer2ctypes.get(a1).size()); types.put(a1, a2, overlapTypes); } } }
From source file:com.android.build.gradle.tasks.PreprocessResourcesTask.java
private void handleFile(File resourceFile, FileStatus fileStatus, PreprocessDataSet mergedSet, PreprocessDataSet generatedSet, SetMultimap<File, File> generatedFiles) throws IOException, MergingException { if (renderer.needsPreprocessing(resourceFile)) { Collection<File> newFiles = renderer.createPngFiles(resourceFile, getGeneratedResDirectory(), getDensitiesToGenerate()); generatedFiles.putAll(resourceFile, newFiles); generatedSet.updateWith(getMergedResDirectory(), resourceFile, fileStatus, getILogger()); } else {/*from ww w . j av a 2 s.c om*/ mergedSet.updateWith(getMergedResDirectory(), resourceFile, fileStatus, getILogger()); } }
From source file:edu.cmu.lti.oaqa.baseqa.answer_type.ConceptGSAnswerTypeLabeler.java
@Override protected void annotateConceptTypesForGSAnswers(List<QuestionAnswerTypes> qats) throws AnalysisEngineProcessException { long answerCount = qats.stream().map(QuestionAnswerTypes::getAnswers).mapToLong(Set::size).sum(); LOG.info("Fetch labels for {} questions ({} answers).", qats.size(), answerCount); // general text requests List<String> texts = qats.stream().map(qat -> String.join(", ", qat.getAnswers())).collect(toList()); // fetch concepts List<Concept> concepts = conceptProvider.getConcepts(texts, "__GS_ANSWER__"); SetMultimap<String, String> cmention2types = HashMultimap.create(); for (Concept concept : concepts) { Set<String> types = TypeUtil.getConceptTypes(concept).stream().map(ConceptType::getName) .collect(toSet());//from w w w. j a v a2s . c om Set<String> cmentions = TypeUtil.getConceptMentions(concept).stream() .map(ConceptMention::getCoveredText).collect(Collectors.toSet()); cmentions.forEach(cmention -> cmention2types.putAll(cmention, types)); } // map the concept types back to qats for (QuestionAnswerTypes qat : qats) { qat.getAnswers().stream().filter(cmention2types::containsKey) .forEach(answer -> qat.addAnswerTypes(answer, cmention2types.get(answer))); } }
From source file:org.jetbrains.jet.lang.resolve.calls.smartcasts.DelegatingDataFlowInfo.java
@NotNull @Override//from w w w. jav a2s. c o m public DataFlowInfo or(@NotNull DataFlowInfo otherInfo) { if (otherInfo == EMPTY) return EMPTY; if (this == EMPTY) return EMPTY; if (this == otherInfo) return this; assert otherInfo instanceof DelegatingDataFlowInfo : "Unknown DataFlowInfo type: " + otherInfo; DelegatingDataFlowInfo other = (DelegatingDataFlowInfo) otherInfo; Map<DataFlowValue, Nullability> nullabilityMapBuilder = Maps.newHashMap(); for (Map.Entry<DataFlowValue, Nullability> entry : other.getCompleteNullabilityInfo().entrySet()) { DataFlowValue key = entry.getKey(); Nullability otherFlags = entry.getValue(); Nullability thisFlags = getNullability(key); nullabilityMapBuilder.put(key, thisFlags.or(otherFlags)); } SetMultimap<DataFlowValue, JetType> myTypeInfo = getCompleteTypeInfo(); SetMultimap<DataFlowValue, JetType> otherTypeInfo = other.getCompleteTypeInfo(); SetMultimap<DataFlowValue, JetType> newTypeInfo = newTypeInfo(); for (DataFlowValue key : Sets.intersection(myTypeInfo.keySet(), otherTypeInfo.keySet())) { Set<JetType> thisTypes = myTypeInfo.get(key); Set<JetType> otherTypes = otherTypeInfo.get(key); newTypeInfo.putAll(key, Sets.intersection(thisTypes, otherTypes)); } if (nullabilityMapBuilder.isEmpty() && newTypeInfo.isEmpty()) { return EMPTY; } return new DelegatingDataFlowInfo(null, ImmutableMap.copyOf(nullabilityMapBuilder), newTypeInfo); }
From source file:checkers.game_engine.game_rules.RuleManager.java
@Override public SetMultimap<Position, Position> getAllAvailableCaptures(Player activePlayer, Board board) { SetMultimap<Position, Position> allCaptures = HashMultimap.create(); for (int i = 1; i < board.getSize(); i++) { for (int j = 1; j < board.getSize(); j++) { Position startPos = new Position(i, j); if (activePlayer == Player.PLAYER_ONE && (board.getFieldAt(i, j) == Board.WHITE_KING || board.getFieldAt(i, j) == Board.WHITE_REGULAR_PIECE)) { allCaptures.putAll(startPos, getAvailableCaptures(startPos, board)); } else if (activePlayer == Player.PLAYER_TWO && (board.getFieldAt(i, j) == Board.BLACK_KING || board.getFieldAt(i, j) == Board.BLACK_REGULAR_PIECE)) { allCaptures.putAll(startPos, getAvailableCaptures(startPos, board)); }/*from w w w .j a v a 2 s .com*/ } } return allCaptures; }
From source file:org.elasticlib.common.model.RevisionTree.java
private Set<Revision> latestCommonAncestors(Revision left, Revision right) { Set<Revision> commonAncestors = intersection(ancestors(left), ancestors(right)); SetMultimap<Revision, Revision> dependencies = HashMultimap.create(); commonAncestors.forEach(info -> { dependencies.putAll(info, intersection(commonAncestors, ancestors(info))); });//from w w w . j a v a2s. c o m return difference(commonAncestors, new HashSet<>(dependencies.values())); }
From source file:org.apache.gobblin.data.management.copy.hive.WhitelistBlacklist.java
private static void populateMultimap(SetMultimap<Pattern, Pattern> multimap, String list) throws IOException { Splitter tokenSplitter = Splitter.on(",").omitEmptyStrings().trimResults(); Splitter partSplitter = Splitter.on(".").omitEmptyStrings().trimResults(); Splitter tableSplitter = Splitter.on("|").omitEmptyStrings().trimResults(); for (String token : tokenSplitter.split(list)) { if (!Strings.isNullOrEmpty(token)) { List<String> parts = partSplitter.splitToList(token); if (parts.size() > 2) { throw new IOException("Invalid token " + token); }// w ww. ja v a 2s. c o m Pattern databasePattern = Pattern.compile(parts.get(0).replace("*", ".*")); Set<Pattern> tablePatterns = Sets.newHashSet(); if (parts.size() == 2) { String tables = parts.get(1); for (String table : tableSplitter.split(tables)) { if (table.equals("*")) { // special case, must use ALL_TABLES due to use of set.contains(ALL_TABLES) in multimapContains tablePatterns.add(ALL_TABLES); } else { tablePatterns.add(Pattern.compile(table.replace("*", ".*"))); } } } else { tablePatterns.add(ALL_TABLES); } multimap.putAll(databasePattern, tablePatterns); } } }
From source file:org.jetbrains.kotlin.resolve.calls.smartcasts.DelegatingDataFlowInfo.java
@NotNull @Override/* w w w . ja va2s . c om*/ public DataFlowInfo or(@NotNull DataFlowInfo otherInfo) { if (otherInfo == EMPTY) return EMPTY; if (this == EMPTY) return EMPTY; if (this == otherInfo) return this; assert otherInfo instanceof DelegatingDataFlowInfo : "Unknown DataFlowInfo type: " + otherInfo; DelegatingDataFlowInfo other = (DelegatingDataFlowInfo) otherInfo; Map<DataFlowValue, Nullability> nullabilityMapBuilder = Maps.newHashMap(); for (Map.Entry<DataFlowValue, Nullability> entry : other.getCompleteNullabilityInfo().entrySet()) { DataFlowValue key = entry.getKey(); Nullability otherFlags = entry.getValue(); Nullability thisFlags = getNullability(key); nullabilityMapBuilder.put(key, thisFlags.or(otherFlags)); } SetMultimap<DataFlowValue, KotlinType> myTypeInfo = getCompleteTypeInfo(); SetMultimap<DataFlowValue, KotlinType> otherTypeInfo = other.getCompleteTypeInfo(); SetMultimap<DataFlowValue, KotlinType> newTypeInfo = newTypeInfo(); for (DataFlowValue key : Sets.intersection(myTypeInfo.keySet(), otherTypeInfo.keySet())) { Set<KotlinType> thisTypes = myTypeInfo.get(key); Set<KotlinType> otherTypes = otherTypeInfo.get(key); newTypeInfo.putAll(key, Sets.intersection(thisTypes, otherTypes)); } if (nullabilityMapBuilder.isEmpty() && newTypeInfo.isEmpty()) { return EMPTY; } return new DelegatingDataFlowInfo(null, ImmutableMap.copyOf(nullabilityMapBuilder), newTypeInfo); }