edu.stanford.nlp.ie.pcfg
Class TreeUtil

java.lang.Object
  |
  +--edu.stanford.nlp.ie.pcfg.TreeUtil

public class TreeUtil
extends Object

This class contains many utility functions for performing common tree operations. It's very possible that much of this functionality overlaps with that provided by existing JavaNLP code.


Field Summary
static String startSymbol
          this symbol marks the top of a tree.
 
Constructor Summary
TreeUtil()
           
 
Method Summary
static Tree AddTop(Tree tree)
          Adds a new node (with label == startSymbol) to the root of the tree.
static void Clean(Tree tree, boolean includeTags, boolean includeHead)
          Removes tag and head information from all labels in a tree.
static void CleanLabels(Tree tree)
          Strips tag information from all labels in a tree Use Clean(Tree tree, boolean includeTags, boolean includeHead) instead!
static void CleanLeaves(Tree tree)
          Removes tag information from all the nodes in a tree
static void CleanTop(Tree tree)
          Removes tag information from the top node in a tree.
static void CopyTags(Tree fromTree, Tree toTree)
          copy label tags from fromTree to toTree.
static void DoSlyTricks(Tree tree)
           
static Tree GetCopy(Tree tree)
          Makes a deep copy.
static Tree GetHeadedCopy(Tree tree)
          Gets a copy of tree, including some lexical head information.
static Tree GetLeaf(Tree tree, int i)
          Gets the ith leaf.
static Tree GetNumberedCopy(Tree tree)
          Gets a copy of a tree, with labels replaced by numbers
static List GetPOSList(Tree tree)
          Gets a list of the POS of all leaves in a tree
static XRule GetRule(Tree tree)
          Given a tree with only two nodes (parent and child), returns an XRule that describes the generation "parent -> child".
static List GetRules(List trees)
          Gets a list of all the rules (XRules) needed to generate a list of trees.
static List GetRules(List trees, boolean isLex)
          Gets a list of all the rules (XRules) needed to generate a list of trees.
static List GetRules(Tree tree)
          Gets a list of all the rules (XRules) needed to generate a given tree.
static List GetRules(Tree tree, boolean isLex)
          Gets a list of all the rules (XRules) needed to generate a given tree.
static ArrayList GetSentence(Tree tree)
          Gets the sentence represented by a tree (as a list of XLabels).
static String GetSentenceAsString(Tree tree)
          Gets the sentence represented by a tree (as a string).
static String GetSentenceAsString(Tree tree, boolean includeHead, boolean includeTags)
          Gets the sentence represented by a tree (as a string).
static XTagSet GetTagSet(Tree tree)
          Returns a set of all the tags in the tree.
static void main(String[] args)
           
static void Number(Tree tree)
          Replaces tree node labels with numbers.
static boolean ParentOfLeaf(Tree tree)
          Returns true if the tree has only one child (a leaf), false otherwise.
static void PerkUp(Tree tree, int i, String label)
          "Perculates" tag info from leaves up through the root
static void PrintTreeSentences(List trees)
          prints a list of trees as sentences see GetSentenceAsString
static Tree ReadTree(String fn)
          reads a single tree from a file
static List ReadTrees(String fn)
          reads a list of trees from a file
static void SetLabels(Tree tree)
          Converts tree labels from strings to XLabel.toString().
static void SetLeaves(Tree tree)
          Copies tag information from ParentOfLeaves to leaves.
static void WriteTree(Tree t, String fn)
          writes a single tree to a file
static void WriteTrees(List trees, String fn)
          writes a list of trees to a file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startSymbol

public static final String startSymbol
this symbol marks the top of a tree.

See Also:
Constant Field Values
Constructor Detail

TreeUtil

public TreeUtil()
Method Detail

WriteTree

public static void WriteTree(Tree t,
                             String fn)
                      throws IOException
writes a single tree to a file

IOException

ReadTree

public static Tree ReadTree(String fn)
                     throws IOException
reads a single tree from a file

IOException

WriteTrees

public static void WriteTrees(List trees,
                              String fn)
                       throws IOException
writes a list of trees to a file

IOException

ReadTrees

public static List ReadTrees(String fn)
                      throws IOException
reads a list of trees from a file

IOException

PrintTreeSentences

public static void PrintTreeSentences(List trees)
prints a list of trees as sentences see GetSentenceAsString


CopyTags

public static void CopyTags(Tree fromTree,
                            Tree toTree)
copy label tags from fromTree to toTree.

See Also:
XLabel

GetTagSet

public static XTagSet GetTagSet(Tree tree)
Returns a set of all the tags in the tree. The union of each leaf's tags

See Also:
XLabel

GetSentence

public static ArrayList GetSentence(Tree tree)
Gets the sentence represented by a tree (as a list of XLabels).

See Also:
XLabel

GetSentenceAsString

public static String GetSentenceAsString(Tree tree,
                                         boolean includeHead,
                                         boolean includeTags)
Gets the sentence represented by a tree (as a string). Converts each XLabel leaf into a string using parameters includeHead, includeTags

See Also:
XLabel

GetSentenceAsString

public static String GetSentenceAsString(Tree tree)
Gets the sentence represented by a tree (as a string). Includes all head and tag information from leaf XLabels

See Also:
XLabel

GetLeaf

public static Tree GetLeaf(Tree tree,
                           int i)
Gets the ith leaf.


GetPOSList

public static List GetPOSList(Tree tree)
Gets a list of the POS of all leaves in a tree


CleanLabels

public static void CleanLabels(Tree tree)
Strips tag information from all labels in a tree Use Clean(Tree tree, boolean includeTags, boolean includeHead) instead!


SetLabels

public static void SetLabels(Tree tree)
Converts tree labels from strings to XLabel.toString(). Depending on the current XLabel implementation, this may or may not insert brackets after each label

See Also:
XLabel

PerkUp

public static void PerkUp(Tree tree,
                          int i,
                          String label)
"Perculates" tag info from leaves up through the root

See Also:
XLabel

AddTop

public static Tree AddTop(Tree tree)
Adds a new node (with label == startSymbol) to the root of the tree. see startSymbol

See Also:
XLabel

ParentOfLeaf

public static boolean ParentOfLeaf(Tree tree)
Returns true if the tree has only one child (a leaf), false otherwise.


CleanTop

public static void CleanTop(Tree tree)
Removes tag information from the top node in a tree.

See Also:
XLabel

CleanLeaves

public static void CleanLeaves(Tree tree)
Removes tag information from all the nodes in a tree


SetLeaves

public static void SetLeaves(Tree tree)
Copies tag information from ParentOfLeaves to leaves.

See Also:
XLabel

Number

public static void Number(Tree tree)
Replaces tree node labels with numbers. Assigns a unique number to each node depth-first.


GetNumberedCopy

public static Tree GetNumberedCopy(Tree tree)
Gets a copy of a tree, with labels replaced by numbers

See Also:
Number, XLabel

GetRule

public static XRule GetRule(Tree tree)
Given a tree with only two nodes (parent and child), returns an XRule that describes the generation "parent -> child". This XRule has a default probability of 1.

See Also:
XRule

GetRules

public static List GetRules(Tree tree,
                            boolean isLex)
Gets a list of all the rules (XRules) needed to generate a given tree. Each rule has a probability of 1.

Parameters:
isLex - if true, returns only those rules used to generate the bottom layer of the tree (ParentOfChild -> Child). if false returns all rules used to generate tree except those in the bottom layer
See Also:
XRule

GetRules

public static List GetRules(Tree tree)
Gets a list of all the rules (XRules) needed to generate a given tree.


GetRules

public static List GetRules(List trees,
                            boolean isLex)
Gets a list of all the rules (XRules) needed to generate a list of trees.

Parameters:
isLex - if true, returns only those rules used to generate the bottom layer of the tree (ParentOfChild -> Child). if false returns all rules used to generate tree except those in the bottom layer
See Also:
XRule

GetRules

public static List GetRules(List trees)
Gets a list of all the rules (XRules) needed to generate a list of trees.

See Also:
XRule

GetCopy

public static Tree GetCopy(Tree tree)
Makes a deep copy. Creates new Labels as LabeledScoredTreeLeaf or LabeledScoredTreeNode


DoSlyTricks

public static void DoSlyTricks(Tree tree)

GetHeadedCopy

public static Tree GetHeadedCopy(Tree tree)
Gets a copy of tree, including some lexical head information. Currently returns head information for VPs but no other nodes.


Clean

public static void Clean(Tree tree,
                         boolean includeTags,
                         boolean includeHead)
Removes tag and head information from all labels in a tree.

Parameters:
includeTags - true if you don't want to remove tag information
includeHead - true if you don't want to remove head information

main

public static void main(String[] args)
                 throws Exception
Exception


Stanford NLP Group