private List<IndexedWord> getHeadPathToRoot() { return headPathToRoot == null ? (headPathToRoot = enhancedDependency.getPathToRoot(headIndexedWord)) : headPathToRoot; }
/** * Return the real syntactic parent of vertex. */ public IndexedWord getParent(IndexedWord vertex) { List<IndexedWord> path = getPathToRoot(vertex); if (path != null && path.size() > 0) return path.get(0); else return null; }
/** * Find the path from the given node to a root. The path does not include the * given node. Returns an empty list if vertex is a root. Returns null if a * root is inaccessible (should never happen). */ public List<IndexedWord> getPathToRoot(IndexedWord vertex) { List<IndexedWord> path = getPathToRoot(vertex, Generics.newArrayList()); if (path != null) Collections.reverse(path); return path; }
@Override public void evaluate(SemanticGraph sg, SemgrexMatcher sm) { List<IndexedWord> nodes = new ArrayList<>(sg.vertexSet()); for (IndexedWord node : nodes) { List<IndexedWord> rootPath = sg.getPathToRoot(node); if (rootPath == null) { sg.removeVertex(node); } } }
List<IndexedWord> path = getPathToRoot(parent, used); if (path != null) { path.add(parent);
public int getModal(Dictionaries dict) { if(headIndexedWord == null) return 0; // direct modal in a child Collection<IndexedWord> children = dependency.getChildren(headIndexedWord); for(IndexedWord child : children) { if(dict.modals.contains(child.lemma())) return 1; } // check the parent IndexedWord parent = dependency.getParent(headIndexedWord); if (parent != null) { if(dict.modals.contains(parent.lemma())) return 1; // check the children of the parent (that is needed for modal auxiliaries) IndexedWord child = dependency.getChildWithReln(parent, UniversalEnglishGrammaticalRelations.AUX_MODIFIER); if(!dependency.hasParentWithReln(headIndexedWord, UniversalEnglishGrammaticalRelations.NOMINAL_SUBJECT) && child != null && dict.modals.contains(child.lemma())) return 1; } // look at the path to root List<IndexedWord> path = dependency.getPathToRoot(headIndexedWord); if(path == null) return 0; for(IndexedWord word : path) { if(dict.modals.contains(word.lemma())) return 1; } return 0; }
private static boolean findSpeaker(Document doc, int utterNum, int sentNum, List<CoreMap> sentences, int startIndex, int endIndex, Dictionaries dict) { List<CoreLabel> sent = sentences.get(sentNum).get(CoreAnnotations.TokensAnnotation.class); for(int i = startIndex ; i < endIndex ; i++) { CoreLabel cl = sent.get(i); if(cl.get(CoreAnnotations.UtteranceAnnotation.class)!=0) continue; String lemma = cl.lemma(); String word = cl.word(); if(dict.reportVerb.contains(lemma) && cl.tag().startsWith("V")) { // find subject SemanticGraph dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class); if (dependency == null) { dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class); } IndexedWord w = dependency.getNodeByWordPattern(word); if (w != null) { if(findSubject(doc, dependency, w, sentNum, utterNum)) return true; for(IndexedWord p : dependency.getPathToRoot(w)) { if(!p.tag().startsWith("V") && !p.tag().startsWith("MD")) break; if(findSubject(doc, dependency, p, sentNum, utterNum)) return true; // handling something like "was talking", "can tell" } } else { Redwood.log("debug-preprocessor", "Cannot find node in dependency for word " + word); } } } return false; }
public int getReportEmbedding(Dictionaries dict) { if(headIndexedWord == null) return 0; // check adverbial clause with marker "as" for(IndexedWord sibling : dependency.getSiblings(headIndexedWord)) { if(dict.reportVerb.contains(sibling.lemma()) && dependency.hasParentWithReln(sibling,UniversalEnglishGrammaticalRelations.ADV_CLAUSE_MODIFIER)) { IndexedWord marker = dependency.getChildWithReln(sibling,UniversalEnglishGrammaticalRelations.MARKER); if (marker != null && marker.lemma().equals("as")) { return 1; } } } // look at the path to root List<IndexedWord> path = dependency.getPathToRoot(headIndexedWord); if(path == null) return 0; boolean isSubject = false; // if the node itself is a subject, we will not take into account its parent in the path if(dependency.hasParentWithReln(headIndexedWord, UniversalEnglishGrammaticalRelations.NOMINAL_SUBJECT)) isSubject = true; for (IndexedWord word : path) { if(!isSubject && (dict.reportVerb.contains(word.lemma()) || dict.reportNoun.contains(word.lemma()))) { return 1; } // check how to put isSubject isSubject = dependency.hasParentWithReln(word, UniversalEnglishGrammaticalRelations.NOMINAL_SUBJECT); } return 0; }
List<IndexedWord> path = sg.getPathToRoot(node); if (path != null) depthMap.put(node, path.size());
private List<IndexedWord> getHeadPathToRoot() { return headPathToRoot == null ? (headPathToRoot = enhancedDependency.getPathToRoot(headIndexedWord)) : headPathToRoot; }
/** * Find the path from the given node to a root. The path does not include the * given node. Returns an empty list if vertex is a root. Returns null if a * root is inaccessible (should never happen). */ public List<IndexedWord> getPathToRoot(IndexedWord vertex) { return getPathToRoot(vertex, new Vector<IndexedWord>()); }
/** * Return the real syntactic parent of vertex. */ public IndexedWord getParent(IndexedWord vertex) { List<IndexedWord> path = getPathToRoot(vertex); if (path != null && path.size() > 0) return path.get(0); else return null; }
/** * Return the real syntactic parent of vertex. */ public IndexedWord getParent(IndexedWord vertex) { List<IndexedWord> path = getPathToRoot(vertex); if (path != null && path.size() > 0) return path.get(0); else return null; }
/** * Return the real syntactic parent of vertex. */ public IndexedWord getParent(IndexedWord vertex) { List<IndexedWord> path = getPathToRoot(vertex); if (path != null && path.size() > 0) return path.get(0); else return null; }
/** * Find the path from the given node to a root. The path does not include the * given node. Returns an empty list if vertex is a root. Returns null if a * root is inaccessible (should never happen). */ public List<IndexedWord> getPathToRoot(IndexedWord vertex) { List<IndexedWord> path = getPathToRoot(vertex, Generics.newArrayList()); if (path != null) Collections.reverse(path); return path; }
/** * Find the path from the given node to a root. The path does not include the * given node. Returns an empty list if vertex is a root. Returns null if a * root is inaccessible (should never happen). */ public List<IndexedWord> getPathToRoot(IndexedWord vertex) { List<IndexedWord> path = getPathToRoot(vertex, Generics.newArrayList()); if (path != null) Collections.reverse(path); return path; }
private List<IndexedWord> getPathToRoot(IndexedWord vertex, List<IndexedWord> used) { used.add(vertex); List<IndexedWord> parents = getParentList(vertex); parents.removeAll(used); if (roots.contains(vertex) || (parents.size() == 0)) { used.remove(used.size() - 1); if (roots.contains(vertex)) return new Vector<IndexedWord>(); else return null; // no path found } for (IndexedWord parent : parents) { List<IndexedWord> path = getPathToRoot(parent, used); if (path != null) { path.add(0, parent); used.remove(used.size() - 1); return path; } } used.remove(used.size() - 1); return null; }
public int getModal(Dictionaries dict) { if(headIndexedWord == null) return 0; // direct modal in a child Collection<IndexedWord> children = dependency.getChildren(headIndexedWord); for(IndexedWord child : children) { if(dict.modals.contains(child.lemma())) return 1; } // check the parent IndexedWord parent = dependency.getParent(headIndexedWord); if (parent != null) { if(dict.modals.contains(parent.lemma())) return 1; // check the children of the parent (that is needed for modal auxiliaries) IndexedWord child = dependency.getChildWithReln(parent, UniversalEnglishGrammaticalRelations.AUX_MODIFIER); if(!dependency.hasParentWithReln(headIndexedWord, UniversalEnglishGrammaticalRelations.NOMINAL_SUBJECT) && child != null && dict.modals.contains(child.lemma())) return 1; } // look at the path to root List<IndexedWord> path = dependency.getPathToRoot(headIndexedWord); if(path == null) return 0; for(IndexedWord word : path) { if(dict.modals.contains(word.lemma())) return 1; } return 0; }
public int getModal(Dictionaries dict) { if(headIndexedWord == null) return 0; // direct modal in a child Collection<IndexedWord> children = dependency.getChildren(headIndexedWord); for(IndexedWord child : children) { if(dict.modals.contains(child.lemma())) return 1; } // check the parent IndexedWord parent = dependency.getParent(headIndexedWord); if (parent != null) { if(dict.modals.contains(parent.lemma())) return 1; // check the children of the parent (that is needed for modal auxiliaries) IndexedWord child = dependency.getChildWithReln(parent,EnglishGrammaticalRelations.AUX_MODIFIER); if(!dependency.hasParentWithReln(headIndexedWord, EnglishGrammaticalRelations.NOMINAL_SUBJECT) && child != null && dict.modals.contains(child.lemma())) return 1; } // look at the path to root List<IndexedWord> path = dependency.getPathToRoot(headIndexedWord); if(path == null) return 0; for(IndexedWord word : path) { if(dict.modals.contains(word.lemma())) return 1; } return 0; }
public int getReportEmbedding(Dictionaries dict) { if(headIndexedWord == null) return 0; // check adverbial clause with marker "as" for(IndexedWord sibling : dependency.getSiblings(headIndexedWord)) { if(dict.reportVerb.contains(sibling.lemma()) && dependency.hasParentWithReln(sibling,UniversalEnglishGrammaticalRelations.ADV_CLAUSE_MODIFIER)) { IndexedWord marker = dependency.getChildWithReln(sibling,UniversalEnglishGrammaticalRelations.MARKER); if (marker != null && marker.lemma().equals("as")) { return 1; } } } // look at the path to root List<IndexedWord> path = dependency.getPathToRoot(headIndexedWord); if(path == null) return 0; boolean isSubject = false; // if the node itself is a subject, we will not take into account its parent in the path if(dependency.hasParentWithReln(headIndexedWord, UniversalEnglishGrammaticalRelations.NOMINAL_SUBJECT)) isSubject = true; for (IndexedWord word : path) { if(!isSubject && (dict.reportVerb.contains(word.lemma()) || dict.reportNoun.contains(word.lemma()))) { return 1; } // check how to put isSubject isSubject = dependency.hasParentWithReln(word, UniversalEnglishGrammaticalRelations.NOMINAL_SUBJECT); } return 0; }