|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.stanford.nlp.ie.pcfg.TreeUtil
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 |
public static final String startSymbol
Constructor Detail |
public TreeUtil()
Method Detail |
public static void WriteTree(Tree t, String fn) throws IOException
IOException
public static Tree ReadTree(String fn) throws IOException
IOException
public static void WriteTrees(List trees, String fn) throws IOException
IOException
public static List ReadTrees(String fn) throws IOException
IOException
public static void PrintTreeSentences(List trees)
public static void CopyTags(Tree fromTree, Tree toTree)
XLabel
public static XTagSet GetTagSet(Tree tree)
XLabel
public static ArrayList GetSentence(Tree tree)
XLabel
public static String GetSentenceAsString(Tree tree, boolean includeHead, boolean includeTags)
XLabel
public static String GetSentenceAsString(Tree tree)
XLabel
public static Tree GetLeaf(Tree tree, int i)
public static List GetPOSList(Tree tree)
public static void CleanLabels(Tree tree)
public static void SetLabels(Tree tree)
XLabel
public static void PerkUp(Tree tree, int i, String label)
XLabel
public static Tree AddTop(Tree tree)
XLabel
public static boolean ParentOfLeaf(Tree tree)
public static void CleanTop(Tree tree)
XLabel
public static void CleanLeaves(Tree tree)
public static void SetLeaves(Tree tree)
XLabel
public static void Number(Tree tree)
public static Tree GetNumberedCopy(Tree tree)
Number
,
XLabel
public static XRule GetRule(Tree tree)
XRule
public static List GetRules(Tree tree, boolean isLex)
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 layerXRule
public static List GetRules(Tree tree)
public static List GetRules(List trees, boolean isLex)
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 layerXRule
public static List GetRules(List trees)
XRule
public static Tree GetCopy(Tree tree)
public static void DoSlyTricks(Tree tree)
public static Tree GetHeadedCopy(Tree tree)
public static void Clean(Tree tree, boolean includeTags, boolean includeHead)
includeTags
- true if you don't want to remove tag informationincludeHead
- true if you don't want to remove head informationpublic static void main(String[] args) throws Exception
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |