edu.stanford.nlp.trees
Class TreePrint

java.lang.Object
  extended by 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, 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)
          utility code...
 Tree markHeadNodes(Tree t)
           
static void print(Collection<TypedDependency> dependencies, PrintWriter pw)
          USED BY TREEPRINT AND 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 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.
static String toString(Collection<TypedDependency> dependencies)
          NO OUTSIDE USE Returns a String representation of this set of typed dependencies as exemplified by the following:
static String toString(Collection<TypedDependency> dependencies, String format)
          NO OUTSIDE USE Returns a String representation of the result of this set of typed dependencies in a user-specified format.
 
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


TreePrint

public TreePrint(String formats,
                 TreebankLanguagePack tlp)

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. Known formats are: oneline, penn, latexTree, words, wordsAndTags, rootSymbolOnly, dependencies, typedDependencies, typedDependenciesCollapsed, collocations. 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 .
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.


printTree

public void printTree(Tree t,
                      PrintWriter pw)
Prints the tree, with an empty ID.


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:
id - A name for this sentence.

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.


setHeadFinder

public void setHeadFinder(HeadFinder hf)
Set the headfinder to be used for lexicalizing trees. Relevant if the output is to be lexicalized. By default, CollinsHeadFinder is used.


getHeadFinder

public 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.


getPrintWriter

public PrintWriter getPrintWriter()

markHeadNodes

public Tree markHeadNodes(Tree t)

main

public static void main(String[] args)
utility code...


toString

public static String toString(Collection<TypedDependency> dependencies,
                              String format)
NO OUTSIDE USE Returns a String representation of the result of this set of typed dependencies in a user-specified format. Currently, three formats are supported:
"plain"
(Default.) Formats the dependencies as logical relations, as exemplified by the following:
  nsubj(died-1, Sam-0)
  tmod(died-1, today-2)
  
"readable"
Formats the dependencies as a table with columns dependent, relation, and governor, as exemplified by the following:
  Sam-0               nsubj               died-1
  today-2             tmod                died-1
  
"xml"
Formats the dependencies as XML, as exemplified by the following:
  <dependencies>
    <dep type="nsubj">
      <governor idx="1">died</governor>
      <dependent idx="0">Sam</dependent>
    </dep>
    <dep type="tmod">
      <governor idx="1">died</governor>
      <dependent idx="2">today</dependent>
    </dep>
  </dependencies>
  

Parameters:
format - a String specifying the desired format
Returns:
a String representation of the typed dependencies in this GrammaticalStructure

toString

public static String toString(Collection<TypedDependency> dependencies)
NO OUTSIDE USE Returns a String representation of this set of typed dependencies as exemplified by the following:
  tmod(died-6, today-9)
  nsubj(died-6, Sam-3)
  

Returns:
a String representation of this set of typed dependencies

print

public static void print(Collection<TypedDependency> dependencies,
                         PrintWriter pw)
USED BY TREEPRINT AND PREPROCESS Prints this set of typed dependencies to the specified PrintWriter.


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.



Stanford NLP Group