Java Code Examples for it.unimi.dsi.fastutil.objects.ObjectArrayList#contains()
The following examples show how to use
it.unimi.dsi.fastutil.objects.ObjectArrayList#contains() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoreNLPUtils.java From minie with GNU General Public License v3.0 | 6 votes |
/** * Given the sentence semantic graph and a list of words, get a subgraph containing just the words in the list * 'words'. Each typed dependency has each word from the list as a governor. * @param sg: sentence semantic graph * @param words: list of words which should contain the semantic graph * @return subgraph containing the words from 'words' * TODO: this needs to be double checked! In some cases we have weird graphs, where there are words missing. * E.g. the sentence 120 from NYT "The International ... ". Try this for getting the subgraph when the source is * detected. */ public static SemanticGraph getSubgraphFromWords(SemanticGraph sg, ObjectArrayList<IndexedWord> words){ // Determining the root int minInd = Integer.MAX_VALUE; IndexedWord root = new IndexedWord(); for (IndexedWord w: words){ if (w.index() < minInd){ minInd = w.index(); root = w; } } // Getting the typed dependency ObjectArrayList<TypedDependency> tds = new ObjectArrayList<TypedDependency>(); for (TypedDependency td: sg.typedDependencies()){ if (words.contains(td.gov()) && words.contains(td.dep())) tds.add(td); } // Create the semantic graph TreeGraphNode rootTGN = new TreeGraphNode(new CoreLabel(root)); EnglishGrammaticalStructure gs = new EnglishGrammaticalStructure(tds, rootTGN); SemanticGraph phraseSg = SemanticGraphFactory.generateUncollapsedDependencies(gs); return phraseSg; }
Example 2
Source File: CoreNLPUtils.java From minie with GNU General Public License v3.0 | 6 votes |
private static SemanticGraph getSubgraph(ObjectArrayList<TypedDependency> tds, SemanticGraph sg, IndexedWord parent, SemanticGraphEdge e, int maxPathLength, ObjectArrayList<IndexedWord> words){ Set<IndexedWord> children = sg.getChildren(parent); for (IndexedWord child: children){ if (((sg.getShortestDirectedPathEdges(sg.getFirstRoot(), child)).size() <= maxPathLength) && words.contains(child)){ e = sg.getEdge(parent, child); tds.add(new TypedDependency(e.getRelation(), parent, child)); if (sg.hasChildren(child)) getSubgraph(tds, sg, child, e, maxPathLength, words); } // else break; } TreeGraphNode rootTGN = new TreeGraphNode(new CoreLabel(parent)); EnglishGrammaticalStructure gs = new EnglishGrammaticalStructure(tds, rootTGN); return SemanticGraphFactory.generateUncollapsedDependencies(gs); }
Example 3
Source File: MathInputScreen.java From WarpPI with Apache License 2.0 | 6 votes |
private ObjectArrayList<Function> getKnownVariables(final Function[] fncs) { final ObjectArrayList<Function> res = new ObjectArrayList<>(); for (final Function f : fncs) { if (f instanceof FunctionOperator) { res.addAll(getKnownVariables(new Function[] { ((FunctionOperator) f).getParameter1(), ((FunctionOperator) f).getParameter2() })); } else if (f instanceof FunctionDynamic) { res.addAll(getKnownVariables(((FunctionDynamic) f).getParameters())); } else if (f instanceof FunctionSingle) { res.addAll(getKnownVariables(new Function[] { ((FunctionSingle) f).getParameter() })); } else if (f instanceof Variable) { if (((Variable) f).getType() == Variable.V_TYPE.CONSTANT) { if (!res.contains(f)) { res.add(f); } } } } return res; }
Example 4
Source File: MathSolver.java From WarpPI with Apache License 2.0 | 5 votes |
private void setSimplified(Function fnc, Rule rule) { ObjectArrayList<Rule> oar; if (simplificationCache.containsKey(fnc)) { oar = new ObjectArrayList<>(); simplificationCache.put(fnc, oar); } else { oar = simplificationCache.get(fnc); if (oar.contains(rule)) return; } oar.add(rule); }