Class 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 specified at construction.
    Author:
    Roger Levy, Christopher Manning, Galen Andrew
    • 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,
                         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 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 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 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
      • printFooter

        public void printFooter​(PrintWriter pw)
      • 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,
                                 boolean includeTags,
                                 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,
                                 boolean includeTags,
                                 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 - "xml" or "readable" or other
        pw - Where to print them