## 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 a `edu.stanford.nlp.trees.Tree` as the output of the parser. This class supports printing in multiple ways and altering behavior via properties.

Author:
  Roger Levy, Christopher Manning, Galen Andrew

Field Summary
`static String` `headMark`
`static String[]` `outputTreeFormats` The legal output tree formats.
`static String` `rootLabelOnlyFormat`

Constructor Summary
`TreePrint(String formats)` The anglocentric constructor.
`TreePrint(String formats, String options)`
`TreePrint(String formats, String options, TreebankLanguagePack tlp)`
`TreePrint(String formatString, String optionsString, TreebankLanguagePack tlp, HeadFinder hf)` Make a TreePrint instance.
`TreePrint(String formats, TreebankLanguagePack tlp)`

Method Summary
`HeadFinder` `getHeadFinder()`
`PrintWriter` `getPrintWriter()`
`static void` `main(String[] args)` This provides a simple main method for calling TreePrint.
`Tree` `markHeadNodes(Tree t)`
`static void` `print(Collection<TypedDependency> dependencies, PrintWriter pw)` USED BY TREEPRINT AND WSD.SUPWSD.PREPROCESS Prints this set of typed dependencies to the specified `PrintWriter`.
`static void` `print(Collection<TypedDependency> dependencies, String format, PrintWriter pw)` USED BY TREEPRINT Prints this set of typed dependencies to the specified `PrintWriter` in the specified format.
`void` `printFooter(PrintWriter pw)`
`void` `printHeader(PrintWriter pw, String charset)`
`void` `printTree(Tree t)` Prints the tree to the default PrintWriter.
`void` `printTree(Tree t, PrintWriter pw)` Prints the tree, with an empty ID.
`void` `printTree(Tree t, String id, PrintWriter pw)` Prints the tree according to the options specified for this instance.
`void` `printTrees(List<ScoredObject<Tree>> trees, String id, PrintWriter pw)` Prints the trees according to the options specified for this instance.
`void` `setHeadFinder(HeadFinder hf)` Set the headfinder to be used for lexicalizing trees.
`void` `setPrintWriter(PrintWriter pw)` Sets the default print writer for printing trees with the instance.
`void` `setStem(boolean stem)` Sets whether or not to stem the Trees using Morphology.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### rootLabelOnlyFormat

    public static final String rootLabelOnlyFormat

See Also:
  Constant Field Values

### outputTreeFormats

    public static final String[] outputTreeFormats

  The legal output tree formats.

### headMark

    public static final String headMark

See Also:
  Constant Field Values

Constructor Detail

### TreePrint

    public TreePrint(String formats)

  The anglocentric constructor. Should work for English only.

  Parameters:
    `formats` - The formats to print the tree in.

### TreePrint

    public TreePrint(String formats,
                     TreebankLanguagePack tlp)

### TreePrint

    public TreePrint(String formats,
                     String options)

### TreePrint

    public TreePrint(String formats,
                     String options,
                     TreebankLanguagePack tlp)

### TreePrint

    public TreePrint(String formatString,
                     String optionsString,
                     TreebankLanguagePack tlp,
                     HeadFinder hf)

  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, words, wordsAndTags, rootSymbolOnly, dependencies, typedDependencies, typedDependenciesCollapsed, collocations, semanticGraph. All of them print a blank line after the output except for oneline. oneline is also not meaningul in XML output (it is ignored: use penn instead).
    `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` .
    `tlp` - The TreebankLanguagePack used to do things like delete or ignore punctuation in output
    `hf` - 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 display
    `pw` - 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 tree `t` is `null`, then the code prints a line indicating a skipped tree. Under the XML option this is an `s` element with the `skipped` attribute having value `true`, and, otherwise, it is the token `SENTENCE_SKIPPED_OR_UNPARSABLE`.

  Parameters:
    `t` - The tree to display
    `id` - A name for this sentence
    `pw` - Where to dislay 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 tree `t` is `null`, then the code prints a line indicating a skipped tree. Under the XML option this is an `s` element with the `skipped` attribute having value `true`, and, otherwise, it is the token `SENTENCE_SKIPPED_OR_UNPARSABLE`.

  Parameters:
    `trees` - The list of trees to display
    `id` - A name for this sentence
    `pw` - Where to dislay the tree

### printHeader

    public void printHeader(PrintWriter pw,
                            String charset)

### printFooter

    public void printFooter(PrintWriter pw)

### setStem

    public void setStem(boolean stem)

  Sets whether or not to stem the Trees using Morphology. This option is currently only for English.

  Parameters:
    `stem` - Whether to stem each word

### setHeadFinder

    public final void setHeadFinder(HeadFinder hf)

  Set the headfinder to be used for lexicalizing trees. Relevant if the output is to be lexicalized. By default, `ModCollinsHeadFinder` is used.

  Parameters:
    `hf` - The HeadFinder to use

### getHeadFinder

    public final HeadFinder getHeadFinder()

### setPrintWriter

    public void setPrintWriter(PrintWriter pw)

  Sets the default print writer for printing trees with the instance. Unless this is set, the default is `System.out`.

  Parameters:
    `pw` - The PrintWriter to use for output by default

### getPrintWriter

    public PrintWriter getPrintWriter()

### markHeadNodes

    public Tree markHeadNodes(Tree t)

### main

    public static void main(String[] args)

  This provides a simple main method for calling TreePrint. Flags supported are:
  1. -format format (like -outputFormat of parser, default "penn")
  2. -options options (like -outputFormatOptions of parser, default "")
  3. -tLP class (the TreebankLanguagePack, default "edu.stanford.nlp.tree.PennTreebankLanguagePack")
  4. -hf class (the HeadFinder, default, the one in the class specified by -tLP)
  5. -useTLPTreeReader (use the treeReaderFactory() inside the -tLP class; otherwise a PennTreeReader with no normalization is used)
  The single argument should be a file containing Trees in the format that is either Penn Treebank s-expressions or as specified by -useTLPTreeReader and the -tLP class, or if there is no such argument, trees are read from stdin and the program runs as a filter.

  Parameters:
    `args` - Command line arguments, as above.

### print

    public static void print(Collection<TypedDependency> dependencies,
                             PrintWriter pw)

  USED BY TREEPRINT AND WSD.SUPWSD.PREPROCESS Prints this set of typed dependencies to the specified `PrintWriter`.

  Parameters:
    `dependencies` - The collection of TypedDependency to print
    `pw` - Where to print them

### print

    public static void print(Collection<TypedDependency> dependencies,
                             String format,
                             PrintWriter pw)

  USED BY TREEPRINT Prints this set of typed dependencies to the specified `PrintWriter` in the specified format.

  Parameters:
    `dependencies` - The collection of TypedDependency to print
    `format` - Where "xml" or "readable" or other
    `pw` - Where to print them

Stanford NLP Group