List of usage examples for edu.stanford.nlp.trees Tree value
@Override
public String value()
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static Entity getSubject(final Tree sentence, final Tree root, boolean tryAdjective) { Entity e = new Entity(); final List<Tree> childList = sentence.getChildrenAsList(); for (int i = 0; i < childList.size(); i++) { final Tree tempTree = childList.get(i); if (isNounPhrase(tempTree) || (tryAdjective && isAdjectivePhrase(tempTree))) { Tree subject = getSubjectNode(tempTree, tryAdjective); if (subject != null && subject.getChildrenAsList().size() > 0) { e.tree = tempTree;/*from ww w. j a va 2 s . co m*/ e.attributes = getSubjectAttributes(tempTree, true, root, subject); e.name = subject.getChild(0).value(); e.type = subject.value(); } } if (isVerbPhrase(tempTree)) break; } return e; }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static List<Entity> getSubjectAttributes(final Tree tempTree, boolean searchUncles, final Tree root, final Tree objectOrSubject) { final ArrayList<Entity> list = new ArrayList<Entity>(); final List<Tree> childList = tempTree.getChildrenAsList(); for (int i = 0; i < childList.size(); i++) { Tree sibling = childList.get(i); if ((isAttribForNoun(sibling) || isNoun(sibling)) && sibling != objectOrSubject) { if (sibling.getChildrenAsList().size() > 0) list.add(new Entity(sibling.getChild(0).value(), sibling.value())); } else if (isAttribForNounPhrase(sibling)) { list.addAll(getSubjectAttributes(sibling, false, root, objectOrSubject)); }//ww w.ja va 2 s . com } if (searchUncles) { Tree parent = tempTree.ancestor(1, root); final List<Tree> childList2 = parent.getChildrenAsList(); for (int i = 0; i < childList2.size(); i++) { Tree uncle = childList2.get(i); if ((isAdjectivePhrase(uncle) || isPrepositionPhrase(uncle) || isNounPhraseAttrib(uncle)) && uncle != tempTree) { List<Entity> tmp = getSubjectAttributes(uncle, false, root, objectOrSubject); list.addAll(tmp); } } } return list; }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static List<Entity> getVerbAttributes(final Tree tempTree, final boolean searchUncles, final Tree root, final Tree verb) { final ArrayList<Entity> list = new ArrayList<Entity>(); final List<Tree> childList = tempTree.getChildrenAsList(); for (int i = 0; i < childList.size(); i++) { Tree sibling = childList.get(i); if (isAttribForVerb(sibling)) { if (sibling.getChildrenAsList().size() > 0) list.add(new Entity(sibling.getChild(0).value(), sibling.value())); } else if (sibling.value().equalsIgnoreCase("ADVP") || sibling.value().equalsIgnoreCase("PRT")) { List<Tree> tmp = sibling.getChildrenAsList(); for (int j = 0; j < tmp.size(); j++) { Tree tr = tmp.get(j);//from w ww. j a v a2s. co m if (tr.getChildrenAsList().size() > 0) list.add(new Entity(tr.getChild(0).value(), tr.value())); } } } if (searchUncles) { Tree parent = tempTree.ancestor(1, root); final List<Tree> childList2 = parent.getChildrenAsList(); for (int i = 0; i < childList2.size(); i++) { Tree uncle = childList2.get(i); if ((isVerb(uncle) || uncle.value().equalsIgnoreCase("RB") || uncle.value().equalsIgnoreCase("MD")) && uncle != verb) { if (uncle.getChildrenAsList().size() > 0) list.add(new Entity(uncle.getChild(0).value(), uncle.value())); } if (isAdjectivePhrase(uncle) || isAdVerbPhrase(uncle)) { list.addAll(getVerbAttributes(uncle, false, root, verb)); } } } return list; }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static Entity getObject(final Tree sentence, final Tree root, final Tree subjectTree) { Entity e = new Entity(); if (sentence == null) return e; final List<Tree> childList = sentence.getChildrenAsList(); for (int i = 0; i < childList.size(); i++) { final Tree tempTree = childList.get(i); if ((isNounPhrase(tempTree) || isPrepositionPhrase(tempTree)) && tempTree != subjectTree) { Tree object = getSubjectNode(tempTree, false); if (object != null && object.getChildrenAsList().size() > 0) { e.type = object.value(); e.attributes = getSubjectAttributes(tempTree, true, root, object); e.name = object.getChild(0).value(); e.tree = object;//from ww w . java 2 s . c o m } } else if (isAdjectivePhrase(tempTree) && tempTree != subjectTree) { Tree object = getAdjectiveNode(tempTree); if (object != null && object.getChildrenAsList().size() > 0) { e.attributes = getSubjectAttributes(tempTree, true, root, object); e.name = object.getChild(0).value(); e.type = object.value(); e.tree = object; } } if (!e.name.trim().equalsIgnoreCase("")) { break; } } return e; }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static Tree getSubjectNode(Tree tempTree, boolean tryAdj) { final List<Tree> childList = tempTree.getChildrenAsList(); Tree subject = null;//from ww w.ja v a 2 s . co m for (int i = 0; i < childList.size(); i++) { if (subject != null) break; final Tree child = childList.get(i); if (isNoun(child) || child.value().equalsIgnoreCase("VBG") || (tryAdj && isAdjective(child))) { subject = child; } else { Tree tmp = getSubjectNode(child, tryAdj); if (tmp != null) { subject = tmp; } } } return subject; }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static Entity getVerb(final Tree sentence, final Tree root, final boolean checkWordNet) { Entity e = new Entity(); verbDepth = 0;/*www . java 2 s . c o m*/ deepestVerbPhrase = sentence; Tree verb = getDeepestVerb(sentence, 0, checkWordNet); if (verb != null && verb.getChildrenAsList().size() > 0) { List<Entity> attribs = getVerbAttributes(deepestVerbPhrase, true, root, verb); e.attributes = attribs; e.type = verb.value(); e.name = verb.getChild(0).value(); e.tree = verb; e.treeParent = sentence; } return e; }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static Tree getDeepestVerb(Tree tempTree, int depth, boolean checkwordNet) { Tree verb = null;/* w w w . j a v a 2 s. co m*/ final List<Tree> childList = tempTree.getChildrenAsList(); for (int i = 0; i < childList.size(); i++) { final Tree child = childList.get(i); String word = child.getChildrenAsList().size() > 0 ? child.getChild(0).value() : ""; if ((isVerb(child) || checkwordNet) && depth >= verbDepth) { deepestVerbPhrase = tempTree; verbDepth = depth; verb = child; } else { if (!isNounPhrase(child) && !child.value().equalsIgnoreCase("ADVP") && !child.value().equalsIgnoreCase("PRT")) { Tree tmp = getDeepestVerb(child, depth + 1, checkwordNet); if (tmp != null) verb = tmp; } } } return verb; }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static boolean isNoToDependencies(Tree t) { if (t.value().equalsIgnoreCase("WP") || t.value().equalsIgnoreCase("WDT") || t.toString().equalsIgnoreCase("that")) { return true; }//from ww w. jav a 2s.c o m return false; }