本文整理汇总了Java中org.apache.commons.collections4.map.MultiValueMap.getCollection方法的典型用法代码示例。如果您正苦于以下问题:Java MultiValueMap.getCollection方法的具体用法?Java MultiValueMap.getCollection怎么用?Java MultiValueMap.getCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.collections4.map.MultiValueMap
的用法示例。
在下文中一共展示了MultiValueMap.getCollection方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateEntryWithRolesMap
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
private void updateEntryWithRolesMap(MultiValueMap<String, LexiconEntryWithRoles> map, String key, LexiconEntryWithRoles entry, String unlexEntryWithSemantics)
{
Collection<LexiconEntryWithRoles> col = map.getCollection(key);
if(col != null && col.contains(entry))
{
for(LexiconEntryWithRoles e : col)
{
if(entry.equals(e)) // syntactically same tree with (potentially) different role assignments
{
e.addEntry(entry, unlexEntryWithSemantics);
break;
}
} // for
} // if
else
{
map.put(key, entry);
}
}
示例2: getRolesPerNode
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
/**
* Create a map of nodes that have a role. Note, we split role signatures into
* individual nodes with roles; this might potentially result in combinations of roles
* in trees not existing in the training set.
* @param tree an ElementaryStringTree with potential roles attached to it
* @param offset the node id offset. This is the highest node id of the prefix tree.
* @return
*/
private MultiValueMap<Integer, Role> getRolesPerNode(ElementaryStringTree tree, short offset)
{
MultiValueMap<Integer, Role> roleMap = new MultiValueMap();
for(RoleSignature sig : tree.getRoleSignatures())
{
for(Role role : sig.getRoles().values()) // wrong! It might result in combination of roles in trees not existing in the training set
{
int newId = role.getNodeId() + offset;
Collection<Role> rolesPerNode = roleMap.getCollection(newId);
if(rolesPerNode == null || !rolesPerNode.contains(role)) // if the collection is empty and doesn't contain the same role
roleMap.put(newId, role);
if(role.secondRoleNameId != null) // make sure we treat roles with multiple argument labels separately (e.g., @ARG1;@ARG0)
{
Role secondRole = new Role(role.roleIndexer, role.secondRoleNameId, role.nodeId);
if(!roleMap.getCollection(newId).contains(secondRole))
roleMap.put(newId, secondRole);
}
}
}
return roleMap;
}
示例3: obtainLanguagesCacheTrans
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
private void obtainLanguagesCacheTrans(List<LanguagesOutput> outputList,
List<LanguagesInput> inputList) {
if ((LanguagesInput.searchEngine(inputList, Engine.CACHETRANS.toString())) == -1) {
return;
}
MultiValueMap langs = Cachetrans.getLanguages();
for (Object s : langs.keySet()) {
for (Object t : langs.getCollection(s)) {
addLanguagePair(outputList, s.toString(), t.toString(),
Engine.CACHETRANS.toString());
}
}
return;
}
示例4: mapExamples
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
/**
* commons collectios 的实例代码
*/
private void mapExamples() {
// 多值 map,一个 key 对于多个值
MultiValueMap mvm = new MultiValueMap();
mvm.put("1", "one");
mvm.put("2", "two");
mvm.put("1", "three");
for (Iterator it = mvm.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
out.println("key=" + key + "; value=" + value);
}
// 判断是否包含指定的 key value
out.println(mvm.containsValue("1", "one"));
// MultiValueMap 的 value 值是 Collection 类型。实际上是 arrayList
//测试类型
out.println(mvm.get("1").getClass());
ArrayList<String> list = (ArrayList<String>) mvm.getCollection("1");
for (String s : list)
out.println(s);
}
示例5: printEntriesWithComplexRolesStats
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
private void printEntriesWithComplexRolesStats(MultiValueMap<String, LexiconEntryWithRoles> unlexEntriesWithNormWordsAsKeys)
{
for(String key : unlexEntriesWithNormWordsAsKeys.keySet())
{
StringBuilder treesStr = new StringBuilder();
for(LexiconEntryWithRoles tree : unlexEntriesWithNormWordsAsKeys.getCollection(key))
{
if(tree.getRoles().size() > 0)
{
boolean treeMoreThanOneRole = false;
StringBuilder treeStr = new StringBuilder("\n");
for(RoleSignature sig : tree.getRoles())
{
treeStr.append(sig).append(", ");
if(sig.numOfRoles() > 1)
{
treeMoreThanOneRole = true;
} // if
} // for
if(treeMoreThanOneRole && tree.getRoles().size() > 1)
treesStr.append("\t").append(treeStr);
} // if
} // for
if(treesStr.length() > 0)
System.out.println(key + treesStr);
}
}
示例6: reconstructArgument
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
private Argument reconstructArgument(Lexicon lexicon, Predicate predPred, Argument goldArg, MultiValueMap<Predicate, Argument> identifiedArcs)
{
String goldWord = Example.wordRemoveDigits(goldArg.getForm());
String goldPosTag = goldArg.getPosTag();
String simplifiedPosTag = simplifyPosTag(goldWord, goldPosTag, goldArg.getTimestamp());
String posWord = simplifiedPosTag + " " + goldWord;
List<ElementaryStringTree> entries = (List)lexicon.getEntries(posWord, posWord.toLowerCase(), simplifiedPosTag, false, goldArg.getTimestamp());
if(entries.size() > 0)
{
String elemTree = entries.get(0).toStringUnlex(false); // always choose the first. In case of ambiguity then we've picked the wrong tree!
// try to find an argument with the same POS tag as the word in the gold standard
boolean foundPosTag = false;
Argument predArg = null;
Collection<Argument> candArgs = identifiedArcs.getCollection(predPred);
for(Argument candArg : candArgs)
{
if(Utils.getCatInventory(candArg.getPosTag(), true).equals(simplifiedPosTag)) // simplify POS tag
{
predArg = candArg;
foundPosTag = true;
break;
}
}
if(!foundPosTag) // couldn't find an argument with same POS tag, so choose pick the first one (inaccurate)
predArg = candArgs.iterator().next();
return new Argument(goldArg.getTimestamp(), goldArg.getRole(), goldWord, goldPosTag, elemTree,
predArg.getIntegrationPoint(), predArg.getPrefixFringeAlphaSet(), predArg.getOperationPath(), null);
}
// else if(!opts.silentMode)
// {
// LogInfo.error("Could not find lexicon entry while reconstructing argument, during feature extraction (gold POS was " + goldPosTag + " and got simplified to " + simplifiedPosTag + ")");
// }
return null;
}
示例7: getOrigin
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected Collection<Integer> getOrigin(Integer nodeID, MultiValueMap<Integer, Integer> origin)
{
if (origin == null)
{
return null;
}
if (origin.containsKey(nodeID))
{
return origin.getCollection(nodeID);
}
return null;
}
示例8: getLowestOrigin
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected Integer getLowestOrigin(Integer nodeID, MultiValueMap<Integer, Integer> origin)
{
Integer lowest = 9999999;
if (origin.containsKey(nodeID))
{
Collection<Integer> nodeIds = origin.getCollection(nodeID);
if(nodeIds.isEmpty())
return -1;
for(Integer id : nodeIds)
{
if (id < lowest)
{
lowest = id;
}
}
// Iterator<Integer> nodeids = origin.getCollection(nodeID).iterator();
// if (origin.getCollection(nodeID).isEmpty())
// {
// return -1;
//// return "-1";
// //return null;
// }
// while (nodeids.hasNext())
// {
// Integer id = nodeids.next();
//// int id = Integer.parseInt((String) nodeids.next());
// if (id < lowest)
// {
// lowest = id;
// }
// }
}
else
{
return null;
}
return lowest;
// return Integer.toString(lowest);
}
示例9: makeLexTrees
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
/**
* Converts a MultiValueMap with String values to one with StringTree values.
* @param treetype
*
* @param MultiValueMap lexString
* @return MultiValueMap lexTree
*/
@SuppressWarnings("unchecked")
private MultiValueMap makeLexTrees(MultiValueMap lexString, String treetype)
{
MultiValueMap<String, ElementaryStringTree> lexTree = new MultiValueMap();
Set<String> keys = lexString.keySet();
for (String key : keys)
{
Collection<String> values = lexString.getCollection(key);
HashMap<String, ElementaryStringTree> treelist = new HashMap<String, ElementaryStringTree>();
for (String treeString : values)
{
ElementaryStringTree tree = makeToStringTreeOld(treeString, treetype);
if (tree == null)
{
continue;
}
String POSword = tree.getPOStagged(tree.getRoot()).trim();
if (key.equals("prediction: "))
{
POSword = key;
}
// for lexentries for "put up" etc, add three times into Map: as "put up", "put" and "up".
String[] words = POSword.split("\t");
ElementaryStringTree sametree = null;
if (!treelist.containsKey(POSword + "@@" + tree.toString()))
{
lexTree.put(POSword, tree);
}
treelist.put(POSword + "@@" + tree.toString(), tree);
if (words.length > 1)
{
for (String word : words)
{
if (sametree == null)
{
lexTree.put(word, tree);
}
}
}
}
}
return lexTree;
}
示例10: getMajorityBaselineDirectArcs
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
public Map<Predicate, Proposition> getMajorityBaselineDirectArcs(Map<String, Pair<String, Integer>> majorityDepArgs)
{
int threshold = 10;
List<List<String>> words = Utils.unpackConllSentenceToTokens(goldStandardConll);
// Build a map of Heads to pairs of DepRels and their timestamp. Essentially we gather all the
// arguments of each word in the sentence.
MultiValueMap<String, Pair> headsPosDepRels = new MultiValueMap<String, Pair>();
for(int wordPos = 0; wordPos < words.size(); wordPos++)
{
List<String> word = words.get(wordPos);
headsPosDepRels.put(word.get(HEAD_COL), new Pair<Integer, String>(wordPos, word.get(DEPREL_COL+1))); // Pair: word_position - DepRel
}
// Guess predicates and arguments
Map<Predicate, Proposition> props = new HashMap();
int i = 0;
for(Predicate goldPred : getVerbPredicates())
{
// cheating. We are copying the whole predicate.
// This is going to give us 100% Precision and Recall
Predicate pred = new Predicate(goldPred);
int predPos = verbPredPositions.get(i++);
String predId = words.get(predPos).get(ID_COL); // id of the predicate.
Collection<Pair> predArgs = headsPosDepRels.getCollection(predId);
Proposition prop = new Proposition(pred);
if(predArgs != null)
{
for(Pair pair : predArgs)
{
Pair<Integer, String> p = (Pair<Integer, String>)pair;
Pair<String, Integer> argFreq = majorityDepArgs.get(p.getSecond()); // poll the depRel in the map of the top N depRels
if(argFreq != null)
{
int freqOfRole = argFreq.getSecond();
if(freqOfRole > threshold)
{
String role = argFreq.getFirst();
prop.addArgument(new Argument(p.getFirst(), role, "_", p.getSecond()));
}
}
} // for each arg
} // if
props.put(pred, prop);
} // for each predicate
return props;
}
示例11: addDependency
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
/**
* Add dependency with integration point on the elementary tree.
* @param integrationPoint
* @param tree
* @param offset
* @param isRelation
* @param rolesPerNode
*/
private void addDependency(DepNode integrationPoint, ElementaryStringTree tree, short adjoiningNodeInElemTreeId, short offset,
MultiValueMap<Integer, Role> rolesPerNode, Node prefixTreeNode, boolean isShadowTree, String[] words, String[] origPosTags,
String operation, boolean direction, int timestamp)
{
boolean isRelation = tree.isRelation();
// integrationPoint.setCategory(tree.getCategory(integrationPoint.getId() - offset));
integrationPoint.setCategory(tree.getCategory(adjoiningNodeInElemTreeId));
// DependencyArc arc = new DependencyArc(integrationPoint, rolesPerNode.getCollection(integrationPoint.getId()), null, null);
DependencyArc arc = new DependencyArc(integrationPoint, rolesPerNode.getCollection(adjoiningNodeInElemTreeId + offset), null, null);
// DependencyArc arc = newDependencyArc(integrationPoint, rolesPerNode.getCollection(adjoiningNodeInElemTreeId + offset), tree, isRelation);
DepNode anchorNode = !isShadowTree ? getAnchorNode(tree, offset, timestamp) : null;
// if integration point has common ancestor with existing dependency
// which is missing a relation/argument (depends on whether tree is an argument/relation) [AT the moment only attach to a hanging relation]
DepNode relationWithMatchingAnchor = prefixTreeNode != null ? dependencies.getRelationWithCategory(getNodeCategory(prefixTreeNode), isRelation) : null;
// if(isRelation && relationWithMatchingAnchor != null)
//System.out.println("Need to check " + tree);
boolean mergedArc = false, ppMergedArc = false, keepArc = true;
if(isRelation) // rel is anchor
{
mergedArc = setRelation(arc, anchorNode, words, origPosTags, operation, direction, isShadowTree);
if(prefixTreeNode != null)// arg is head of prefix tree
{
mergedArc = setArgument(arc, new DepNode(getNodeCategory(prefixTreeNode), prefixTreeNode.getCategory(), // TODO: check getCategory() always return POS tag
prefixTreeNode.getNodeId(), prefixTreeNode.getOrigTree(), prefixTreeNode.getLambdaTimestamp()),
words, origPosTags, operation, direction, isShadowTree);
}
ppMergedArc = applyPPArgumentHeuristic(arc, tree, anchorNode, offset, words, origPosTags, operation, direction, isShadowTree);
// possibly created a complete arc, so we can identify and disambiguate role labels discriminatively
keepArc = identifyArcAndDisambiguateRoles(model, arc, words, origPosTags);
}
else
{ // arg is anchor (e.g. tree for 'will')
// if(tree.isAuxtree() && !tree.hasFootLeft())
// if(tree.isAuxtree() && (isShadowTree ? true : !isTreePP(tree, anchorNode, offset)))
if(tree.isAuxtree())
{
if(applyConllHeuristics || !(anchorNode == null || isTreePP(tree, anchorNode, offset) && arc.isArgumentIncomplete()))
{
mergedArc = setArgument(arc, anchorNode, words, origPosTags, operation, direction, isShadowTree);
}
else
{
ppMergedArc = isShadowTree ? setArgument(arc, anchorNode, words, origPosTags, operation, direction, isShadowTree) :
applyPPArgumentHeuristic(arc, tree, anchorNode, offset, words, origPosTags, operation, direction, isShadowTree);
}
// keepArc = true;
}
else if(prefixTreeNode != null)// arg is head of prefix tree
{
mergedArc = setArgument(arc, new DepNode(getNodeCategory(prefixTreeNode), prefixTreeNode.getCategory(),
prefixTreeNode.getNodeId(), prefixTreeNode.getOrigTree(), prefixTreeNode.getLambdaTimestamp()),
words, origPosTags, operation, direction, isShadowTree);
// keepArc = true;
}
if(relationWithMatchingAnchor != null)
{
mergedArc = setRelation(arc, relationWithMatchingAnchor, words, origPosTags, operation, direction, isShadowTree);
keepArc = identifyArcAndDisambiguateRoles(model, arc, words, origPosTags); // possibly created a complete arc, so we can disambiguate role labels discriminatively
}
}
if(!(integrationPoint.category.equals(":") || mergedArc || ppMergedArc || !keepArc)) // don't add trace; we will deal with it when we encounter the verb (late assignment)
addArc(arc);
}
示例12: findCodes
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
private static List<Code> findCodes(boolean forValueSet, MultiValueMap<MultiKey<String>, Code> codes, MultiKey<String> codeKey) {
return ((forValueSet && codes.containsKey(codeKey)) ? new ArrayList<>(codes.getCollection(codeKey)) : Collections.emptyList());
}