|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<Tree>
edu.stanford.nlp.trees.Tree
public abstract class Tree
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.
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 TaggedWord-TaggedWord dependencies, represented as Dependency objects, for the Tree. |
|
Set<Dependency<Label,Label,Object>> |
dependencies(Filter<Dependency<Label,Label,Object>> f)
|
|
Set<Dependency<Label,Label,Object>> |
dependencies(Filter<Dependency<Label,Label,Object>> f,
boolean isConcrete,
boolean copyLabel,
boolean copyPosTag)
Return a set of TaggedWord-TaggedWord 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. |
|
|
getLeaves()
Gets the leaves of the tree. |
|
|
getLeaves(List<T> 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 |
indentedXMLPrint()
Indented xml printing of a tree. |
|
void |
indentedXMLPrint(PrintWriter pw,
boolean printScores)
Indented xml printing of a tree. |
|
void |
indexLeaves()
Assign sequential integer indices to the leaves of the tree rooted at this Tree , starting with 1. |
|
void |
indexLeaves(boolean overWrite)
Index the leaves, and optionally overwrite existing IndexAnnotations if they exist. |
|
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()
|
|
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 |
percolateHeadIndices()
Percolates terminal indices through a dependency tree. |
|
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<? extends 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. |
|
|
subTrees(T n)
Add the set of all subtrees inside a tree (including the tree itself) to the given Collection . |
|
List<CoreLabel> |
taggedLabeledYield()
|
|
ArrayList<TaggedWord> |
taggedYield()
Gets the tagged yield of the tree. |
|
|
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. |
|
|
yield(List<T> y)
Gets the yield of the tree. |
|
|
yieldHasWord()
|
|
|
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 |
---|
public static final Tree[] EMPTY_TREE_ARRAY
public static boolean DISPLAY_SCORES
Constructor Detail |
---|
public Tree()
Method Detail |
---|
public boolean isLeaf()
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.
public int numChildren()
Tree
. Being a leaf is defined
as having no children.
public boolean isUnaryRewrite()
Tree
.
public boolean isPreTerminal()
public boolean isPrePreTerminal()
public boolean isPhrasal()
true
if the node is phrasal;
false
otherwisepublic boolean equals(Object o)
value()
s, the same number of children, and their children
are pairwise equal.
equals
in interface Collection<Tree>
equals
in class Object
o
- The object to compare with
public int hashCode()
hashCode
in interface Collection<Tree>
hashCode
in class Object
public int indexOf(Tree tree)
equals()
.
tree
- The tree to look for in children list
public abstract Tree[] children()
isLeaf()
returns
true, or this node has a nonzero number of children.
getChildrenAsList()
public List<Tree> getChildrenAsList()
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.
public void setChildren(Tree[] children)
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.
children
- The array of children, each a Tree
setChildren(List)
public void setChildren(List<? extends Tree> childTreesList)
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).
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).setChildren(Tree[])
public Label label()
null
.
label
in interface Labeled
public void setLabel(Label label)
setLabel
in interface Labeled
label
- The labelpublic double score()
score
in interface Scored
public void setScore(double score)
score
- The scorepublic Tree firstChild()
null
if none.
public Tree lastChild()
null
if none.
public Tree upperMostUnary(Tree root)
root
- The root of the tree that contains this subtree
public void setSpans()
public IntPair getSpan()
public Set<Constituent> constituents()
Constituent
public Set<Constituent> constituents(ConstituentFactory cf)
cf
- ConstituentFactory used to build the Constituent objects
HashSet
public Set<Constituent> constituents(ConstituentFactory cf, boolean charLevel)
cf
- ConstituentFactory used to build the Constituent objectscharLevel
- If true, compute bracketings irrespective of whitespace boundaries.
HashSet
public Tree localTree()
public Set<Tree> localTrees()
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.
public String toStructureDebugString()
public StringBuilder toStringBuilder(StringBuilder sb)
Appendable
, such as a StringBuffer
.
The implementation of this may be more efficient than for
toString()
on complex trees.
sb
- The StringBuilder
to which the tree will be appended
StringBuilder
passed in with extra stuff in itpublic StringBuilder toStringBuilder(StringBuilder sb, boolean printOnlyLabelValue)
Appendable
, such as a StringBuffer
.
The implementation of this may be more efficient than for
toString()
on complex trees.
sb
- The StringBuilder
to which the tree will be appendedprintOnlyLabelValue
- If true, print only the value() of each node's label
StringBuilder
passed in with extra stuff in itpublic String toString()
Implementation note: Internally, the method gains
efficiency by chaining use of a single StringBuilder
through all the printing.
toString
in interface Label
toString
in class AbstractCollection<Tree>
public void printLocalTree()
public void printLocalTree(PrintWriter pw)
public void indentedListPrint()
public void indentedListPrint(PrintWriter pw, boolean printScores)
pw
- The PrintWriter to print the tree toprintScores
- Whether to print the scores (log probs) of tree nodespublic void indentedXMLPrint()
public void indentedXMLPrint(PrintWriter pw, boolean printScores)
pw
- The PrintWriter to print the tree toprintScores
- Whether to print the scores (log probs) of tree nodespublic String nodeString()
toString()
on the value, if it exists. Otherwise,
an empty string is returned.
public void pennPrint(PrintWriter pw)
pw
- The tree is printed to this PrintWriter
public void pennPrint(PrintStream ps)
ps
- The tree is printed to this PrintStream
public String pennString()
pennPrint()
and saves output to a String
public void pennPrint()
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.
public int depth()
public int depth(Tree node)
node
- A subtree contained in this tree
public Tree headTerminal(HeadFinder hf, Tree parent)
hf
- The head-finding algorithm to useparent
- The parent of this tree
null
public Tree headTerminal(HeadFinder hf)
hf
- The headfinding algorithm to use
null
public Tree headPreTerminal(HeadFinder hf)
isPreTerminal()
for
the definition of a preterminal node. Beware that some tree nodes may
have no preterminal head.
hf
- The headfinding algorithm to use
null
IllegalArgumentException
- if called on a leaf nodepublic void percolateHeads(HeadFinder hf)
hf
- The headfinding algorithm to usepublic Set<Dependency<Label,Label,Object>> dependencies()
public Set<Dependency<Label,Label,Object>> dependencies(Filter<Dependency<Label,Label,Object>> f)
public Set<Dependency<Label,Label,Object>> dependencies(Filter<Dependency<Label,Label,Object>> f, boolean isConcrete, boolean copyLabel, boolean copyPosTag)
f
- Dependencies are excluded for which the Dependency is not
accepted by the Filter
public Set<Dependency<Label,Label,Object>> mapDependencies(Filter<Dependency<Label,Label,Object>> f, HeadFinder hf)
f
- Dependencies are excluded for which the Dependency is not
accepted by the Filterhf
- 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.
Dependency
between two
CyclicCoreLabel
s, which each contain a tag(), word(),
and value(), the last two of which are identical).public Set<Dependency<Label,Label,Object>> mapDependencies(Filter<Dependency<Label,Label,Object>> f, HeadFinder hf, String rootName)
f
- Dependencies are excluded for which the Dependency is not
accepted by the Filterhf
- 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 CoreLabel.rootName
- Name of the root node.
Dependency
between two
CoreLabel
s, which each contain a tag(), word(),
and value(), the last two of which are identical).public ArrayList<Label> yield()
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.
List
of the data in the tree's leaves.public ArrayList<Label> yield(ArrayList<Label> y)
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.
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.
List
of the data in the tree's leaves.public ArrayList<Word> yieldWords()
public ArrayList<Word> yieldWords(ArrayList<Word> y)
public <X extends HasWord> ArrayList<X> yieldHasWord()
public <X extends HasWord> ArrayList<X> yieldHasWord(ArrayList<X> y)
public <T> List<T> yield(List<T> y)
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.
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.
List
of the data in the tree's leaves.public ArrayList<TaggedWord> taggedYield()
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.
List
of the data in the tree's leaves.public List<LabeledWord> labeledYield()
public <X extends List<TaggedWord>> X taggedYield(X ty)
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
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.
List
of the data in the tree's leaves.public List<LabeledWord> labeledYield(List<LabeledWord> ty)
public List<CoreLabel> taggedLabeledYield()
public List<Label> preTerminalYield()
List
of the data in the tree's pre-leaves.public List<Label> preTerminalYield(List<Label> y)
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.
List
of the data in the tree's pre-leaves.public <T extends Tree> List<T> getLeaves()
List
of the leaves.public <T extends Tree> List<T> getLeaves(List<T> list)
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.
List
of the leaves.public Collection<Label> labels()
Label
s,
null or otherwise, contained in the tree.
labels
in interface Labeled
Collection
(actually, Set) of all values
in the tree.public void setLabels(Collection<Label> c)
Labeled
setLabels
in interface Labeled
c
- The set of Label valuespublic Tree flatten()
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.
public Tree flatten(TreeFactory tf)
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.
tf
- TreeFactory used to create tree structure for flattened tree
public Set<Tree> subTrees()
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.
public List<Tree> subTreeList()
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.
public <T extends Collection<Tree>> T subTrees(T n)
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.
public Tree deepCopy()
public Tree deepCopy(TreeFactory tf)
tf
- The TreeFactory used to make all nodes in the copied
tree structure
public Tree deepCopy(TreeFactory tf, LabelFactory lf)
tf
- The TreeFactory used to make all nodes in the copied
tree structurelf
- The LabelFactory used to make all nodes in the copied
tree structure
public Tree treeSkeletonCopy()
TreeFactory
that will
produce a Tree
like the input one.
public Tree treeSkeletonCopy(TreeFactory tf)
TreeFactory
, this
method can be used to change the type of a Tree
.
tf
- The TreeFactory
to be used for creating
the returned Tree
public Tree transform(TreeTransformer transformer)
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.
transformer
- The function that transforms tree nodes or subtrees
Tree
public Tree transform(TreeTransformer transformer, TreeFactory tf)
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.
transformer
- The function that transforms tree nodes or subtreestf
- The TreeFactory
which will be used for creating
new nodes for the returned Tree
Tree
public Tree spliceOut(Filter<Tree> nodeFilter)
nodeFilter
- a Filter method which returns true to mean
keep this node, false to mean delete it
public Tree spliceOut(Filter<Tree> nodeFilter, TreeFactory tf)
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.
nodeFilter
- a Filter method which returns true to mean
keep this node, false to mean delete ittf
- A TreeFactory
for making new trees. Used if
the root node is deleted.
public Tree prune(Filter<Tree> filter)
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
filter
- the filter to be apply
public Tree prune(Filter<Tree> filter, TreeFactory tf)
Filter
can assume
that it will not be called with a null
argument.
filter
- the filter to be applytf
- the TreeFactory to be used to make new Tree nodes if needed
null
if the root node of the tree is filteredpublic Tree skipRoot()
public abstract TreeFactory treeFactory()
TreeFactory
that produces trees of the
appropriate type.
public Tree parent()
null
meaning simply that the implementation doesn't
know how to determine the parent node, rather than there is no
such node.
Tree
node or null
parent(Tree)
public Tree parent(Tree root)
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
.
root
- The root node of the whole Tree
Tree
node if any;
else null
public int size()
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).
size
in interface Collection<Tree>
size
in class AbstractCollection<Tree>
depth()
public Tree ancestor(int height, Tree root)
height
nodes up from the current node.
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
height
. It returns null
if it does not exist or the tree implementation does not keep track
of parentspublic Iterator<Tree> iterator()
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.)
iterator
in interface Iterable<Tree>
iterator
in interface Collection<Tree>
iterator
in class AbstractCollection<Tree>
public List<Tree> postOrderNodeList()
public List<Tree> preOrderNodeList()
public static Tree valueOf(String str)
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.
str
- The tree as a bracketed list in a String.
RuntimeException
- If Tree format is not validpublic static Tree valueOf(String str, TreeReaderFactory trf)
toString()
,
pennPrint()
, or as in the Penn Treebank.
It's not the most efficient thing to do for heavy duty usage.
str
- The tree as a bracketed list in a String.trf
- The TreeFactory used to make the new Tree
RuntimeException
- If the Tree format is not validpublic Tree getChild(int i)
i
- The daughter index
public Tree removeChild(int i)
ArrayIndexOutOfBoundsException
if
the daughter index is too big for the list of daughters.
i
- The daughter index
public void addChild(int i, Tree t)
ArrayIndexOutOfBoundsException
if
the daughter index is too big for the list of daughters.
i
- the index position at which to add the new daughtert
- the new daughterpublic void addChild(Tree t)
t
- the new daughterpublic Tree setChild(int i, Tree t)
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.
i
- The index position at which to replace the childt
- The new child
public boolean dominates(Tree t)
this
dominates the Tree passed in
as an argument. Object equality (==) rather than .equals() is used
to determine domination.
t.dominates(t) returns false.
public List<Tree> dominationPath(Tree t)
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.
public List<Tree> pathNodeToNode(Tree t1, Tree t2)
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.
public Tree joinNode(Tree t1, Tree t2)
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.
public boolean cCommands(Tree t1, Tree t2)
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).)
public List<Tree> siblings(Tree root)
root
- The root within which this tree node is contained
public void insertDtr(Tree dtr, int position)
dtr
after position
existing
daughters in this
.
public String value()
Label
value
in interface Label
public void setValue(String value)
Label
setValue
in interface Label
value
- - the value for the labelpublic void setFromString(String labelStr)
Label
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.
setFromString
in interface Label
labelStr
- the String that translates into the content of the
labelpublic LabelFactory labelFactory()
null
if no appropriate factory is known.
labelFactory
in interface Label
public int leftCharEdge(Tree node)
public int rightCharEdge(Tree node)
node
- The subtree to look for in this Tree
public int nodeNumber(Tree root)
root
and ending at this
. Returns -1 if root
does not contain this
.
root
- the root node of the relevant tree
root
does not contain this
.public Tree getNodeNumber(int i)
i
th node in the tree, with node numbers defined
as in nodeNumber(Tree)
.
i
- the node number to fetch
i
th node in the tree
IndexOutOfBoundsException
- if i
is not between 1 and
the number of nodes (inclusive) contained in this
.public void indexLeaves()
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.
public void indexLeaves(boolean overWrite)
overWrite
- public void percolateHeadIndices()
This method assumes CoreLabels!
public void indexSpans()
public void indexSpans(int startIndex)
public Pair<Integer,Integer> indexSpans(MutableInteger startIndex)
startIndex
- Begin indexing at this value
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |