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
public static final boolean isAdjectivePhrase(final Tree treeNode) { return treeNode.value().equalsIgnoreCase("ADJP"); }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
public static final boolean isAdVerbPhrase(final Tree treeNode) { return treeNode.value().equalsIgnoreCase("ADVP"); }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
public static final boolean isPrepositionPhrase(final Tree treeNode) { return treeNode.value().equalsIgnoreCase("PP"); }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
public static final boolean isAttribForNoun(final Tree treeNode) { return treeNode.value().equalsIgnoreCase("PRP$") || treeNode.value().equalsIgnoreCase("POS") || treeNode.value().equalsIgnoreCase("JJ") || treeNode.value().equalsIgnoreCase("CD") || treeNode.value().equalsIgnoreCase("QP") || treeNode.value().equalsIgnoreCase("IN") || treeNode.value().equalsIgnoreCase("RB"); }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
public static final boolean isAttribForNounPhrase(final Tree treeNode) { return treeNode.value().equalsIgnoreCase("ADJP") || treeNode.value().equalsIgnoreCase("NP"); }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
public static final boolean isAttribForVerb(final Tree treeNode) { return treeNode.value().equalsIgnoreCase("RB"); }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static void getTriplets(final Tree sentence, List<Tree> leaves) { Comparator<KeyValue<Integer, Entity>> cmp = new Comparator<KeyValue<Integer, Entity>>() { public int compare(KeyValue<Integer, Entity> o1, KeyValue<Integer, Entity> o2) { return o1.getValue().compareTo(o2.getValue()); }//from ww w.j a va2s.co m }; deepestSentence = null; dependancy = ""; toDependancy = ""; e = null; deepestVerbPhrase = null; dependancyDepth = 0; depthOfSentence = -10; childNumberOfDeepestSenctence = -1; getDeepestSentence(sentence, 0); if (deepestSentence != null) { tmpTriplets = new ArrayList<Triplet>(); Triplet tempTriplet = extractTriplet(deepestSentence, leaves); final Tree ancestor = deepestSentence.ancestor(1, sentence); if (ancestor == null) return; if (childNumberOfDeepestSenctence != -1) { addAttribute(cmp, sentence, deepestSentence); ancestor.removeChild(childNumberOfDeepestSenctence); } if (ancestor.value().equalsIgnoreCase("ROOT")) { return; } else { Tree parentOfSentence = ancestor.ancestor(1, sentence); int clauseIndex = parentOfSentence.indexOf(ancestor); for (int j = clauseIndex - 1; j >= 0; j--) { Tree lastNoun = parentOfSentence.getChild(j); nounFound = false; e = new Entity(); extractLastNoun(lastNoun); tempTriplet.lastNP = e; if (!tempTriplet.lastNP.isEmpty()) if (tempTriplet.subject.isEmpty()) { tempTriplet.subject = e; tempTriplet.subject.attributes = getSubjectAttributes(e.tree.ancestor(1, sentence), true, sentence, e.tree); } if (!tempTriplet.lastNP.isEmpty()) break; } } getTriplets(sentence, leaves); } else { tmpTriplets = new ArrayList<Triplet>(); Triplet tempTriplet = extractTriplet(sentence, leaves); addAttribute(cmp, sentence, sentence); } }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static void addAttribute(Comparator cmp, Tree rootSentence, Tree deepSentence) { List<Tree> leaves = deepSentence.getLeaves(); TIntHashSet intSet = new TIntHashSet(); ArrayList<KeyValue<Integer, Entity>> tripletEntity2Index = new ArrayList<KeyValue<Integer, Entity>>(); for (int i = 0; i < tmpTriplets.size(); i++) { Triplet triplet = tmpTriplets.get(i); if (triplet.subject != null && !triplet.subject.name.trim().equalsIgnoreCase("")) { Entity subject = triplet.subject; subject.attributes.clear();/*from w ww . j av a2 s .c om*/ int value = findIndex(subject.name, leaves); if (!intSet.contains(value)) { KeyValue<Integer, Entity> keyValue = new KeyValue<Integer, Entity>(subject, value); tripletEntity2Index.add(keyValue); intSet.add(value); } } if (triplet.verb != null && !triplet.verb.name.trim().equalsIgnoreCase("")) { Entity verb = triplet.verb; verb.isVerb = true; verb.attributes.clear(); int value = findIndex(verb.name, leaves); if (!intSet.contains(value)) { KeyValue<Integer, Entity> keyValue = new KeyValue<Integer, Entity>(verb, value); tripletEntity2Index.add(keyValue); intSet.add(value); } } if (triplet.object != null && !triplet.object.name.trim().equalsIgnoreCase("")) { Entity object = triplet.object; object.attributes.clear(); int value = findIndex(object.name, leaves); if (!intSet.contains(value)) { KeyValue<Integer, Entity> keyValue = new KeyValue<Integer, Entity>(object, value); tripletEntity2Index.add(keyValue); intSet.add(value); } } } Entity closetVerb = null; if (tripletEntity2Index.size() == 0) return; int EndInterval = 0, StartInterval = -1; for (int i = 0; i < leaves.size(); i++) { final KeyValue<Integer, Entity> keyValue = tripletEntity2Index.get(EndInterval); Entity entity = keyValue.getKey(); if (entity.isVerb) closetVerb = entity; int index = keyValue.getValue(); Tree leaf = leaves.get(i); if (i == index) { StartInterval = index; EndInterval++; if (EndInterval == tripletEntity2Index.size()) { break; } } else if (i > StartInterval && i < index) { Entity attrib = new Entity(leaf.value(), leaf.ancestor(1, rootSentence).value()); if (leaf.ancestor(1, rootSentence).value().equalsIgnoreCase("RP") && closetVerb != null && !closetVerb.isEmpty()) closetVerb.name += " " + leaf; else entity.attributes.add(attrib); } } for (int i = StartInterval + 1; i < leaves.size(); i++) { final KeyValue<Integer, Entity> keyValue = tripletEntity2Index.get(EndInterval - 1); Entity entity = keyValue.getKey(); Tree leaf = leaves.get(i); Entity attrib = new Entity(leaf.value(), leaf.ancestor(1, rootSentence).value()); if (leaf.ancestor(1, rootSentence).value().equalsIgnoreCase("RP") && closetVerb != null && !closetVerb.isEmpty()) closetVerb.name += " " + leaf; else entity.attributes.add(attrib); } }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
private static int findIndex(String entityName, List<Tree> leaves) { for (int i = 0; i < leaves.size(); i++) { Tree tree = leaves.get(i); String currentNodeName = tree.value(); currentNodeName = currentNodeName.trim(); entityName = entityName.trim();/*from w w w . j av a 2 s . com*/ if (currentNodeName.equalsIgnoreCase(entityName)) return i; } return -1; }
From source file:uk.ac.gla.mir.util.TripletExtractor.java
License:Open Source License
public static void extractLastNoun(Tree sentence) { List<Tree> tempList = sentence.getChildrenAsList(); for (int i = tempList.size() - 1; i >= 0; i--) { if (nounFound) break; Tree tempTree = tempList.get(i); if (TripletExtractor.isNoun(tempTree) && tempTree.getChildrenAsList().size() > 0) { e.name = tempTree.getChild(0).toString(); e.tree = tempTree;// ww w . j av a2 s . co m e.type = tempTree.value(); nounFound = true; } else { extractLastNoun(tempTree); } } }