Java Code Examples for edu.stanford.nlp.trees.Tree#value()

The following examples show how to use edu.stanford.nlp.trees.Tree#value() . 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: TreePrinter.java    From UDepLambda with Apache License 2.0 6 votes vote down vote up
static StringBuilder toStringBuilder(Tree tree, StringBuilder sb, 
  boolean printOnlyLabelValue, String offset) {
  if (tree.isLeaf()) {
    if (tree.label() != null) sb.append(printOnlyLabelValue ? tree.label().value() : tree.label());
    return sb;
  } 
  sb.append('(');
  if (tree.label() != null) {
  	if (printOnlyLabelValue) {
  		if (tree.value() != null) sb.append(tree.label().value());
  		// don't print a null, just nothing!
  	} else {
  		sb.append(tree.label());
  	}
  }
  Tree[] kids = tree.children();
  if (kids != null) {
  	for (Tree kid : kids) {
  		if (kid.isLeaf()) sb.append(' '); 
  		else sb.append('\n').append(offset).append(' ');
  		toStringBuilder(kid, sb, printOnlyLabelValue,offset + "  ");
  	}
  }
  return sb.append(')');
}
 
Example 2
Source File: ClueType.java    From uncc2014watsonsim with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A very simple LAT detector. It wants the lowest subtree with both a determiner and a noun
 */
private static Analysis detectPart(Tree t) {
	switch (t.value()) {
	case "WDT":
	case "DT": return new Analysis(t, null);
	case "NN":
	case "NNS": return new Analysis(null, t);
	default:
		Analysis l = new Analysis((Tree) null, null);
		// The last noun tends to be the most general
		List<Tree> kids = t.getChildrenAsList();
		Collections.reverse(kids);
		for (Tree kid : kids)
			l = merge(l, detectPart(kid));
		return l;
	}
	
}