The TreePrint class provides a simple way to display the tree. An instance of the class is created using a string describing the display format to be used. An array of valid output formats can be obtained using the static outputTreeFormats variable and are listed in the following table:
|
Tree format strings |
|
penn |
dependencies |
collocations |
oneline |
typedDependencies |
semanticGraph |
rootSymbolOnly |
typedDependenciesCollapsed |
conllStyleDependencies |
words |
latexTree |
conll2007 |
wordsAndTags |
xmlTree |
Stanford uses type dependencies to describe the grammatical relationships that exist within a sentence. These are detailed in the Stanford typed dependencies manual (http://nlp.stanford.edu/software/dependencies_manual.pdf).
The following code example illustrates how the TreePrint class can be used. The printTree method performs the actual display operation.
In this case, the TreePrint object is created, showing "typedDependenciesCollapsed":
TreePrint treePrint = new TreePrint("typedDependenciesCollapsed"); treePrint.printTree(parseTree);
The output of this sequence is as follows, where the number reflects its position within the sentence:
det(cow-2, The-1) nsubj(jumped-3, cow-2) root(ROOT-0, jumped-3) det(moon-6, the-5) prep_over(jumped-3, moon-6)
Using the penn string to create the object results in the following output:
(ROOT (S (NP (DT The) (NN cow)) (VP (VBD jumped) (PP (IN over) (NP (DT the) (NN moon)))) (. .)))
The dependencies string produces a simple list of dependencies:
dep(cow-2,The-1) dep(jumped-3,cow-2) dep(null-0,jumped-3,root) dep(jumped-3,over-4) dep(moon-6,the-5) dep(over-4,moon-6)
The formats can be combined using commas. The following example will result in both the penn style and the typedDependenciesCollapsed formats being used for the display:
"penn,typedDependenciesCollapsed"