edu.stanford.nlp.trees
Class ParentalTreeWrapper

java.lang.Object
  extended by java.util.AbstractCollection<Tree>
      extended by edu.stanford.nlp.trees.Tree
          extended by edu.stanford.nlp.trees.ParentalTreeWrapper
All Implemented Interfaces:
Label, Labeled, Scored, java.io.Serializable, java.lang.Iterable<Tree>, java.util.Collection<Tree>

public class ParentalTreeWrapper
extends Tree

A wrapper class for a regular tree that looks like a Tree, but adds parent pointers to the nodes. Calls to parent() or parent(root) return the cached parent pointer, and other calls are passed through to the underlying Tree. This is useful in the Tregex system, where it greatly reduces the time spent searching for parent nodes.
TODO: only those calls used by the Tregex system get passed along to the underlying Tree. Other users may want to expand on this.

Author:
John Bauer
See Also:
Serialized Form

Field Summary
 
Fields inherited from class edu.stanford.nlp.trees.Tree
DISPLAY_SCORES, EMPTY_TREE_ARRAY
 
Constructor Summary
ParentalTreeWrapper(Tree tree)
           
ParentalTreeWrapper(Tree tree, Tree parent)
           
 
Method Summary
 Tree[] children()
          Returns an array of children for the current node.
 Tree getBackingTree()
           
 Label label()
          Returns the label associated with the current node, or null if there is no label.
 Tree parent()
          Return the parent of the tree node.
 Tree parent(Tree root)
          Return the parent of the tree node.
 TreeFactory treeFactory()
          Return a TreeFactory that produces trees of the appropriate type.
 java.lang.String value()
          Return a String representation of just the "main" value of this label.
 
Methods inherited from class edu.stanford.nlp.trees.Tree
addChild, addChild, ancestor, cCommands, constituents, constituents, constituents, deepCopy, deepCopy, deepCopy, dependencies, dependencies, dependencies, dependencies, depth, depth, dominates, dominationPath, equals, firstChild, flatten, flatten, getChild, getChildrenAsList, getLeaves, getLeaves, getNodeNumber, getSpan, hashCode, headPreTerminal, headTerminal, headTerminal, indentedListPrint, indentedListPrint, indentedXMLPrint, indentedXMLPrint, indexLeaves, indexOf, indexSpans, indexSpans, indexSpans, insertDtr, isLeaf, isPhrasal, isPrePreTerminal, isPreTerminal, isUnaryRewrite, iterator, joinNode, labeledYield, labeledYield, labelFactory, labels, lastChild, leftCharEdge, localTree, localTrees, mapDependencies, mapDependencies, nodeNumber, nodeString, numChildren, pathNodeToNode, pennPrint, pennPrint, pennPrint, pennString, percolateHeads, postOrderNodeList, preOrderNodeList, preTerminalYield, preTerminalYield, printLocalTree, printLocalTree, prune, prune, removeChild, rightCharEdge, score, setChild, setChildren, setChildren, setFromString, setLabel, setLabels, setScore, setSpans, setValue, siblings, size, skipRoot, spliceOut, spliceOut, subTreeList, subTrees, subTrees, taggedDependencies, taggedDependencies, taggedDependencies, taggedDependencies, taggedLabeledYield, taggedYield, taggedYield, toString, toStringBuilder, toStringBuilder, toStructureDebugString, transform, transform, treeSkeletonCopy, treeSkeletonCopy, upperMostUnary, valueOf, valueOf, yield, yield, yield, yieldHasWord, yieldHasWord, yieldWords, yieldWords
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParentalTreeWrapper

public ParentalTreeWrapper(Tree tree)

ParentalTreeWrapper

public ParentalTreeWrapper(Tree tree,
                           Tree parent)
Method Detail

children

public Tree[] children()
Description copied from class: Tree
Returns an array of children for the current node. If there are no children (if the node is a leaf), this must return a Tree[] array of length 0. A null children() value for tree leaves was previously supported, but no longer is. A caller may assume that either isLeaf() returns true, or this node has a nonzero number of children.

Specified by:
children in class Tree
Returns:
The children of the node
See Also:
Tree.getChildrenAsList()

treeFactory

public TreeFactory treeFactory()
Description copied from class: Tree
Return a TreeFactory that produces trees of the appropriate type.

Specified by:
treeFactory in class Tree
Returns:
A factory to produce Trees

parent

public Tree parent()
Description copied from class: Tree
Return the parent of the tree node. This routine may return null meaning simply that the implementation doesn't know how to determine the parent node, rather than there is no such node.

Overrides:
parent in class Tree
Returns:
The parent Tree node or null
See Also:
Tree.parent(Tree)

parent

public Tree parent(Tree root)
Description copied from class: Tree
Return the parent of the tree node. This routine will traverse a tree (depth first) from the given root, and will correctly find the parent, regardless of whether the concrete class stores parents. It will only return null if this node is the root node, or if this node is not contained within the tree rooted at root.

Overrides:
parent in class Tree
Parameters:
root - The root node of the whole Tree
Returns:
the parent Tree node if any; else null

getBackingTree

public Tree getBackingTree()

label

public Label label()
Description copied from class: Tree
Returns the label associated with the current node, or null if there is no label. The default implementation always returns null.

Specified by:
label in interface Labeled
Overrides:
label in class Tree
Returns:
The label of the node

value

public java.lang.String value()
Description copied from interface: Label
Return a String representation of just the "main" value of this label.

Specified by:
value in interface Label
Overrides:
value in class Tree
Returns:
the "value" of the label


Stanford NLP Group