Package edu.stanford.nlp.trees
Class TreePrint
- java.lang.Object
-
- edu.stanford.nlp.trees.TreePrint
-
public class TreePrint extends Object
A class for customizing the print method(s) for aedu.stanford.nlp.trees.Treeas the output of the parser. This class supports printing in multiple ways and altering behavior via properties specified at construction.- Author:
- Roger Levy, Christopher Manning, Galen Andrew
-
-
Field Summary
Fields Modifier and Type Field Description static StringheadMarkstatic String[]outputTreeFormatsThe legal output tree formats.static StringrootLabelOnlyFormat
-
Constructor Summary
Constructors Constructor Description TreePrint(String formats)Construct a new TreePrint that will print the given formats.TreePrint(String formats, TreebankLanguagePack tlp)Make a TreePrint instance with no options specified.TreePrint(String formats, String options, TreebankLanguagePack tlp)Make a TreePrint instance.TreePrint(String formatString, String optionsString, TreebankLanguagePack tlp, HeadFinder hf, HeadFinder typedDependencyHF)Make a TreePrint instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidmain(String[] args)This provides a simple main method for calling TreePrint.TreemarkHeadNodes(Tree t)static voidprint(Collection<TypedDependency> dependencies, boolean includeTags, PrintWriter pw)USED BY TREEPRINT AND WSD.SUPWSD.PREPROCESS Prints this set of typed dependencies to the specifiedPrintWriter.static voidprint(Collection<TypedDependency> dependencies, String format, boolean includeTags, PrintWriter pw)USED BY TREEPRINT Prints this set of typed dependencies to the specifiedPrintWriterin the specified format.voidprintFooter(PrintWriter pw)voidprintHeader(PrintWriter pw, String charset)voidprintTree(Tree t)Prints the tree to the default PrintWriter.voidprintTree(Tree t, PrintWriter pw)Prints the tree, with an empty ID.voidprintTree(Tree t, String id, PrintWriter pw)Prints the tree according to the options specified for this instance.voidprintTrees(List<ScoredObject<Tree>> trees, String id, PrintWriter pw)Prints the trees according to the options specified for this instance.
-
-
-
Field Detail
-
rootLabelOnlyFormat
public static final String rootLabelOnlyFormat
- See Also:
- Constant Field Values
-
headMark
public static final String headMark
- See Also:
- Constant Field Values
-
outputTreeFormats
public static final String[] outputTreeFormats
The legal output tree formats.
-
-
Constructor Detail
-
TreePrint
public TreePrint(String formats)
Construct a new TreePrint that will print the given formats. Warning! This is the anglocentric constructor. It will work correctly only for English.- Parameters:
formats- The formats to print the tree in.
-
TreePrint
public TreePrint(String formats, TreebankLanguagePack tlp)
Make a TreePrint instance with no options specified.
-
TreePrint
public TreePrint(String formats, String options, TreebankLanguagePack tlp)
Make a TreePrint instance. This one uses the default tlp headFinder.
-
TreePrint
public TreePrint(String formatString, String optionsString, TreebankLanguagePack tlp, HeadFinder hf, HeadFinder typedDependencyHF)
Make a TreePrint instance.- Parameters:
formatString- A comma separated list of ways to print each Tree. For instance, "penn" or "words,typedDependencies". Known formats are: oneline, penn, latexTree, xmlTree, words, wordsAndTags, rootSymbolOnly, dependencies, typedDependencies, typedDependenciesCollapsed, collocations, semanticGraph, conllStyleDependencies, conll2007. The last two are both tab-separated values formats. The latter has a lot more columns filled with underscores. All of them print a blank line after the output except for oneline. oneline is also not meaningful in XML output (it is ignored: use penn instead). (Use of typedDependenciesCollapsed is deprecated. It works but we recommend instead selecting a type of dependencies using the optionsString argument. Note in particular that typedDependenciesCollapsed does not do CC propagation, which we generally recommend.)optionsString- Options that additionally specify how trees are to be printed (for instance, whether stemming should be done). Known options are:stem, lexicalize, markHeadNodes, xml, removeTopBracket, transChinese, includePunctuationDependencies, basicDependencies, treeDependencies, CCPropagatedDependencies, collapsedDependencies, nonCollapsedDependencies, nonCollapsedDependenciesSeparated, includeTags.tlp- The TreebankLanguagePack used to do things like delete or ignore punctuation in outputhf- The HeadFinder used in printing output
-
-
Method Detail
-
printTree
public void printTree(Tree t)
Prints the tree to the default PrintWriter.- Parameters:
t- The tree to display
-
printTree
public void printTree(Tree t, PrintWriter pw)
Prints the tree, with an empty ID.- Parameters:
t- The tree to displaypw- The PrintWriter to print it to
-
printTree
public void printTree(Tree t, String id, PrintWriter pw)
Prints the tree according to the options specified for this instance. If the treetisnull, then the code prints a line indicating a skipped tree. Under the XML option this is anselement with theskippedattribute having valuetrue, and, otherwise, it is the tokenSENTENCE_SKIPPED_OR_UNPARSABLE.- Parameters:
t- The tree to displayid- A name for this sentencepw- Where to display the tree
-
printTrees
public void printTrees(List<ScoredObject<Tree>> trees, String id, PrintWriter pw)
Prints the trees according to the options specified for this instance. If the treetisnull, then the code prints a line indicating a skipped tree. Under the XML option this is anselement with theskippedattribute having valuetrue, and, otherwise, it is the tokenSENTENCE_SKIPPED_OR_UNPARSABLE.- Parameters:
trees- The list of trees to displayid- A name for this sentencepw- Where to dislay the tree
-
printHeader
public void printHeader(PrintWriter pw, String charset)
-
printFooter
public void printFooter(PrintWriter pw)
-
main
public static void main(String[] args)
This provides a simple main method for calling TreePrint. Flags supported are:- -format format (like -outputFormat of parser, default "penn")
- -options options (like -outputFormatOptions of parser, default "")
- -tLP class (the TreebankLanguagePack, default "edu.stanford.nlp.tree.PennTreebankLanguagePack")
- -hf class (the HeadFinder, default, the one in the class specified by -tLP)
- -useTLPTreeReader (use the treeReaderFactory() inside the -tLP class; otherwise a PennTreeReader with no normalization is used)
- Parameters:
args- Command line arguments, as above.
-
print
public static void print(Collection<TypedDependency> dependencies, boolean includeTags, PrintWriter pw)
USED BY TREEPRINT AND WSD.SUPWSD.PREPROCESS Prints this set of typed dependencies to the specifiedPrintWriter.- Parameters:
dependencies- The collection of TypedDependency to printpw- Where to print them
-
print
public static void print(Collection<TypedDependency> dependencies, String format, boolean includeTags, PrintWriter pw)
USED BY TREEPRINT Prints this set of typed dependencies to the specifiedPrintWriterin the specified format.- Parameters:
dependencies- The collection of TypedDependency to printformat- "xml" or "readable" or otherpw- Where to print them
-
-