Example usage for org.apache.commons.collections4.map MultiValueMap values

List of usage examples for org.apache.commons.collections4.map MultiValueMap values

Introduction

In this page you can find the example usage for org.apache.commons.collections4.map MultiValueMap values.

Prototype

@Override
@SuppressWarnings("unchecked")
public Collection<Object> values() 

Source Link

Document

Gets a collection containing all the values in the map.

Usage

From source file:pltag.corpus.ConnectionPathCalculator.java

/**
 * Calculates which prediction trees need to be generated from the set of connectionNodes.
 * And combines prediction trees if possible.
 * /*from w  w w . j  av a2  s .com*/
 * @param currentLeafNumber
 * @param lexicon 
 * @return
 */
@SuppressWarnings("unchecked") // cast to Collection<String>
private List<PredictionStringTree> generatePredictionTrees(int currentLeafNumber, List<StringTree> lexicon) {//, String leaf) {
                                                                                                             //if (currentLeafNumber.equals("6"))
                                                                                                             //System.out.print("");
    MultiValueMap predictionTreeNodeMap = findNodesWithGreaterLeafnumbers(currentLeafNumber);
    ArrayList<PredictionStringTree> localPredictedTrees = new ArrayList<PredictionStringTree>();
    int sourcetreeno = 0;
    ArrayList<PredictionStringTree> unhelpfulpredtrees = new ArrayList<PredictionStringTree>();
    HashMap<Integer, Integer> translations = new HashMap<Integer, Integer>();
    //System.out.println("prediction tree to connect leaf " + currentLeafNumber + " number of pred trees needed: "+ predictionTreeNodeMap.size());
    //System.out.println("nodes needed: "+predictionTreeNodeMap);
    for (Integer predictionTreeOrigin : (Collection<Integer>) predictionTreeNodeMap.keySet()) {
        ElementaryStringTree originalStringTree = (ElementaryStringTree) sentenceWordLex[predictionTreeOrigin];
        //            ElementaryStringTree originalStringTree = (ElementaryStringTree) sentenceWordLex[Integer.parseInt(predictionTreeOrigin)];
        if (originalStringTree == null) {
            continue;
        }
        originalStringTree.makeLexiconEntry();
        if (originalStringTree.categories[originalStringTree.root] != null)
        //            if (originalStringTree.categories[Integer.parseInt(originalStringTree.root)] != null)
        {
            translations.putAll(originalStringTree.removeUnaryNodes(originalStringTree.root));
        } else {
            translations.putAll(originalStringTree.removeUnaryNodes(originalStringTree.coordanchor));
        }
        if (originalStringTree.getAnchor() == Integer.MIN_VALUE
                && originalStringTree.treeString.startsWith("*"))
        //            if (originalStringTree.getAnchor().equals("") && originalStringTree.treeString.startsWith("*"))
        {
            continue;
        }
        Collection<Integer> cn = predictionTreeNodeMap.getCollection(predictionTreeOrigin);
        PredictionStringTree predictionTree = buildPredictionTree(originalStringTree, cn, currentLeafNumber);
        //            PredictionStringTree predictionTree = buildPredictionTree(originalStringTree, cn, Integer.parseInt(currentLeafNumber));
        predictionTree.cutTail(cn);
        if (predictionTree.hasUsefulNodes(cn, translations)) {
            predictionTree = buildPredictionTree(originalStringTree, cn, currentLeafNumber);
            //                predictionTree = buildPredictionTree(originalStringTree, cn, Integer.parseInt(currentLeafNumber));
            sourcetreeno++;
            //System.out.println(predictionTree.print());
            ArrayList<PredictionStringTree> newlist = new ArrayList<PredictionStringTree>();
            ArrayList<PredictionStringTree> removelist = new ArrayList<PredictionStringTree>();
            // combine prediction trees (trees can always be combined! I think.)
            for (PredictionStringTree otherTree : localPredictedTrees) {
                PredictionStringTree ct = combinePredTrees(predictionTree, otherTree,
                        predictionTreeNodeMap.values(), translations);//.copyPred();
                if (ct != null) {
                    removelist.add(otherTree);
                    removelist.add(predictionTree);
                    newlist.remove(predictionTree);
                    newlist.add(ct);
                    predictionTree = ct;
                }
            }
            if (predictionTree.isAuxtree()) {
                localPredictedTrees.add(predictionTree);
            } else {
                localPredictedTrees.add(0, predictionTree);
            }
            localPredictedTrees.removeAll(removelist);
            //            might add too much here.
            for (PredictionStringTree npt : newlist) {
                if (predictionTree.isAuxtree()) {
                    localPredictedTrees.add(npt);
                } else {
                    localPredictedTrees.add(0, npt);
                }
            }
        } else {
            predictionTree = buildPredictionTree(originalStringTree, cn, currentLeafNumber);
            //                predictionTree = buildPredictionTree(originalStringTree, cn, Integer.parseInt(currentLeafNumber));
            unhelpfulpredtrees.add(predictionTree);
        }
    }
    if (localPredictedTrees.isEmpty() & unhelpfulpredtrees.size() > 0) {
        PredictionStringTree first = null;
        int min = Integer.MAX_VALUE;
        //         String others = "";
        for (PredictionStringTree pt : unhelpfulpredtrees) {
            if (pt.isAuxtree()) {
                continue;
            }
            int anchorpos = pt.getAnchorList().get(0);
            //                int anchorpos = Integer.parseInt(pt.getAnchorList().get(0));
            if (anchorpos < min) {
                min = anchorpos;
                if (first != null)
                //            others += " @ "+first.toString();
                {
                    first = pt;
                }
            }
            //      else{ 
            //         if (first !=null)
            //         others += " @ "+first.toString();
            //      }
        }
        if (first != null) {
            //      System.out.println(first+"\t"+others);
            localPredictedTrees.add(first);
        }
    } //*/
    if (localPredictedTrees.size() > 1) {
        PredictionStringTree predictionTree = localPredictedTrees.get(0);
        ArrayList<PredictionStringTree> newlist = new ArrayList<PredictionStringTree>();
        ArrayList<PredictionStringTree> removelist = new ArrayList<PredictionStringTree>();
        for (int i = 1; i < localPredictedTrees.size(); i++) {
            PredictionStringTree otherTree = localPredictedTrees.get(i);
            PredictionStringTree ct = combinePredTrees(predictionTree, otherTree,
                    predictionTreeNodeMap.values(), translations);//.copyPred();
            if (ct != null) {
                removelist.add(otherTree);
                removelist.add(predictionTree);
                newlist.remove(predictionTree);
                newlist.add(ct);
                predictionTree = ct;
            }
        }
        if (predictionTree.isAuxtree()) {
            localPredictedTrees.add(predictionTree);
        } else {
            localPredictedTrees.add(0, predictionTree);
        }
        localPredictedTrees.removeAll(removelist);
        //            might add too much here.
        for (PredictionStringTree npt : newlist) {
            if (predictionTree.isAuxtree()) {
                localPredictedTrees.add(npt);
            } else {
                localPredictedTrees.add(0, npt);
            }
        }
    }
    for (PredictionStringTree pst : localPredictedTrees) {
        pst.cutTail(predictionTreeNodeMap.values());
    }

    if (localPredictedTrees.size() > 1) {
        LogInfo.error("unaccounted case! combination of prediction trees; number of trees: " + sourcetreeno
                + " to connect leaf " + currentLeafNumber);
    }
    //        noOfSources.put(sourcetreeno + "", noOfSources.get(sourcetreeno + "").intValue() + 1);
    noOfSources.put(sourcetreeno, noOfSources.get(sourcetreeno) + 1);
    return localPredictedTrees;
}

From source file:pltag.corpus.PredictionStringTree.java

private void makeMapping(MultiValueMap<Integer, Integer> origin) {
    Iterator valuit = origin.values().iterator();
    HashMap<Integer, Boolean> singlevals = new HashMap<Integer, Boolean>();
    int maxval = -1;
    while (valuit.hasNext()) {
        Integer val = (Integer) valuit.next();
        singlevals.put(val, true);
        if (val > maxval) {
            maxval = val;
        }//from  w  ww  . j  ava  2s . c om
        //         if (Integer.parseInt(val) > maxval){maxval = Integer.parseInt(val);}
    }
    Boolean[] v = new Boolean[maxval + 1];
    for (Integer key : singlevals.keySet()) {
        //      for (String key : singlevals.keySet()){
        //         int intkey= Integer.parseInt(intkey);
        v[key] = true;
    }
    mapping = new int[maxval + 1];
    int j = 1;
    for (int i = 0; i < v.length; i++) {
        if (v[i] != null) {
            mapping[i] = j;
            //            mapping[i] = j+"";
            j++;
        }
    }
}

From source file:pltag.parser.Lexicon.java

@SuppressWarnings("unchecked")
protected int checkType(String string, MultiValueMap stringTreeMap) {
    Collection<StringTree> values = stringTreeMap.values();
    int errors = 0;
    for (StringTree tree : values) {
        if ((string.equals("MOD") && tree.isAuxtree()) || (string.equals("ARG") && !tree.isAuxtree())) {
            //ok//from  w  w  w .ja  v a2s. c  o m
        } else {
            System.err.println(
                    "wrong tree type: " + string + tree.getStructure(tree.getRoot(), opts.useSemantics));
            errors++;
        }
    }
    return errors;
}

From source file:pltag.parser.semantics.classifier.ArgumentClassifier.java

public void extractFeatures(Map<Predicate, Proposition> predProps, Map<Predicate, Proposition> goldProps,
        Lexicon lexicon, boolean train) {
    MultiValueMap<Predicate, Argument> identifiedArcs = new MultiValueMap<Predicate, Argument>();
    // Get things in common (Arguments)
    Iterator<Map.Entry<Predicate, Proposition>> iterProps = goldProps.entrySet().iterator();
    while (iterProps.hasNext()) {
        Map.Entry<Predicate, Proposition> goldEntry = iterProps.next();
        Proposition predProp = predProps.get(goldEntry.getKey());
        if (predProp == null) // if we didn't find the correct predicate
        {//from   ww  w  .j a v  a 2  s . c om
            Predicate predPredIgnoreCase = Predicate.getPredicateIgnoreSense(goldEntry.getKey(),
                    predProps.keySet());
            if (predPredIgnoreCase != null) // found correct predicate with wrong sense
            {
                predProp = predProps.get(predPredIgnoreCase);
            }
        }
        if (predProp != null) // continue with identifying correct arguments
        {
            List<Argument> goldArgs = goldEntry.getValue().getArguments();
            List<Argument> predArgs = predProp.getArguments();

            Iterator<Argument> iterGoldArgs = goldArgs.iterator();
            while (iterGoldArgs.hasNext()) {
                Argument goldArg = iterGoldArgs.next();
                Iterator<Argument> iterPredArgs = predArgs.iterator();
                while (iterPredArgs.hasNext()) // True Positive (gold role label, +1 identifier label)
                {
                    Argument predArg = iterPredArgs.next();
                    if (predArg.getTimestamp() == goldArg.getTimestamp()) {
                        addFeatureVecs(predProp.getPredicate(), predArg, goldArg.getRole(), true,
                                identifiedArcs, train);
                        iterGoldArgs.remove();
                        iterPredArgs.remove();
                        break;
                    }
                }
            } //  while
            if (predArgs.isEmpty())
                predProps.remove(goldEntry.getKey());
            if (goldArgs.isEmpty())
                iterProps.remove();
        } // if
    } // while
      // Mark the differences between the two maps (entries left)
    for (Proposition predProp : predProps.values()) {
        for (Argument predArg : predProp.getArguments()) // False Positive
        {
            addFeatureVecs(predProp.getPredicate(), predArg, null, false, identifiedArcs, train);
        }
    }
    for (Proposition goldProp : goldProps.values()) {
        for (Argument goldArg : goldProp.getArguments()) // False Negatives (inaccurate)
        {
            Predicate goldPred = goldProp.getPredicate();
            // try to find a predicate we've already correctly predicted earlier
            Predicate predPred = Predicate.getPredicateIgnoreSense(goldPred, identifiedArcs.keySet());
            if (predPred != null) {
                // try to find argument in list of identified arcs (attached to a wrong predicate)
                boolean foundInIdentified = false;
                for (Object predObj : identifiedArcs.values()) {
                    Argument predArg = (Argument) predObj;
                    if (predArg.getTimestamp() == goldArg.getTimestamp()) {
                        addFeatureVecs(predPred, predArg, goldArg.getRole(), true, identifiedArcs, train);
                        foundInIdentified = true;
                        break;
                    } // if
                } // for
                if (!foundInIdentified) // reconstruct argument (fairly inaccurate) from lexicon and info from rest predictions
                {
                    Argument reconstructedArgument = reconstructArgument(lexicon, predPred, goldArg,
                            identifiedArcs);
                    if (reconstructedArgument != null)
                        addFeatureVecs(predPred, reconstructedArgument, goldArg.getRole(), true, identifiedArcs,
                                train);
                }
            } // if
        } // for
    } // for
}

From source file:pltag.parser.semantics.Dependencies.java

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);//w w w. j a v  a 2s . c  o m
        out.put(new DepNode(oldArc.getIntegrationPoint()), newArc);
    }
    return out;
}