## edu.stanford.nlp.trees
Class Tree

    java.lang.Object
      java.util.AbstractCollection<Tree>
          edu.stanford.nlp.trees.Tree

All Implemented Interfaces:
  Label, Labeled, Scored, Serializable, Iterable<Tree>, Collection<Tree>

Direct Known Subclasses:
  LabeledScoredTreeNode, SimpleTree, TreeGraphNode

    public abstract class Tree

extends AbstractCollection<Tree>
implements Label, Labeled, Scored, Serializable

The abstract class `Tree` is used to collect all of the tree types, and acts as a generic extendable type. This is the standard implementation of inheritance-based polymorphism. All `Tree` objects support accessors for their children (a `Tree[]`), their label (a `Label`), and their score (a `double`). However, different concrete implementations may or may not include the latter two, in which case a default value is returned. The class Tree defines no data fields. The two abstract methods that must be implemented are: `children()`, and `treeFactory()`. Notes that `setChildren(Tree[])` is now an optional operation, whereas it was previously required to be implemented. There is now support for finding the parent of a tree. This may be done by search from a tree root, or via a directly stored parent. The `Tree` class now implements the `Collection` interface: in terms of this, each node of the tree is an element of the collection; hence one can explore the tree by using the methods of this interface. A `Tree` is regarded as a read-only `Collection` (even though the `Tree` class has various methods that modify trees). Moreover, the implementation is not thread-safe: no attempt is made to detect and report concurrent modifications.

Author:
  Christopher Manning, Dan Klein, Sarah Spikes (sdspikes@cs.stanford.edu) - filled in types
See Also:
  Serialized Form

Field Summary
`static boolean` `DISPLAY_SCORES`
`static Tree[]` `EMPTY_TREE_ARRAY` A leaf node should have a zero-length array for its children.

Constructor Summary
`Tree()`

Method Summary
`void` `addChild(int i, Tree t)` Adds the tree t at the index position among the daughters.
`void` `addChild(Tree t)` Adds the tree t at the last index position among the daughters.
`Tree` `ancestor(int height, Tree root)` Return the ancestor tree node `height` nodes up from the current node.
`boolean` `cCommands(Tree t1, Tree t2)` Given nodes `t1` and `t2` which are dominated by this node, returns `true` iff `t1` c-commands `t2`.
`abstract Tree[]` `children()` Returns an array of children for the current node.
`Set<Constituent>` `constituents()` Returns the Constituents generated by the parse tree.
`Set<Constituent>` `constituents(ConstituentFactory cf)` Returns the Constituents generated by the parse tree.
`Set<Constituent>` `constituents(ConstituentFactory cf, boolean charLevel)` Returns the Constituents generated by the parse tree.
`Tree` `deepCopy()` Makes a deep copy of not only the Tree structure but of the labels as well.
`Tree` `deepCopy(TreeFactory tf)` Makes a deep copy of not only the Tree structure but of the labels as well.
`Tree` `deepCopy(TreeFactory tf, LabelFactory lf)` Makes a deep copy of not only the Tree structure but of the labels as well.
`Set<Dependency<Label,Label,Object>>` `dependencies()` Return a set of Word-Word dependencies, represented as Dependency objects, for the Tree.
`Set<Dependency<Label,Label,Object>>` `dependencies(Filter<Dependency<Label,Label,Object>> f)` Return a set of Word-Word dependencies, represented as Dependency objects, for the Tree.
`Set<Dependency<Label,Label,Object>>` `dependencies(Filter<Dependency<Label,Label,Object>> f, HeadFinder hf)` Return a set of Word-Word dependencies, represented as Dependency objects, for the Tree.
`Set<Dependency<Label,Label,Object>>` `dependencies(HeadFinder hf)` Return a set of Word-Word dependencies, represented as Dependency objects for the Tree.
`int` `depth()` Finds the depth of the tree.
`int` `depth(Tree node)` Finds the distance from this node to the specified node.
`boolean` `dominates(Tree t)` Returns true if `this` dominates the Tree passed in as an argument.
`List<Tree>` `dominationPath(Tree t)` Returns the path of nodes leading down to a dominated node, including `this` and the dominated node itself.
`boolean` `equals(Object o)` Implements equality for Tree's.
`Tree` `firstChild()` Returns the first child of a tree, or `null` if none.
`Tree` `flatten()` Return a flattened version of a tree.
`Tree` `flatten(TreeFactory tf)` Return a flattened version of a tree.
`Tree` `getChild(int i)` Return the child at some daughter index.
`List<Tree>` `getChildrenAsList()` Returns a List of children for the current node.
`List<Tree>` `getLeaves()` Gets the leaves of the tree.
`List<Tree>` `getLeaves(List<Tree> list)` Gets the leaves of the tree.
`Tree` `getNodeNumber(int i)` Fetches the `i`th node in the tree, with node numbers defined as in `nodeNumber(Tree)`.
`IntPair` `getSpan()`
`int` `hashCode()` Implements a hashCode for Tree's.
`Tree` `headPreTerminal(HeadFinder hf)` Returns the preterminal tree that is the head of the tree.
`Tree` `headTerminal(HeadFinder hf)` Returns the tree leaf that is the head of the tree.
`Tree` `headTerminal(HeadFinder hf, Tree parent)` Returns the tree leaf that is the head of the tree.
`void` `indentedListPrint()` Indented list printing of a tree.
`void` `indentedListPrint(PrintWriter pw, boolean printScores)` Indented list printing of a tree.
`void` `indexLeaves()` Assign sequential integer indices to the leaves of the tree rooted at this `Tree`, starting with 1.
`int` `indexOf(Tree tree)` Returns the position of a Tree in the children list, if present, or -1 if it is not present.
`void` `indexSpans(int startIndex)`
`Pair<Integer,Integer>` `indexSpans(MutableInteger startIndex)` Assigns span indices (BeginIndexAnnotation and EndIndexAnnotation) to all nodes in a tree.
`void` `insertDtr(Tree dtr, int position)` insert `dtr` after `position` existing daughters in `this`.
`boolean` `isLeaf()` Says whether a node is a leaf.
`boolean` `isPhrasal()` Return whether this node is a phrasal node or not.
`boolean` `isPrePreTerminal()` Return whether all the children of this node are preterminals or not.
`boolean` `isPreTerminal()` Return whether this node is a preterminal or not.
`boolean` `isUnaryRewrite()` Says whether the current node has only one child.
`Iterator<Tree>` `iterator()` Returns an iterator over all the nodes of the tree.
`Tree` `joinNode(Tree t1, Tree t2)` Given nodes `t1` and `t2` which are dominated by this node, returns their "join node": the node `j` such that `j` dominates both `t1` and `t2`, and every other node which dominates both `t1` and `t2` dominates `j`.
`Label` `label()` Returns the label associated with the current node, or null if there is no label.
`List<LabeledWord>` `labeledYield()`
`List<LabeledWord>` `labeledYield(List<LabeledWord> ty)`
`LabelFactory` `labelFactory()` Returns a factory that makes labels of the same type as this one.
`Collection<Label>` `labels()` Get the set of all node and leaf `Label`s, null or otherwise, contained in the tree.
`Tree` `lastChild()` Returns the last child of a tree, or `null` if none.
`int` `leftCharEdge(Tree node)` Returns the positional index of the left edge of node within the tree, as measured by characters.
`Tree` `localTree()` Returns a new Tree that represents the local Tree at a certain node.
`Set<Tree>` `localTrees()` Returns a set of one level `Tree`s that ares the local trees of the tree.
`Set<Dependency<Label,Label,Object>>` `mapDependencies(Filter<Dependency<Label,Label,Object>> f, HeadFinder hf)` Return a set of Label-Label dependencies, represented as Dependency objects, for the Tree.
`Set<Dependency<Label,Label,Object>>` `mapDependencies(Filter<Dependency<Label,Label,Object>> f, HeadFinder hf, String rootName)` Return a set of Label-Label dependencies, represented as Dependency objects, for the Tree.
`int` `nodeNumber(Tree root)` Calculates the node's number, defined as the number of nodes traversed in a left-to-right, depth-first search of the tree starting at `root` and ending at `this`.
`String` `nodeString()` Returns the value of the nodes label as a String.
`int` `numChildren()` Says how many children a tree node has in its local tree.
`Tree` `parent()` Return the parent of the tree node.
`Tree` `parent(Tree root)` Return the parent of the tree node.
`List<Tree>` `pathNodeToNode(Tree t1, Tree t2)` Given nodes `t1` and `t2` which are dominated by this node, returns a list of all the nodes on the path from t1 to t2, inclusive, or null if none found.
`void` `pennPrint()` Print the tree as done in Penn Treebank merged files.
`void` `pennPrint(PrintStream ps)` Print the tree as done in Penn Treebank merged files.
`void` `pennPrint(PrintWriter pw)` Print the tree as done in Penn Treebank merged files.
`String` `pennString()` Calls `pennPrint()` and saves output to a String
`void` `percolateHeads(HeadFinder hf)` Finds the heads of the tree.
`List<Tree>` `postOrderNodeList()`
`List<Tree>` `preOrderNodeList()`
`List<Label>` `preTerminalYield()` Gets the preterminal yield (i.e., tags) of the tree.
`List<Label>` `preTerminalYield(List<Label> y)` Gets the preterminal yield (i.e., tags) of the tree.
`void` `printLocalTree()`
`void` `printLocalTree(PrintWriter pw)`
`Tree` `prune(Filter<Tree> filter)` Creates a deep copy of the tree, where all nodes that the filter does not accept and all children of such nodes are pruned.
`Tree` `prune(Filter<Tree> filter, TreeFactory tf)` Creates a deep copy of the tree, where all nodes that the filter does not accept and all children of such nodes are pruned.
`Tree` `removeChild(int i)` Destructively removes the child at some daughter index and returns it.
`int` `rightCharEdge(Tree node)` Returns the positional index of the right edge of node within the tree, as measured by characters.
`double` `score()` Returns the score associated with the current node, or NaN if there is no score.
`Tree` `setChild(int i, Tree t)` Replaces the `i`th child of `this` with the tree t.
`void` `setChildren(List<Tree> childTreesList)` Set the children of this tree node to the given list.
`void` `setChildren(Tree[] children)` Set the children of this node to be the children given in the array.
`void` `setFromString(String labelStr)` Set the contents of this label to this `String` representing the complete contents of the label.
`void` `setLabel(Label label)` Sets the label associated with the current node, if there is one.
`void` `setLabels(Collection<Label> c)` Sets the labels associated with this object.
`void` `setScore(double score)` Sets the score associated with the current node, if there is one.
`void` `setSpans()`
`void` `setValue(String value)` Set the value for the label (if one is stored).
`List<Tree>` `siblings(Tree root)` Returns the siblings of this Tree node.
`int` `size()` Returns the number of nodes the tree contains.
`Tree` `skipRoot()` Returns first child if it is single and if the label at the current node is either "ROOT" or empty.
`Tree` `spliceOut(Filter<Tree> nodeFilter)` Creates a (partial) deep copy of the tree, where all nodes that the filter does not accept are spliced out.
`Tree` `spliceOut(Filter<Tree> nodeFilter, TreeFactory tf)` Creates a (partial) deep copy of the tree, where all nodes that the filter does not accept are spliced out.
`List<Tree>` `subTreeList()` Get the list of all subtrees inside the tree by returning a tree rooted at each node.
`Set<Tree>` `subTrees()` Get the set of all subtrees inside the tree by returning a tree rooted at each node.

`

`<T extends Collection<Tree>> T`

`

`subTrees(T n)`
Add the set of all subtrees inside a tree (including the tree itself) to the given `Collection`.

`Set<Dependency<Label,Label,Object>>` `taggedDependencies()` Return a Set of TaggedWord-TaggedWord dependencies, represented as Dependency objects, for the Tree.
`Set<Dependency<Label,Label,Object>>` `taggedDependencies(Filter<Dependency<Label,Label,Object>> f)` Return a set of TaggedWord-TaggedWord dependencies, represented as Dependency objects, for the Tree.
`Set<Dependency<Label,Label,Object>>` `taggedDependencies(Filter<Dependency<Label,Label,Object>> f, HeadFinder hf)` Return a set of TaggedWord-TaggedWord dependencies, represented as Dependency objects, for the Tree.
`Set<Dependency<Label,Label,Object>>` `taggedDependencies(HeadFinder hf)` Return a set of TaggedWord-TaggedWord dependencies, represented as Dependency objects for the Tree.
`List<CoreLabel>` `taggedLabeledYield()`
`ArrayList<TaggedWord>` `taggedYield()` Gets the tagged yield of the tree.

`

`<X extends List<TaggedWord>> X`

`

`taggedYield(X ty)`
Gets the tagged yield of the tree -- that is, get the preterminals as well as the terminals.

`String` `toString()` Converts parse tree to string in Penn Treebank format.
`StringBuilder` `toStringBuilder(StringBuilder sb)` Appends the printed form of a parse tree (as a bracketed String) to an `Appendable`, such as a `StringBuffer`.
`StringBuilder` `toStringBuilder(StringBuilder sb, boolean printOnlyLabelValue)` Appends the printed form of a parse tree (as a bracketed String) to an `Appendable`, such as a `StringBuffer`.
`String` `toStructureDebugString()` Returns a String reporting what kinds of Tree and Label nodes this Tree contains.
`Tree` `transform(TreeTransformer transformer)` Create a transformed Tree.
`Tree` `transform(TreeTransformer transformer, TreeFactory tf)` Create a transformed Tree.
`abstract TreeFactory` `treeFactory()` Return a `TreeFactory` that produces trees of the appropriate type.
`Tree` `treeSkeletonCopy()` Create a deep copy of the tree structure.
`Tree` `treeSkeletonCopy(TreeFactory tf)` Create a deep copy of the tree structure.
`Tree` `upperMostUnary(Tree root)` Return the highest node of the (perhaps trivial) unary chain that this node is part of.
`String` `value()` Return a String representation of just the "main" value of this label.
`static Tree` `valueOf(String str)` This gives you a tree from a String representation (as a bracketed Tree, of the kind produced by `toString()`, `pennPrint()`, or as in the Penn Treebank).
`static Tree` `valueOf(String str, TreeReaderFactory trf)` This gives you a tree from a String representation (as a bracketed Tree, of the kind produced by `toString()`, `pennPrint()`, or as in the Penn Treebank.
`ArrayList<Label>` `yield()` Gets the yield of the tree.
`ArrayList<Label>` `yield(ArrayList<Label> y)` Gets the yield of the tree.

`

`<T> List<T>`

`

`yield(List<T> y)`
Gets the yield of the tree.

`

`<X extends HasWord> ArrayList<X>`

`

`yieldHasWord()`

`

`<X extends HasWord> ArrayList<X>`

`

`yieldHasWord(ArrayList<X> y)`

`ArrayList<Word>` `yieldWords()`
`ArrayList<Word>` `yieldWords(ArrayList<Word> y)`

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`

Field Detail

### EMPTY_TREE_ARRAY

    public static final Tree[] EMPTY_TREE_ARRAY

  A leaf node should have a zero-length array for its children. For efficiency, classes can use this array as a return value for children() for leaf nodes if desired. This can also be used elsewhere when you want an empty Tree array.

### DISPLAY_SCORES

    public static boolean DISPLAY_SCORES

Constructor Detail

### Tree

    public Tree()

Method Detail

### isLeaf

    public boolean isLeaf()

  Says whether a node is a leaf. Can be used on an arbitrary `Tree`. Being a leaf is defined as having no children. This must be implemented as returning a zero-length Tree[] array for children(). This is the preferred alternative to running meta checks on types, as it works independent of Tree implementation.

  Returns:
    true if this object is a leaf

### numChildren

    public int numChildren()

  Says how many children a tree node has in its local tree. Can be used on an arbitrary `Tree`. Being a leaf is defined as having no children.

  Returns:
    The number of direct children of the tree node

### isUnaryRewrite

    public boolean isUnaryRewrite()

  Says whether the current node has only one child. Can be used on an arbitrary `Tree`.

  Returns:
    Whether the node heads a unary rewrite

### isPreTerminal

    public boolean isPreTerminal()

  Return whether this node is a preterminal or not. A preterminal is defined to be a node with one child which is itself a leaf.

  Returns:
    true if the node is a preterminal; false otherwise

### isPrePreTerminal

    public boolean isPrePreTerminal()

  Return whether all the children of this node are preterminals or not. A preterminal is defined to be a node with one child which is itself a leaf. Considered false if the node has no children

  Returns:
    true if the node is a prepreterminal; false otherwise

### isPhrasal

    public boolean isPhrasal()

  Return whether this node is a phrasal node or not. A phrasal node is defined to be a node which is not a leaf or a preterminal. Worded positively, this means that it must have two or more children, or one child that is not a leaf.

  Returns:
    `true` if the node is phrasal; `false` otherwise

### equals

    public boolean equals(Object o)

  Implements equality for Tree's. Two Tree objects are equal if they have equal `value()`s, the same number of children, and their children are pairwise equal.

  Specified by:
    `equals` in interface `Collection<Tree>`
  Overrides:
    `equals` in class `Object`
  Parameters:
    `o` - The object to compare with
  Returns:
    Whether two things are equal

### hashCode

    public int hashCode()

  Implements a hashCode for Tree's. Two trees should have the same hashcode if they are equal, so we hash on the label value and the children's label values.

  Specified by:
    `hashCode` in interface `Collection<Tree>`
  Overrides:
    `hashCode` in class `Object`
  Returns:
    The hash code

### indexOf

    public int indexOf(Tree tree)

  Returns the position of a Tree in the children list, if present, or -1 if it is not present. Trees are checked for presence with `equals()`.

  Parameters:
    `tree` - The tree to look for in children list
  Returns:
    Its index in the list or -1

### children

    public abstract Tree[] children()

  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.

  Returns:
    The children of the node
  See Also:
    `getChildrenAsList()`

### getChildrenAsList

    public List<Tree> getChildrenAsList()

  Returns a List of children for the current node. If there are no children, then a (non-null) `List<Tree>` of size 0 will be returned. The list has new list structure but pointers to, not copies of the children. That is, the returned list is mutable, and simply adding to or deleting items from it is safe, but beware changing the contents of the children.

  Returns:
    The children of the node

### setChildren

    public void setChildren(Tree[] children)

  Set the children of this node to be the children given in the array. This is an optional operation; by default it is unsupported. Note for subclasses that if there are no children, the children() method must return a Tree[] array of length 0. This class gives subclasses access to a protected `ZEROCHILDREN` canonical zero-length Tree[] array to represent zero children, but it is not required that leaf nodes use this particular zero-length array to represent a leaf node.

  Parameters:
    `children` - The array of children, each a `Tree`
  See Also:
    `setChildren(List)`

### setChildren

    public void setChildren(List<Tree> childTreesList)

  Set the children of this tree node to the given list. This method is implemented in the `Tree` class by converting the `List` into a tree array and calling the array-based method. Subclasses which use a `List`-based representation of tree children should override this method. This implementation allows the case that the `List` is `null`: it yields a node with no children (represented by a canonical zero-length children() array).

  Parameters:
    `childTreesList` - A list of trees to become children of the node. This method does not retain the List that you pass it (copying is done), but it will retain the individual children (they are not copied).
  See Also:
    `setChildren(Tree[])`

### label

    public Label label()

  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`
  Returns:
    The label of the node

### setLabel

    public void setLabel(Label label)

  Sets the label associated with the current node, if there is one. The default implementation ignores the label.

  Specified by:
    `setLabel` in interface `Labeled`
  Parameters:
    `label` - The label

### score

    public double score()

  Returns the score associated with the current node, or NaN if there is no score. The default implementation returns NaN.

  Specified by:
    `score` in interface `Scored`
  Returns:
    The score

### setScore

    public void setScore(double score)

  Sets the score associated with the current node, if there is one.

  Parameters:
    `score` - The score

### firstChild

    public Tree firstChild()

  Returns the first child of a tree, or `null` if none.

  Returns:
    The first child

### lastChild

    public Tree lastChild()

  Returns the last child of a tree, or `null` if none.

  Returns:
    The last child

### upperMostUnary

    public Tree upperMostUnary(Tree root)

  Return the highest node of the (perhaps trivial) unary chain that this node is part of. In case this node is the only child of its parent, trace up the chain of unaries, and return the uppermost node of the chain (the node whose parent has multiple children, or the node that is the root of the tree).

  Parameters:
    `root` - The root of the tree that contains this subtree
  Returns:
    The uppermost node of the unary chain, if this node is in a unary chain, or else the current node

### setSpans

    public void setSpans()

### getSpan

    public IntPair getSpan()

### constituents

    public Set<Constituent> constituents()

  Returns the Constituents generated by the parse tree. Constituents are computed with respect to whitespace (e.g., at the word level).

  Returns:
    a Set of the constituents as constituents of type `Constituent`

### constituents

    public Set<Constituent> constituents(ConstituentFactory cf)

  Returns the Constituents generated by the parse tree. The Constituents of a sentence include the preterminal categories but not the leaves.

  Parameters:
    `cf` - ConstituentFactory used to build the Constituent objects
  Returns:
    a Set of the constituents as SimpleConstituent type (in the current implementation, a `HashSet`

### constituents

    public Set<Constituent> constituents(ConstituentFactory cf,
                                         boolean charLevel)

  Returns the Constituents generated by the parse tree. The Constituents of a sentence include the preterminal categories but not the leaves.

  Parameters:
    `cf` - ConstituentFactory used to build the Constituent objects
    `charLevel` - If true, compute bracketings irrespective of whitespace boundaries.
  Returns:
    a Set of the constituents as SimpleConstituent type (in the current implementation, a `HashSet`

### localTree

    public Tree localTree()

  Returns a new Tree that represents the local Tree at a certain node. That is, it builds a new tree that copies the mother and daughter nodes (but not their Labels), as non-Leaf nodes, but zeroes out their children.

  Returns:
    A local tree

### localTrees

    public Set<Tree> localTrees()

  Returns a set of one level `Tree`s that ares the local trees of the tree. That is, it builds a new tree that copies the mother and daughter nodes (but not their Labels), for each phrasal node, but zeroes out their children.

  Returns:
    A set of local tree

### toStructureDebugString

    public String toStructureDebugString()

  Returns a String reporting what kinds of Tree and Label nodes this Tree contains.

  Returns:
    A String reporting what kinds of Tree and Label nodes this Tree contains.

### toStringBuilder

    public StringBuilder toStringBuilder(StringBuilder sb)

  Appends the printed form of a parse tree (as a bracketed String) to an `Appendable`, such as a `StringBuffer`. The implementation of this may be more efficient than for `toString()` on complex trees.

  Parameters:
    `sb` - The `StringBuilder` to which the tree will be appended
  Returns:
    Returns the `StringBuilder` passed in with extra stuff in it

### toStringBuilder

    public StringBuilder toStringBuilder(StringBuilder sb,
                                         boolean printOnlyLabelValue)

  Appends the printed form of a parse tree (as a bracketed String) to an `Appendable`, such as a `StringBuffer`. The implementation of this may be more efficient than for `toString()` on complex trees.

  Parameters:
    `sb` - The `StringBuilder` to which the tree will be appended
    `printOnlyLabelValue` - If true, print only the value() of each node's label
  Returns:
    Returns the `StringBuilder` passed in with extra stuff in it

### toString

    public String toString()

  Converts parse tree to string in Penn Treebank format. Get efficiency by chaining a single `StringBuffer` through it all.

  Specified by:
    `toString` in interface `Label`
  Overrides:
    `toString` in class `AbstractCollection<Tree>`
  Returns:
    the tree as a bracketed list on one line

### printLocalTree

    public void printLocalTree()

### printLocalTree

    public void printLocalTree(PrintWriter pw)

### indentedListPrint

    public void indentedListPrint()

  Indented list printing of a tree. The tree is printed in an indented list notation, with nodel labels followed by node scores.

### indentedListPrint

    public void indentedListPrint(PrintWriter pw,
                                  boolean printScores)

  Indented list printing of a tree. The tree is printed in an indented list notation, with nodel labels followed by node scores.

  Parameters:
    `pw` - The PrintWriter to print the tree to
    `printScores` - Whether to print the scores (log probs) of tree nodes

### nodeString

    public String nodeString()

  Returns the value of the nodes label as a String. This is done by calling `toString()` on the value, if it exists. Otherwise, an empty string is returned.

  Returns:
    The label of a tree node as a String

### pennPrint

    public void pennPrint(PrintWriter pw)

  Print the tree as done in Penn Treebank merged files. The formatting should be exactly the same, but we don't print the trailing whitespace found in Penn Treebank trees. The basic deviation from a bracketed indented tree is to in general collapse the printing of adjacent preterminals onto one line of tasg and words. Additional complexities are that conjunctions (tag CC) are not collapsed in this way, and that the unlabeled outer brackets are collapsed onto the same line as the next bracket down.

  Parameters:
    `pw` - The tree is printed to this `PrintWriter`

### pennPrint

    public void pennPrint(PrintStream ps)

  Print the tree as done in Penn Treebank merged files. The formatting should be exactly the same, but we don't print the trailing whitespace found in Penn Treebank trees. The basic deviation from a bracketed indented tree is to in general collapse the printing of adjacent preterminals onto one line of tags and words. Additional complexities are that conjunctions (tag CC) are not collapsed in this way, and that the unlabeled outer brackets are collapsed onto the same line as the next bracket down.

  Parameters:
    `ps` - The tree is printed to this `PrintStream`

### pennString

    public String pennString()

  Calls `pennPrint()` and saves output to a String

  Returns:
    The indent S-expression representation of a Tree

### pennPrint

    public void pennPrint()

  Print the tree as done in Penn Treebank merged files. The formatting should be exactly the same, but we don't print the trailing whitespace found in Penn Treebank trees. The tree is printed to `System.out`. The basic deviation from a bracketed indented tree is to in general collapse the printing of adjacent preterminals onto one line of tags and words. Additional complexities are that conjunctions (tag CC) are not collapsed in this way, and that the unlabeled outer brackets are collapsed onto the same line as the next bracket down.

### depth

    public int depth()

  Finds the depth of the tree. The depth is defined as the length of the longest path from this node to a leaf node. Leaf nodes have depth zero. POS tags have depth 1. Phrasal nodes have depth >= 2.

  Returns:
    the depth

### depth

    public int depth(Tree node)

  Finds the distance from this node to the specified node. return -1 if this is not an ancestor of node.

  Parameters:
    `node` - A subtree contained in this tree
  Returns:
    the depth

### headTerminal

    public Tree headTerminal(HeadFinder hf,
                             Tree parent)

  Returns the tree leaf that is the head of the tree.

  Parameters:
    `hf` - The headfinding algorithm to use
    `parent` - The parent of this tree
  Returns:
    The head tree leaf if any, else `null`

### headTerminal

    public Tree headTerminal(HeadFinder hf)

  Returns the tree leaf that is the head of the tree.

  Parameters:
    `hf` - The headfinding algorithm to use
  Returns:
    The head tree leaf if any, else `null`

### headPreTerminal

    public Tree headPreTerminal(HeadFinder hf)

  Returns the preterminal tree that is the head of the tree. See `isPreTerminal()` for the definition of a preterminal node. Beware that some tree nodes may have no preterminal head.

  Parameters:
    `hf` - The headfinding algorithm to use
  Returns:
    The head preterminal tree, if any, else `null`
  Throws:
    `IllegalArgumentException` - if called on a leaf node

### percolateHeads

    public void percolateHeads(HeadFinder hf)

  Finds the heads of the tree. This code assumes that the label does store and return sensible values for the category, word, and tag. It will be a no-op otherwise. The tree is modified. The routine assumes the Tree has word leaves and tag preterminals, and copies their category to word and tag respectively, if they have a null value.

  Parameters:
    `hf` - The headfinding algorithm to use

### dependencies

    public Set<Dependency<Label,Label,Object>> dependencies()

  Return a set of Word-Word dependencies, represented as Dependency objects, for the Tree. This will only give useful results if the internal tree node labels support HasWord and head percolation has already been done (see percolateHeads()).

  Returns:
    Set of dependencies (each a Dependency)

### dependencies

    public Set<Dependency<Label,Label,Object>> dependencies(Filter<Dependency<Label,Label,Object>> f)

  Return a set of Word-Word dependencies, represented as Dependency objects, for the Tree. This will only give useful results if the internal tree node labels support HasWord and head percolation has already been done (see percolateHeads()).

  Parameters:
    `f` - Dependencies are excluded for which the Dependency is not accepted by the Filter
  Returns:
    Set of dependencies (each a Dependency)

### dependencies

    public Set<Dependency<Label,Label,Object>> dependencies(HeadFinder hf)

  Return a set of Word-Word dependencies, represented as Dependency objects for the Tree.

  Parameters:
    `hf` - The HeadFinder to use to identify the head of constituents
  Returns:
    Set of dependencies (each a `Dependency`)

### dependencies

    public Set<Dependency<Label,Label,Object>> dependencies(Filter<Dependency<Label,Label,Object>> f,
                                                            HeadFinder hf)

  Return a set of Word-Word dependencies, represented as Dependency objects, for the Tree.

  Parameters:
    `f` - Dependencies are excluded for which the Dependency is not accepted by the Filter
    `hf` - The HeadFinder to use to identify the head of constituents. If this is `null`, then nodes are assumed to already be marked with their heads.
  Returns:
    Set of dependencies (each a `Dependency`)

### taggedDependencies

    public Set<Dependency<Label,Label,Object>> taggedDependencies()

  Return a Set of TaggedWord-TaggedWord dependencies, represented as Dependency objects, for the Tree. This will only give useful results if the internal tree node labels support HasWord and HasTag, and head percolation has already been done (see percolateHeads()).

  Returns:
    Set of dependencies (each a Dependency)

### taggedDependencies

    public Set<Dependency<Label,Label,Object>> taggedDependencies(Filter<Dependency<Label,Label,Object>> f)

  Return a set of TaggedWord-TaggedWord dependencies, represented as Dependency objects, for the Tree. This will only give useful results if the internal tree node labels support HasWord and head percolation has already been done (see percolateHeads()).

  Implementation note: It would be nice to generalize this with dependencies() to use a LabelFactory, but it seems impossible with the current setup.

  Parameters:
    `f` - Dependencies are excluded for which the Dependency is not accepted by the Filter
  Returns:
    Set of dependencies (each a Dependency)

### taggedDependencies

    public Set<Dependency<Label,Label,Object>> taggedDependencies(HeadFinder hf)

  Return a set of TaggedWord-TaggedWord dependencies, represented as Dependency objects for the Tree.

  Parameters:
    `hf` - The HeadFinder to use to identify the head of constituents
  Returns:
    Set of dependencies (each a `Dependency`)

### taggedDependencies

    public Set<Dependency<Label,Label,Object>> taggedDependencies(Filter<Dependency<Label,Label,Object>> f,
                                                                  HeadFinder hf)

  Return a set of TaggedWord-TaggedWord dependencies, represented as Dependency objects, for the Tree.

  Parameters:
    `f` - Dependencies are excluded for which the Dependency is not accepted by the Filter
    `hf` - The HeadFinder to use to identify the head of constituents. If this is `null`, then nodes are assumed to already be marked with their heads.
  Returns:
    Set of dependencies (each a `Dependency`)

### mapDependencies

    public Set<Dependency<Label,Label,Object>> mapDependencies(Filter<Dependency<Label,Label,Object>> f,
                                                               HeadFinder hf)

  Return a set of Label-Label dependencies, represented as Dependency objects, for the Tree. The Labels are the ones of the leaf nodes of the tree, without mucking with them.

  Parameters:
    `f` - Dependencies are excluded for which the Dependency is not accepted by the Filter
    `hf` - The HeadFinder to use to identify the head of constituents. The code assumes that it can use `headPreTerminal(hf)` to find a tag and word to make a CyclicCoreLabel.
  Returns:
    Set of dependencies (each a `Dependency` between two `CyclicCoreLabel`s, which each contain a tag(), word(), and value(), the last two of which are identical).

### mapDependencies

    public Set<Dependency<Label,Label,Object>> mapDependencies(Filter<Dependency<Label,Label,Object>> f,
                                                               HeadFinder hf,
                                                               String rootName)

  Return a set of Label-Label dependencies, represented as Dependency objects, for the Tree. The Labels are the ones of the leaf nodes of the tree, without mucking with them. The head of the sentence is a dependent of a synthetic "root" label.

  Parameters:
    `f` - Dependencies are excluded for which the Dependency is not accepted by the Filter
    `hf` - The HeadFinder to use to identify the head of constituents. The code assumes that it can use `headPreTerminal(hf)` to find a tag and word to make a CyclicCoreLabel.
    `rootName` - Name of the root node.
  Returns:
    Set of dependencies (each a `Dependency` between two `CyclicCoreLabel`s, which each contain a tag(), word(), and value(), the last two of which are identical).

### yield

    public ArrayList<Label> yield()

  Gets the yield of the tree. The `Label` of all leaf nodes is returned as a list ordered by the natural left to right order of the leaves. Null values, if any, are inserted into the list like any other value.

  Returns:
    a `List` of the data in the tree's leaves.

### yield

    public ArrayList<Label> yield(ArrayList<Label> y)

  Gets the yield of the tree. The `Label` of all leaf nodes is returned as a list ordered by the natural left to right order of the leaves. Null values, if any, are inserted into the list like any other value.

  Implementation notes: c. 2003: This has been rewritten to thread, so only one List is used. 2007: This method was duplicated to start to give type safety to Sentence. This method will now make a Word for any Leaf which does not itself implement HasWord, and put the Word into the Sentence, so the Sentence elements MUST implement HasWord.

  Parameters:
    `y` - The list in which the yield of the tree will be placed. Normally, this will be empty when the routine is called, but if not, the new yield is added to the end of the list.
  Returns:
    a `List` of the data in the tree's leaves.

### yieldWords

    public ArrayList<Word> yieldWords()

### yieldWords

    public ArrayList<Word> yieldWords(ArrayList<Word> y)

### yieldHasWord

    public <X extends HasWord> ArrayList<X> yieldHasWord()

### yieldHasWord

    public <X extends HasWord> ArrayList<X> yieldHasWord(ArrayList<X> y)

### yield

    public <T> List<T> yield(List<T> y)

  Gets the yield of the tree. The `Label` of all leaf nodes is returned as a list ordered by the natural left to right order of the leaves. Null values, if any, are inserted into the list like any other value. This has been rewritten to thread, so only one List is used.

  Parameters:
    `y` - The list in which the yield of the tree will be placed. Normally, this will be empty when the routine is called, but if not, the new yield is added to the end of the list.
  Returns:
    a `List` of the data in the tree's leaves.

### taggedYield

    public ArrayList<TaggedWord> taggedYield()

  Gets the tagged yield of the tree. The `Label` of all leaf nodes is returned as a list ordered by the natural left to right order of the leaves. Null values, if any, are inserted into the list like any other value.

  Returns:
    a `List` of the data in the tree's leaves.

### labeledYield

    public List<LabeledWord> labeledYield()

### taggedYield

    public <X extends List<TaggedWord>> X taggedYield(X ty)

  Gets the tagged yield of the tree -- that is, get the preterminals as well as the terminals. The `Label` of all leaf nodes is returned as a list ordered by the natural left to right order of the leaves. Null values, if any, are inserted into the list like any other value. This has been rewritten to thread, so only one List is used.

  Implementation note: when we summon up enough courage, this method will be changed to take and return a List<W extends TaggedWord>.

  Parameters:
    `ty` - The list in which the tagged yield of the tree will be placed. Normally, this will be empty when the routine is called, but if not, the new yield is added to the end of the list.
  Returns:
    a `List` of the data in the tree's leaves.

### labeledYield

    public List<LabeledWord> labeledYield(List<LabeledWord> ty)

### taggedLabeledYield

    public List<CoreLabel> taggedLabeledYield()

### preTerminalYield

    public List<Label> preTerminalYield()

  Gets the preterminal yield (i.e., tags) of the tree. All data in preleaf nodes is returned as a list ordered by the natural left to right order of the tree. Null values, if any, are inserted into the list like any other value. Pre-leaves are nodes of height 1.

  Returns:
    a `List` of the data in the tree's pre-leaves.

### preTerminalYield

    public List<Label> preTerminalYield(List<Label> y)

  Gets the preterminal yield (i.e., tags) of the tree. All data in preleaf nodes is returned as a list ordered by the natural left to right order of the tree. Null values, if any, are inserted into the list like any other value. Pre-leaves are nodes of height 1.

  Parameters:
    `y` - The list in which the preterminals of the tree will be placed. Normally, this will be empty when the routine is called, but if not, the new yield is added to the end of the list.
  Returns:
    a `List` of the data in the tree's pre-leaves.

### getLeaves

    public List<Tree> getLeaves()

  Gets the leaves of the tree. All leaves nodes are returned as a list ordered by the natural left to right order of the tree. Null values, if any, are inserted into the list like any other value.

  Returns:
    a `List` of the leaves.

### getLeaves

    public List<Tree> getLeaves(List<Tree> list)

  Gets the leaves of the tree.

  Parameters:
    `list` - The list in which the leaves of the tree will be placed. Normally, this will be empty when the routine is called, but if not, the new yield is added to the end of the list.
  Returns:
    a `List` of the leaves.

### labels

    public Collection<Label> labels()

  Get the set of all node and leaf `Label`s, null or otherwise, contained in the tree.

  Specified by:
    `labels` in interface `Labeled`
  Returns:
    the `Collection` (actually, Set) of all values in the tree.

### setLabels

    public void setLabels(Collection<Label> c)

  Description copied from interface: `Labeled`
  Sets the labels associated with this object.

  Specified by:
    `setLabels` in interface `Labeled`
  Parameters:
    `c` - The set of Label values

### flatten

    public Tree flatten()

  Return a flattened version of a tree. In many circumstances, this will just return the tree, but if the tree is something like a binarized version of a dependency grammar tree, then it will be flattened back to a dependency grammar tree representation. Formally, a node will be removed from the tree when: it is not a terminal or preterminal, and its `label()`equal() to the `label()` of its parent, and all its children will then be promoted to become children of the parent (in the same position in the sequence of daughters.

  Returns:
    A flattened version of this tree.

### flatten

    public Tree flatten(TreeFactory tf)

  Return a flattened version of a tree. In many circumstances, this will just return the tree, but if the tree is something like a binarized version of a dependency grammar tree, then it will be flattened back to a dependency grammar tree representation. Formally, a node will be removed from the tree when: it is not a terminal or preterminal, and its `label()`equal() to the `label()` of its parent, and all its children will then be promoted to become children of the parent (in the same position in the sequence of daughters.

  Note: In the current implementation, the tree structure is mainly duplicated, but the links between preterminals and terminals aren't.

  Parameters:
    `tf` - TreeFactory used to create tree structure for flattened tree
  Returns:
    A flattened version of this tree.

### subTrees

    public Set<Tree> subTrees()

  Get the set of all subtrees inside the tree by returning a tree rooted at each node. These are not copies, but all share structure. The tree is regarded as a subtree of itself.

  Note: If you only want to form this Set so that you can iterate over it, it is more efficient to simply use the Tree class's own `iterator() method. This will iterate over the exact same elements (but perhaps/probably in a different order).

  `
  Returns:
    the `Set` of all subtrees in the tree.

### subTreeList

    public List<Tree> subTreeList()

  Get the list of all subtrees inside the tree by returning a tree rooted at each node. These are not copies, but all share structure. The tree is regarded as a subtree of itself.

  Note: If you only want to form this Collection so that you can iterate over it, it is more efficient to simply use the Tree class's own `iterator() method. This will iterate over the exact same elements (but perhaps/probably in a different order).

  `
  Returns:
    the `List` of all subtrees in the tree.

### subTrees

    public <T extends Collection<Tree>> T subTrees(T n)

  Add the set of all subtrees inside a tree (including the tree itself) to the given `Collection`.

  Note: If you only want to form this Collection so that you can iterate over it, it is more efficient to simply use the Tree class's own `iterator() method. This will iterate over the exact same elements (but perhaps/probably in a different order).

  `
  Parameters:
    `n` - A collection of nodes to which the subtrees will be added.
  Returns:
    The collection parameter with the subtrees added.

### deepCopy

    public Tree deepCopy()

  Makes a deep copy of not only the Tree structure but of the labels as well. Uses the TreeFactory of the root node given by treeFactory(). Assumes that your labels give a non-null labelFactory(). (Added by Aria Haghighi.)

  Returns:
    A deep copy of the tree structure and its labels

### deepCopy

    public Tree deepCopy(TreeFactory tf)

  Makes a deep copy of not only the Tree structure but of the labels as well. The new tree will have nodes made by the given TreeFactory. Each Label is copied using the labelFactory() returned by the corresponding node's label. It assumes that your labels give non-null labelFactory. (Added by Aria Haghighi.)

  Parameters:
    `tf` - The TreeFactory used to make all nodes in the copied tree structure
  Returns:
    A Tree that is a deep copy of the tree structure and Labels of the original tree.

### deepCopy

    public Tree deepCopy(TreeFactory tf,
                         LabelFactory lf)

  Makes a deep copy of not only the Tree structure but of the labels as well. Each tree is copied with the given TreeFactory. Each Label is copied using the given LabelFactory. That is, the tree and label factories can transform the nature of the data representation.

  Parameters:
    `tf` - The TreeFactory used to make all nodes in the copied tree structure
    `lf` - The LabelFactory used to make all nodes in the copied tree structure
  Returns:
    A Tree that is a deep copy of the tree structure and Labels of the original tree.

### treeSkeletonCopy

    public Tree treeSkeletonCopy()

  Create a deep copy of the tree structure. The entire structure is recursively copied, but label data themselves are not cloned. The copy is built using a `TreeFactory` that will produce a `Tree` like the input one.

  Returns:
    A deep copy of the tree structure (but not its labels).

### treeSkeletonCopy

    public Tree treeSkeletonCopy(TreeFactory tf)

  Create a deep copy of the tree structure. The entire structure is recursively copied, but label data themselves are not cloned. By specifying an appropriate `TreeFactory`, this method can be used to change the type of a `Tree`.

  Parameters:
    `tf` - The `TreeFactory` to be used for creating the returned `Tree`
  Returns:
    A deep copy of the tree structure (but not its labels).

### transform

    public Tree transform(TreeTransformer transformer)

  Create a transformed Tree. The tree is traversed in a depth-first, left-to-right order, and the `TreeTransformer` is called on each node. It returns some `Tree`. The transformed tree has a new tree structure (i.e., a "deep copy" is done), but it will usually share its labels with the original tree.

  Parameters:
    `transformer` - The function that transforms tree nodes or subtrees
  Returns:
    a transformation of this `Tree`

### transform

    public Tree transform(TreeTransformer transformer,
                          TreeFactory tf)

  Create a transformed Tree. The tree is traversed in a depth-first, left-to-right order, and the `TreeTransformer` is called on each node. It returns some `Tree`. The transformed tree has a new tree structure (i.e., a deep copy of the structure of the tree is done), but it will usually share its labels with the original tree.

  Parameters:
    `transformer` - The function that transforms tree nodes or subtrees
    `tf` - The `TreeFactory` which will be used for creating new nodes for the returned `Tree`
  Returns:
    a transformation of this `Tree`

### spliceOut

    public Tree spliceOut(Filter<Tree> nodeFilter)

  Creates a (partial) deep copy of the tree, where all nodes that the filter does not accept are spliced out. If the result is not a tree (that is, it's a forest), an empty root node is generated.

  Parameters:
    `nodeFilter` - a Filter method which returns true to mean keep this node, false to mean delete it
  Returns:
    a filtered copy of the tree

### spliceOut

    public Tree spliceOut(Filter<Tree> nodeFilter,
                          TreeFactory tf)

  Creates a (partial) deep copy of the tree, where all nodes that the filter does not accept are spliced out. That is, the particular modes for which the `Filter` returns `false` are removed from the `Tree`, but those nodes' children are kept (assuming they pass the `Filter`, and they are added in the appropriate left-to-right ordering as new children of the parent node. If the root node is deleted, so that the result would not be a tree (that is, it's a forest), an empty root node is generated. If nothing is accepted, `null` is returned.

  Parameters:
    `nodeFilter` - a Filter method which returns true to mean keep this node, false to mean delete it
    `tf` - A `TreeFactory` for making new trees. Used if the root node is deleted.
  Returns:
    a filtered copy of the tree.

### prune

    public Tree prune(Filter<Tree> filter)

  Creates a deep copy of the tree, where all nodes that the filter does not accept and all children of such nodes are pruned. If all ' of a node's children are pruned, that node is cut as well. A `Filter` can assume that it will not be called with a `null` argument.

  For example, the following code excises all PP nodes from a Tree: `Filter<Tree> f = new Filter<Tree> { public boolean accept(Tree t) { return ! t.label().value().equals("PP"); } } tree.prune(f);`

  Parameters:
    `filter` - the filter to be apply
  Returns:
    a filtered copy of the tree.

### prune

    public Tree prune(Filter<Tree> filter,
                      TreeFactory tf)

  Creates a deep copy of the tree, where all nodes that the filter does not accept and all children of such nodes are pruned. If all of a node's children are pruned, that node is cut as well. A `Filter` can assume that it will not be called with a `null` argument.

  Parameters:
    `filter` - the filter to be apply
    `tf` - the TreeFactory to be used to make new Tree nodes if needed
  Returns:
    a filtered copy of the tree, including the possibility of `null` if the root node of the tree is filtered

### skipRoot

    public Tree skipRoot()

  Returns first child if it is single and if the label at the current node is either "ROOT" or empty.

### treeFactory

    public abstract TreeFactory treeFactory()

  Return a `TreeFactory` that produces trees of the appropriate type.

  Returns:
    A factory to produce Trees

### parent

    public Tree parent()

  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.

  Returns:
    The parent `Tree` node or `null`
  See Also:
    `parent(Tree)`

### parent

    public Tree parent(Tree root)

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

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

### size

    public int size()

  Returns the number of nodes the tree contains. This method implements the `size()` function required by the `Collections` interface. The size of the tree is the number of nodes it contains (of all types, including the leaf nodes and the root).

  Specified by:
    `size` in interface `Collection<Tree>`
  Specified by:
    `size` in class `AbstractCollection<Tree>`
  Returns:
    The size of the tree
  See Also:
    `depth()`

### ancestor

    public Tree ancestor(int height,
                         Tree root)

  Return the ancestor tree node `height` nodes up from the current node.

  Parameters:
    `height` - How many nodes up to go. A parameter of 0 means return this node, 1 means to return the parent node and so on.
    `root` - The root node that this Tree is embedded under
  Returns:
    The ancestor at height `height`. It returns null if it does not exist or the tree implementation does not keep track of parents

### iterator

    public Iterator<Tree> iterator()

  Returns an iterator over all the nodes of the tree. This method implements the `iterator()` method required by the `Collections` interface. It does a preorder (children after node) traversal of the tree. (A possible extension to the class at some point would be to allow different traversal orderings via variant iterators.)

  Specified by:
    `iterator` in interface `Iterable<Tree>`
  Specified by:
    `iterator` in interface `Collection<Tree>`
  Specified by:
    `iterator` in class `AbstractCollection<Tree>`
  Returns:
    An interator over the nodes of the tree

### postOrderNodeList

    public List<Tree> postOrderNodeList()

### preOrderNodeList

    public List<Tree> preOrderNodeList()

### valueOf

    public static Tree valueOf(String str)
                        throws IOException

  This gives you a tree from a String representation (as a bracketed Tree, of the kind produced by `toString()`, `pennPrint()`, or as in the Penn Treebank). It's not the most efficient thing to do for heavy duty usage. The Tree returned is created by a LabeledScoredTreeReaderFactory.

  Parameters:
    `str` - The tree as a bracketed list in a String.
  Returns:
    The Tree
  Throws:
    `IOException` - If Tree format is not valid

### valueOf

    public static Tree valueOf(String str,
                               TreeReaderFactory trf)
                        throws IOException

  This gives you a tree from a String representation (as a bracketed Tree, of the kind produced by `toString()`, `pennPrint()`, or as in the Penn Treebank. It's not the most efficient thing to do for heavy duty usage.

  Parameters:
    `str` - The tree as a bracketed list in a String.
    `trf` - The TreeFactory used to make the new Tree
  Returns:
    The Tree
  Throws:
    `IOException` - If Tree format is not valid

### getChild

    public Tree getChild(int i)

  Return the child at some daughter index. The children are numbered starting with an index of 0.

  Parameters:
    `i` - The daughter index
  Returns:
    The tree at that daughter index

### removeChild

    public Tree removeChild(int i)

  Destructively removes the child at some daughter index and returns it. Note that this method will throw an `ArrayIndexOutOfBoundsException` if the daughter index is too big for the list of daughters.

  Parameters:
    `i` - The daughter index
  Returns:
    The tree at that daughter index

### addChild

    public void addChild(int i,
                         Tree t)

  Adds the tree t at the index position among the daughters. Note that this method will throw an `ArrayIndexOutOfBoundsException` if the the daughter index is too big for the list of daughters.

  Parameters:
    `i` - the index position at which to add the new daughter
    `t` - the new daughter

### addChild

    public void addChild(Tree t)

  Adds the tree t at the last index position among the daughters.

  Parameters:
    `t` - the new daughter

### setChild

    public Tree setChild(int i,
                         Tree t)

  Replaces the `i`th child of `this` with the tree t. Note that this method will throw an `ArrayIndexOutOfBoundsException` if the child index is too big for the list of children.

  Parameters:
    `i` - The index position at which to replace the child
    `t` - The new child
  Returns:
    The tree that was previously the ith d

### dominates

    public boolean dominates(Tree t)

  Returns true if `this` dominates the Tree passed in as an argument. Object equality (==) rather than .equals() is used to determine domination. t.dominates(t) returns false.

### dominationPath

    public List<Tree> dominationPath(Tree t)

  Returns the path of nodes leading down to a dominated node, including `this` and the dominated node itself. Returns null if t is not dominated by `this`. Object equality (==) is the relevant criterion. t.dominationPath(t) returns null.

### pathNodeToNode

    public List<Tree> pathNodeToNode(Tree t1,
                                     Tree t2)

  Given nodes `t1` and `t2` which are dominated by this node, returns a list of all the nodes on the path from t1 to t2, inclusive, or null if none found.

### joinNode

    public Tree joinNode(Tree t1,
                         Tree t2)

  Given nodes `t1` and `t2` which are dominated by this node, returns their "join node": the node `j` such that `j` dominates both `t1` and `t2`, and every other node which dominates both `t1` and `t2` dominates `j`. In the special case that t1 dominates t2, return t1, and vice versa. Return `null` if no such node can be found.

### cCommands

    public boolean cCommands(Tree t1,
                             Tree t2)

  Given nodes `t1` and `t2` which are dominated by this node, returns `true` iff `t1` c-commands `t2`. (A node c-commands its sister(s) and any nodes below its sister(s).)

### siblings

    public List<Tree> siblings(Tree root)

  Returns the siblings of this Tree node. The siblings are all children of the parent of this node except this node.

  Parameters:
    `root` - The root within which this tree node is contained
  Returns:
    The siblings as a list, an empty list if there are no siblings. The returned list is a modifiable new list structure, but contains the actual children.

### insertDtr

    public void insertDtr(Tree dtr,
                          int position)

  insert `dtr` after `position` existing daughters in `this`.

### value

    public 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`
  Returns:
    the "value" of the label

### setValue

    public void setValue(String value)

  Description copied from interface: `Label`
  Set the value for the label (if one is stored).

  Specified by:
    `setValue` in interface `Label`
  Parameters:
    `value` - - the value for the label

### setFromString

    public void setFromString(String labelStr)

  Description copied from interface: `Label`
  Set the contents of this label to this `String` representing the complete contents of the label. A class implementing label may throw an `UnsupportedOperationException` for this method (only). Typically, this method would do some appropriate decoding of the string in a way that sets multiple fields in an inverse of the `toString()` method.

  Specified by:
    `setFromString` in interface `Label`
  Parameters:
    `labelStr` - the String that translates into the content of the label

### labelFactory

    public LabelFactory labelFactory()

  Returns a factory that makes labels of the same type as this one. May return `null` if no appropriate factory is known.

  Specified by:
    `labelFactory` in interface `Label`
  Returns:
    the LabelFactory for this kind of label

### leftCharEdge

    public int leftCharEdge(Tree node)

  Returns the positional index of the left edge of node within the tree, as measured by characters. Returns -1 if node is not found.

### rightCharEdge

    public int rightCharEdge(Tree node)

  Returns the positional index of the right edge of node within the tree, as measured by characters. Returns -1 if node is not found. rightCharEdge returns the index of the rightmost character + 1, so that rightCharEdge(getLeaves().get(i)) == leftCharEdge(getLeaves().get(i+1))

  Parameters:
    `node` - The subtree to look for in this Tree
  Returns:
    The positional index of the right edge of node

### nodeNumber

    public int nodeNumber(Tree root)

  Calculates the node's number, defined as the number of nodes traversed in a left-to-right, depth-first search of the tree starting at `root` and ending at `this`. Returns -1 if `root` does not contain `this`.

  Parameters:
    `root` - the root node of the relevant tree
  Returns:
    the number of the current node, or -1 if `root` does not contain `this`.

### getNodeNumber

    public Tree getNodeNumber(int i)

  Fetches the `i`th node in the tree, with node numbers defined as in `nodeNumber(Tree)`.

  Parameters:
    `i` - the node number to fetch
  Returns:
    the `i`th node in the tree
  Throws:
    `IndexOutOfBoundsException` - if `i` is not between 1 and the number of nodes (inclusive) contained in `this`.

### indexLeaves

    public void indexLeaves()

  Assign sequential integer indices to the leaves of the tree rooted at this `Tree`, starting with 1. The leaves are traversed from left to right. If the node is already indexed, then it uses the existing index. This will only work if the leaves extend CoreMap.

### indexSpans

    public void indexSpans(int startIndex)

### indexSpans

    public Pair<Integer,Integer> indexSpans(MutableInteger startIndex)

  Assigns span indices (BeginIndexAnnotation and EndIndexAnnotation) to all nodes in a tree. The beginning index is equivalent to the IndexAnnotation of the first leaf in the constituent. The end index is equivalent to the first integer after the IndexAnnotation of the last leaf in the constituent.

  Parameters:
    `startIndex` - Begin indexing at this value

Stanford NLP Group