edu.stanford.nlp.trees
Class Trees

java.lang.Object
  extended by edu.stanford.nlp.trees.Trees

public class Trees
extends Object

Various utilities for the Tree class.

Author:
Roger Levy, Dan Klein

Constructor Summary
Trees()
           
 
Method Summary
static Tree applyToProjections(TreeVisitor v, Tree head, Tree root, HeadFinder hf)
           
static Tree getPreTerminal(Tree tree, int n)
          gets the nth preterminal in tree.
static Tree getTerminal(Tree tree, int n)
          gets the nth terminal in tree.
static boolean heads(Tree head, Tree node, HeadFinder hf)
          returns true iff head (transitively) heads node
static List<Label> leafLabels(Tree t)
          returns the labels of the leaves in a Tree in the order that they're found.
static List<Tree> leaves(Tree t)
          returns the leaves in a Tree in the order that they're found.
static int leftEdge(Tree t, Tree root)
          Returns the positional index of the left edge of a tree t within a given root, as defined by the size of the yield of all material preceding t.
static Tree lexicalize(Tree t, HeadFinder hf)
          Returns a lexicalized Tree whose Labels are CategoryWordTag instances, all corresponds to the input tree.
static List<String> localTreeAsCatList(Tree t)
          returns the syntactic category of the tree as a list of the syntactic categories of the mother and the daughters
static void main(String[] args)
           
static Tree maximalProjection(Tree head, Tree root, HeadFinder hf)
          returns the maximal projection of head in root given a HeadFinder
static Tree normalizeTree(Tree tree, TreeNormalizer tn, TreeFactory tf)
           
static int objectEqualityIndexOf(Tree parent, Tree daughter)
          Returns the index of daughter in parent by ==.
static int rightEdge(Tree t, Tree root)
          Returns the positional index of the right edge of a tree t within a given root, as defined by the size of the yield of all material preceding t plus all the material contained in t.
static List<CoreLabel> taggedLeafLabels(Tree t)
          returns the labels of the leaves in a Tree, augmented with POS tags.
static String toDebugStructureString(Tree t)
          Return information about the objects in this Tree.
static Tree toFlatTree(Sentence<?> s)
          Turns a sentence into a flat phrasal tree.
static Tree toFlatTree(Sentence<?> s, LabelFactory lf)
          Turns a sentence into a flat phrasal tree.
static String treeToLatex(Tree t)
           
static String treeToLatexEven(Tree t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Trees

public Trees()
Method Detail

leftEdge

public static int leftEdge(Tree t,
                           Tree root)
Returns the positional index of the left edge of a tree t within a given root, as defined by the size of the yield of all material preceding t.


rightEdge

public static int rightEdge(Tree t,
                            Tree root)
Returns the positional index of the right edge of a tree t within a given root, as defined by the size of the yield of all material preceding t plus all the material contained in t.


lexicalize

public static Tree lexicalize(Tree t,
                              HeadFinder hf)
Returns a lexicalized Tree whose Labels are CategoryWordTag instances, all corresponds to the input tree.


leaves

public static List<Tree> leaves(Tree t)
returns the leaves in a Tree in the order that they're found.


leafLabels

public static List<Label> leafLabels(Tree t)
returns the labels of the leaves in a Tree in the order that they're found.


taggedLeafLabels

public static List<CoreLabel> taggedLeafLabels(Tree t)
returns the labels of the leaves in a Tree, augmented with POS tags. assumes that the labels are CoreLabels.


heads

public static boolean heads(Tree head,
                            Tree node,
                            HeadFinder hf)
returns true iff head (transitively) heads node


maximalProjection

public static Tree maximalProjection(Tree head,
                                     Tree root,
                                     HeadFinder hf)
returns the maximal projection of head in root given a HeadFinder


applyToProjections

public static Tree applyToProjections(TreeVisitor v,
                                      Tree head,
                                      Tree root,
                                      HeadFinder hf)

getTerminal

public static Tree getTerminal(Tree tree,
                               int n)
gets the nth terminal in tree. The first terminal is number zero.


getPreTerminal

public static Tree getPreTerminal(Tree tree,
                                  int n)
gets the nth preterminal in tree. The first terminal is number zero.


localTreeAsCatList

public static List<String> localTreeAsCatList(Tree t)
returns the syntactic category of the tree as a list of the syntactic categories of the mother and the daughters


objectEqualityIndexOf

public static int objectEqualityIndexOf(Tree parent,
                                        Tree daughter)
Returns the index of daughter in parent by ==. Returns -1 if daughter not found.


toDebugStructureString

public static String toDebugStructureString(Tree t)
Return information about the objects in this Tree.

Parameters:
t - The tree to examine.
Returns:
A human-readable String

toFlatTree

public static Tree toFlatTree(Sentence<?> s)
Turns a sentence into a flat phrasal tree. The structure is S -> tag*. And then each tag goes to a word. The tag is either found from the label or made "WD". The tag and phrasal node have a StringLabel.

Parameters:
s - The Sentence to make the Tree from
Returns:
The one phrasal level Tree

toFlatTree

public static Tree toFlatTree(Sentence<?> s,
                              LabelFactory lf)
Turns a sentence into a flat phrasal tree. The structure is S -> tag*. And then each tag goes to a word. The tag is either found from the label or made "WD". The tag and phrasal node have a StringLabel.

Parameters:
s - The Sentence to make the Tree from
lf - The LabelFactory with which to create the new Tree labels
Returns:
The one phrasal level Tree

treeToLatex

public static String treeToLatex(Tree t)

treeToLatexEven

public static String treeToLatexEven(Tree t)

main

public static void main(String[] args)
                 throws IOException
Throws:
IOException

normalizeTree

public static Tree normalizeTree(Tree tree,
                                 TreeNormalizer tn,
                                 TreeFactory tf)


Stanford NLP Group