List of usage examples for org.apache.commons.collections4.map MultiValueMap containsKey
boolean containsKey(Object key);
From source file:pltag.corpus.PredictionStringTree.java
protected String printOrigin(Integer nodeId, MultiValueMap<Integer, Integer> origin) { if (mapping == null) { makeMapping(origin);/* ww w. j av a 2 s . co m*/ } if (origin.containsKey(nodeId)) { Integer index = origin.getCollection(nodeId).iterator().next(); // String index = (String) origin.getCollection(nodeIDstring).iterator().next(); if (index >= mapping.length) { makeMapping(origin); } return String.valueOf(mapping[index]); // return mapping[Integer.parseInt(index)]; } return null; }
From source file:pltag.corpus.StringTree.java
protected boolean containsOriginNode(Integer nodeID, MultiValueMap<Integer, Integer> origin) { if (origin == null) { return false; }/* w w w . j a va 2 s.c o m*/ return origin.containsKey(nodeID); }
From source file:pltag.corpus.StringTree.java
@SuppressWarnings("unchecked") protected Collection<Integer> getOrigin(Integer nodeID, MultiValueMap<Integer, Integer> origin) { if (origin == null) { return null; }//from w ww.j a va 2s . c o m if (origin.containsKey(nodeID)) { return origin.getCollection(nodeID); } return null; }
From source file:pltag.corpus.StringTree.java
@SuppressWarnings("unchecked") protected Integer getLowestOrigin(Integer nodeID, MultiValueMap<Integer, Integer> origin) { Integer lowest = 9999999;/*from w w w . j a v a2 s.co m*/ 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); }
From source file:pltag.parser.ParsingTask.java
/** * Combines two trees by first checking whether they can be combined (no two shadow trees, or unused shadow tree) * and then calling the integration function and inserting results into the chart. * @param trees//ww w . j av a 2 s . co m * @param chart * @param chartindex * @param posOfNextWord * @return */ @SuppressWarnings("unchecked") // private ArrayList<ChartEntry> combineTrees(Collection<ElementaryStringTree> trees, Chart chart, // Collection<ChartEntry> lastSliceCopy, short chartindex, String[] origPosTags, double startTime, String posOfNextWord, SuperTagger superTagger, int beamWidth, boolean endfOfSent, int timestamp) { ArrayList<ChartEntry> newEntries = new ArrayList<ChartEntry>(); // try to integrate each tree (some may have two alternative fringes) // with prefix trees from prev slice. // add successful combinations to chart. ArrayList<ChartEntry> lastSliceCopy = getLastSlice(chartindex, chart); HashMap<ElementaryStringTree, ArrayList<TreeState>> treeStateMap = new HashMap<ElementaryStringTree, ArrayList<TreeState>>(); double totalTimeSuperTag = 0.0; int a = 0; int b = 0; double bestprob = Double.NEGATIVE_INFINITY; for (ChartEntry chartEntry : lastSliceCopy) { a++; Collection<ElementaryStringTree> selectedTrees; double start = System.currentTimeMillis(); //System.out.print(trees.size()+" "); // call the supertagger only on prediction trees (when trees are elementary trees, posOfNextWord is always "") boolean shadowTree = !posOfNextWord.equals(""); // selectedTrees = opts.train || shadowTree ? superTagger.superTag(trees, chartEntry, posOfNextWord) : trees ; selectedTrees = opts.train || !shadowTree ? trees : superTagger.superTag(trees, chartEntry, posOfNextWord); // selectedTrees = trees; //System.out.println(selectedTrees.size()); totalTimeSuperTag += (System.currentTimeMillis() - start); for (ElementaryStringTree tree : selectedTrees) { b++; ArrayList<TreeState> elemtreeStates; if (treeStateMap.containsKey(tree)) { elemtreeStates = treeStateMap.get(tree); } else { elemtreeStates = getTreeStateForTree(tree, chartindex); treeStateMap.put(tree, elemtreeStates); } for (TreeState elemtreetreeState : elemtreeStates) { MultiValueMap<String, ParserOperation> combinations = new MultiValueMap(); // if (System.currentTimeMillis() - startTime > 60000) return newEntries; if (tree.hasShadowInd() && chartEntry.getTreeState().getShadowTrees().size() > 2) { continue; } TreeState treeState = chartEntry.getTreeState(); if (opts.verbose && treeState.getUnaccessibles().isEmpty() && treeState.getFutureFringe().getNext() != null) { LogInfo.error("why not expanded???"); } String fringeString = treeState.getFringe().toString(); List<ChartEntry> ces = new ArrayList<ChartEntry>(); if (combinations.containsKey(fringeString)) { Collection<ParserOperation> operations = combinations.getCollection(fringeString); if (!elemtreetreeState.getRootNode().isShadow()) { ces.addAll(match(tree, elemtreetreeState, chart, chartEntry, origPosTags, chartindex)); } if (operations.size() == 1 && operations.contains(null)) { //don't need to do anything because this prefix tree does not integrate with prefix tree //need to do this at tree level. } else { for (ParserOperation operation : operations) { if (operation == null || operation == ParserOperation.verify) { continue; } else { ces.addAll(operation.combine(model, opts, words, origPosTags, treeState, elemtreetreeState, tree, chartindex)); } } } } else {//*/ combinations.put(fringeString, null); if (combineTwoShadowTreesInARow(chartEntry, elemtreetreeState)) { continue; } //***************** ces = integrate(treeState, elemtreetreeState, tree, chart, chartEntry, origPosTags, chartindex); //***************** } // clean up results for (ChartEntry cefirst : ces) { ArrayList<ChartEntry> expandedCEs = makeExpansions(cefirst); for (ChartEntry ce : expandedCEs) { for (BuildBlock bb : ce.getBuildBlocks()) { //System.out.println(bb.toString()+ bb.getIpi()+"ELEM:" + tree); if (didNotUseShadow(chartEntry, bb, bb.getIpi(), chartindex, tree)) { LinkedList<BuildBlock> list = new LinkedList<BuildBlock>(); list.add(bb); // ce.getTreeState().getFutureFringe().getBBHist().remove(bb); // TODO: FIX ce.getTreeState().getFutureFringe().getBBHist().remove(list); // TODO: FIX continue; } bb.setPrevChartEntry(chartEntry); if (!opts.train || opts.useProbabilityModel) { bb.retrieveProbability(model.getParams(), opts.freqBaseline); bb.removeElemTree(); // bb.removeFreqCounter(); } if (!elemtreetreeState.getShadowTrees().isEmpty()) { ShadowStringTree shadowt = ce.getTreeState().getShadowTrees() .get(ce.getTreeState().getShadowTrees().size() - 1); shadowt.setPredictProb(bb.getProbability()); } if (!combinations.containsValue(fringeString, bb.getOperation())) { combinations.put(fringeString, bb.getOperation()); } //System.out.print("\n"+ce.getTreeState().getFringe()); if (!opts.train || opts.useProbabilityModel) { // double vlap = computeLAP(tree); ce.updateProbs(ce.getTreeState().getFutureFringe(), 0); } //System.out.println(ce.getBestProbability()+"\t"+ce+"\n"+elemtreetreeState+"\n"+tree+a+" "+b+"\n---\n"); if (opts.pruneUsingScores) { if (ce.getBestScore() > bestprob) { bestprob = ce.getBestScore(); } if (ce.getBestScore() > bestprob - beamWidth) { newEntries.add(ce); } } else { double bestPropWithVlap = ce.getBestProbability() + (opts.train || !shadowTree ? 0.0d : computeLAP(tree)); if (bestPropWithVlap > bestprob) { bestprob = bestPropWithVlap; } if (opts.train || bestPropWithVlap > bestprob - beamWidth) { newEntries.add(ce); } } } // for each build block } // for each expanded chart entry } // for each new chart entry } // for each elementary tree state (fringes) ALWAYS ONE } // for each elementary tree } // for each chart entry // if (opts.timeProfile && totalTimeSuperTag > 100) // { // Utils.log("supertagtime: " + totalTimeSuperTag / 1000 + "\t"); // } return newEntries; }
From source file:pltag.parser.semantics.DepTreeState.java
/** * Checks whether the integration point on the elementary tree has a role. * @param tree an ElementaryStringTree with potential roles attached to it * @param rolesPerNode a Map of nodes with their roles * @param integrationPointId integration point id * @param ipIdOffset the node id offset. This is the highest node id of the prefix tree. * @return //from w ww . j a v a 2 s. com */ private boolean elemIntegrationPointHasRole(ElementaryStringTree tree, MultiValueMap<Integer, Role> rolesPerNode, int integrationPointId) { return tree.hasRoles() && rolesPerNode.containsKey(integrationPointId); }