本文整理汇总了Java中org.apache.commons.collections4.map.MultiValueMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java MultiValueMap.put方法的具体用法?Java MultiValueMap.put怎么用?Java MultiValueMap.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.collections4.map.MultiValueMap
的用法示例。
在下文中一共展示了MultiValueMap.put方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例4: getLexEntriesContaining
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
public MultiValueMap<String, ElementaryStringTree> getLexEntriesContaining(String category)
{
MultiValueMap<String, ElementaryStringTree> out = new MultiValueMap();
for(String key : wordPosMap.keySet())
{
String firstWordPos = wordPosMap.getCollection(key).iterator().next();
Collection<ElementaryStringTree> col = getEntries(key, firstWordPos, firstWordPos.split(" ")[0], false, 0);
for(ElementaryStringTree e : col)
{
if(e.toString().contains(" " +category + "^"))
out.put(key, e);
}
}
return out;
}
示例5: cloneArcs
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
private MultiValueMap<DepNode, DependencyArc> cloneArcs(MultiValueMap<DepNode, DependencyArc> map, Map<DependencyArc, DependencyArc> oldNewMap)
{
MultiValueMap<DepNode, DependencyArc> out = new MultiValueMap<DepNode, DependencyArc>();
for(Object o : map.values())
{
DependencyArc oldArc = (DependencyArc)o;
DependencyArc newArc = new DependencyArc(oldArc);
oldNewMap.put(oldArc, newArc);
out.put(new DepNode(oldArc.getIntegrationPoint()), newArc);
}
return out;
}
示例6: addFeatureVecs
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
private void addFeatureVecs(Predicate predicate, Argument argument, String roleLabel, boolean identifyLabel, MultiValueMap<Predicate, Argument> identifiedArcs, boolean train)
{
identifiedArcs.put(predicate, argument);
FeatureVec vec = newFeatureVec();
extractBilexicalFeatures(predicate, argument, train, vec);
extractSyntacticFeatures(predicate, argument, train, vec);
vec.setLabel(identifyLabel ? 1 : -1);
identifierTrain.add(vec);
if(roleLabel != null)
{
FeatureVec labellerVec = new FeatureVec(vec);
labellerVec.setLabel(featureIndexers.getRoleIndex(roleLabel));
labellerTrain.add(labellerVec);
}
}
示例7: findNodesWithGreaterLeafnumbers
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
/**
* From all the nodes that are in the set of connection nodes, find those that have
* larger smallest origins than the current leaf number, and sort them by their smallest
* origins, and put them into a MultiValueHashMap. This map will now contain as many keys
* as prediction trees needed to connect the current word. The values of these keys contain
* the nodes that are needed in the prediction tree to achieve connectivity.
* (+ one additional node for the head node???, all arguments before spine? that should be
* in prediction tree build procedure.)
*
* @param currentLeafNumber
* @return
*/
private MultiValueMap findNodesWithGreaterLeafnumbers(int currentLeafNumber)
{
MultiValueMap<Integer, Integer> connectionNodes = new MultiValueMap();
//deleteUnary(connectedNodes);
int leafToBeConnectedNumber = currentLeafNumber;
// int leafToBeConnectedNumber = Integer.parseInt(currentLeafNumber);
for (Integer node : connectedNodes)
{
Integer innerNodeLowestUp = stringTree.getLowestOrigin(node, stringTree.originUp);
// int innerNodeLowestUp = Integer.parseInt(stringTree.getLowestOrigin(node, stringTree.originUp));
Integer inld = stringTree.getLowestOrigin(node, stringTree.originDown);
if (innerNodeLowestUp > leafToBeConnectedNumber && !connectionNodes.containsValue(innerNodeLowestUp, node))
{
//check whether that node can be accounted for by one of the connection trees that were already found?
connectionNodes.put(innerNodeLowestUp, node);
}
if (inld != null)
{
Integer innerNodeLowestDown = stringTree.getLowestOrigin(node, stringTree.originDown);
// int innerNodeLowestDown = Integer.parseInt(stringTree.getLowestOrigin(node, stringTree.originDown));
if (innerNodeLowestDown > leafToBeConnectedNumber
&& !connectionNodes.containsValue(innerNodeLowestDown, node))
// && !connectionNodes.containsValue(innerNodeLowestDown + "", node))
{
connectionNodes.put(innerNodeLowestDown, node);
// connectionNodes.put(innerNodeLowestDown + "", node);
}
}
}
return connectionNodes;
}
示例8: 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;
}
示例9: superTag
import org.apache.commons.collections4.map.MultiValueMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Collection<ElementaryStringTree> superTag(
Collection<ElementaryStringTree> trees, ChartEntry chartEntry, String nextPosCat)
{
MultiValueMap<Double, ElementaryStringTree> mvm = new MultiValueMap();//<Double, ElementaryStringTree>
// boolean predTree = true;
// if (nextPosCat.equals("")) {
// //nextPosCat = chartEntry.getPrevPOStags();//
//// predTree = false;
// return trees; //
// }
//else return trees;
Fringe fringe = chartEntry.getTreeState().getFringe();
for (ElementaryStringTree tree : trees)
{
// Fringe fringe = chartEntry.getTreeState().getFringe();
// do this in combineTrees?
// String predTreeStruct = tree.getUnlexStruct(tree.getRoot());//getTreeString();//.substring(tree.getTreeString().indexOf("\t")+1);
String predTreeStruct = predTreeStructMap.get(tree);//getTreeString();//.substring(tree.getTreeString().indexOf("\t")+1);
String predTreeFringeCat = predTreeFringeMap.get(tree);
// String predTreeFringeCat;
// if (predTree) predTreeFringeCat = this.catFringeMap.get(tree);
// else {
// short[] nullarray = new short[2];
// nullarray[0] = -99;
// nullarray[1] = -99;
// HashMap<Short, Node> nodekernelmap = new HashMap<Short, Node>();
// predTreeFringeCat = TreeState.getAuxFringe(tree, -1, nullarray, nodekernelmap).toCatString();
// }
// String currentPosCat = tree.getMainLeaf(tree.getRoot());
String currentPosCat = predTreeMainLeafMap.get(tree);
if (currentPosCat.contains("\t"))
{
currentPosCat = currentPosCat.substring(0, currentPosCat.indexOf("\t"));
}
if (currentPosCat.contains(" "))
{
currentPosCat = currentPosCat.substring(0, currentPosCat.indexOf(" "));
}
SuperTagStructElement stse = new SuperTagStructElement(predTreeStruct, predTreeFringeCat, currentPosCat);
SuperTagElement ste = new SuperTagElement(fringe, nextPosCat, currentPosCat, predTreeFringeCat);
Double s2;
double s1 = stse.getSmoothedProb(freqStruct);
// s1 = superTagElementCache.get(ste);
// if(s1 == null)
// {
// s1 = stse.getSmoothedProb(freqStruct);
// superTagStructCache.put(ste, s1);
// }
s2 = superTagElementCache.get(ste);
if(s2 == null)
{
s2 = ste.getSmoothedProb(freqFringe);
superTagElementCache.put(ste, s2);
}
//if (s2>1.0340192327577293E-2){
// System.out.println(s1+"\t"+s2+"\t"+stse+"\t"+ste+"\n");
// ste.getSmoothedProb(bigFreqMapFringe);
//}
// Double prob = s1 * s2;
mvm.put(s1 * s2, tree);
}
ArrayList<ElementaryStringTree> resultlist = new ArrayList<ElementaryStringTree>();
Double[] keys = ((Set<Double>) mvm.keySet()).toArray(new Double[mvm.keySet().size()]);
Arrays.sort(keys);
int i = keys.length - 1;
while (i >= 0 && resultlist.size() < supertagThreshold)
{
resultlist.addAll(mvm.getCollection(keys[i]));
// System.out.print(keys[i]+" ("+mvm.getCollection(keys[i]).size()+"); ");
i--;
}
//superTag(resultlist, chartEntry, nextPosCat, true);
// System.out.print("(" + resultlist.size()+" shadow trees)");
/* if (resultlist.size() > 20){
System.out.print("(" + resultlist.size()+" shadow trees)");
superTag(resultlist, chartEntry, nextPosCat, true);
}*/
return resultlist;
}
示例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;
}