Java Code Examples for edu.stanford.nlp.ling.IndexedWord#index()
The following examples show how to use
edu.stanford.nlp.ling.IndexedWord#index() .
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: Simplifier.java From tint with GNU General Public License v3.0 | 6 votes |
protected static void addChildren(HashMultimap<Integer, Integer> children, Set<Integer> stack, IndexedWord current, SemanticGraph semanticGraph, Set<IndexedWord> used) { List<SemanticGraphEdge> edges = semanticGraph.getOutEdgesSorted(current); used.add(current); int index = current.index(); for (Integer integer : stack) { children.put(integer, index); } Set<Integer> newStack = new HashSet<>(stack); newStack.add(index); for (SemanticGraphEdge edge : edges) { IndexedWord target = edge.getTarget(); // String relation = edge.getRelation().toString(); // if (relation.equals("punct")) { // continue; // } if (!used.contains(target)) { addChildren(children, newStack, target, semanticGraph, used); } } }
Example 3
Source File: ReplaceSubordinateRule.java From tint with GNU General Public License v3.0 | 5 votes |
static TreeSet<String> getPersons(SemanticGraph semanticGraph, IndexedWord word, CoreMap sentence) { Stack<IndexedWord> wordsToCheck = new Stack<>(); wordsToCheck.add(word); int index = word.index(); while (!wordsToCheck.isEmpty()) { IndexedWord thisWord = wordsToCheck.pop(); List<SemanticGraphEdge> outEdgesSorted = semanticGraph.getOutEdgesSorted(thisWord); for (SemanticGraphEdge semanticGraphEdge : outEdgesSorted) { IndexedWord dependent = semanticGraphEdge.getDependent(); String pos = dependent.get(CoreAnnotations.PartOfSpeechAnnotation.class); if (pos.equals("VA")) { index = Math.min(index, dependent.index()); wordsToCheck.push(dependent); } } } CoreLabel token = sentence.get(CoreAnnotations.TokensAnnotation.class).get(index - 1); String morpho = token.get(DigiMorphAnnotations.MorphoAnnotation.class); String[] parts = morpho.split("\\s+"); TreeSet<String> persons = new TreeSet<>(); for (int i = 1; i < parts.length; i++) { String[] vParts = parts[i].split("\\+"); if (!vParts[1].equals("v")) { continue; } persons.add(vParts[5] + "+" + vParts[6]); } return persons; }
Example 4
Source File: DependencyBnBPreorderer.java From phrasal with GNU General Public License v3.0 | 5 votes |
FeatureNode(Tree node, IndexedWord hw) { List<Label> yield = node.yield(); this.word = (IndexedWord) node.label(); this.hw = hw; this.lm = (IndexedWord) yield.get(0); this.rm = (IndexedWord) yield.get(yield.size() - 1); this.dst = hw.index() - this.word.index(); }
Example 5
Source File: SupportCandidateType.java From uncc2014watsonsim with GNU General Public License v2.0 | 4 votes |
private static String wordID(IndexedWord word) { return "w" + clean(word.word()) + "_" + word.index(); }