public class TreeGraphNode extends Tree implements HasParent
A TreeGraphNode
is simply a
with some additional functionality. For example, the
Tree
parent()
method works without searching from the root.
Labels are always assumed to be
CoreLabel
This class makes the horrible mistake of changing the semantics of equals and hashCode to go back to "==" and System.identityHashCode, despite the semantics of the superclass's equality.
Modifier and Type | Field and Description |
---|---|
protected TreeGraphNode[] |
children
Children of this node.
|
protected CoreLabel |
label
Label for this node.
|
protected TreeGraphNode |
parent
Parent of this node.
|
protected GrammaticalStructure |
tg
The
of which this
node is part. |
protected static TreeGraphNode[] |
ZERO_TGN_CHILDREN
A leaf node should have a zero-length array for its
children.
|
EMPTY_TREE_ARRAY
Modifier | Constructor and Description |
---|---|
|
TreeGraphNode()
Create a new empty
TreeGraphNode . |
|
TreeGraphNode(Label label)
Create a new
TreeGraphNode with the supplied
label. |
|
TreeGraphNode(Label label,
List<Tree> children)
Create a new
TreeGraphNode with the supplied
label and list of child nodes. |
|
TreeGraphNode(Tree t,
GrammaticalStructure graph)
Create a new
TreeGraphNode having the same tree
structure and label values as an existing tree (but no shared
storage). |
|
TreeGraphNode(TreeGraphNode t) |
protected |
TreeGraphNode(Tree t,
TreeGraphNode parent)
Create a new
TreeGraphNode having the same tree
structure and label values as an existing tree (but no shared
storage). |
Modifier and Type | Method and Description |
---|---|
TreeGraphNode[] |
children()
Returns an array of the children of this node.
|
boolean |
equals(Object o)
Implements equality for
TreeGraphNode s. |
static TreeFactory |
factory()
Return a
TreeFactory that produces trees of type
TreeGraphNode . |
static TreeFactory |
factory(LabelFactory lf)
Return a
TreeFactory that produces trees of type
TreeGraphNode , with the Label made
by the supplied LabelFactory . |
int |
hashCode()
Implements a hashCode for Tree's.
|
TreeGraphNode |
headTagNode()
Return the node containing the head tag for this node (or
null if none), as recorded in this node's . |
TreeGraphNode |
headWordNode()
Return the node containing the head word for this node (or
null if none), as recorded in this node's . |
TreeGraphNode |
highestNodeWithSameHead()
Checks the node's ancestors to find the highest ancestor with the
same
headWordNode as this node. |
int |
index()
Get the index for the current node.
|
CoreLabel |
label()
Returns the label associated with the current node, or null
if there is no label.
|
static void |
main(String[] args)
Just for testing.
|
TreeGraphNode |
parent()
Get the parent for the current node.
|
void |
percolateHeads(HeadFinder hf)
Uses the specified
to determine the heads for this node and all its descendants,
and to store references to the head word node and head tag node
in this node's and the
CoreLabel s of all its descendants. |
void |
setChildren(List<? extends Tree> childTreesList)
Set the children of this tree node to the given list.
|
void |
setChildren(Tree[] children)
Sets the children of this
TreeGraphNode . |
protected void |
setIndex(int index)
Set the index for the current node.
|
void |
setLabel(CoreLabel label)
Sets the label associated with the current node.
|
void |
setParent(TreeGraphNode parent)
Set the parent for the current node.
|
protected void |
setTreeGraph(GrammaticalStructure tg)
Set pointer to the
GrammaticalStructure of which this node
is a part. |
String |
toOneLineString()
Returns a
String representation of this node and
its subtree as a one-line parenthesized list. |
String |
toPrettyString(int indentLevel)
Returns a
String representation of this node and
its subtree with one node per line, indented according to
indentLevel . |
String |
toPrimes() |
String |
toString()
Converts parse tree to string in Penn Treebank format.
|
String |
toString(CoreLabel.OutputFormat format) |
TreeFactory |
treeFactory()
Returns a
TreeFactory that produces
TreeGraphNode s. |
protected GrammaticalStructure |
treeGraph()
Get the
GrammaticalStructure of which this node is a
part. |
addChild, addChild, ancestor, cCommands, constituents, constituents, constituents, constituents, constituents, deepCopy, deepCopy, deepCopy, dependencies, dependencies, dependencies, depth, depth, dominates, dominationPath, firstChild, flatten, flatten, getChild, getChildrenAsList, getLeaves, getLeaves, getNodeNumber, getSpan, headPreTerminal, headTerminal, headTerminal, indentedListPrint, indentedListPrint, indentedXMLPrint, indentedXMLPrint, indexLeaves, indexLeaves, indexLeaves, indexSpans, indexSpans, indexSpans, insertDtr, isLeaf, isPhrasal, isPrePreTerminal, isPreTerminal, isUnaryRewrite, iterator, joinNode, labeledYield, labeledYield, labelFactory, labels, lastChild, leftCharEdge, localTree, localTrees, mapDependencies, mapDependencies, nodeNumber, nodeString, numChildren, objectIndexOf, parent, pathNodeToNode, pennPrint, pennPrint, pennPrint, pennPrint, pennPrint, pennString, percolateHeadAnnotations, percolateHeadIndices, postOrderNodeList, preOrderNodeList, preTerminalYield, preTerminalYield, printLocalTree, printLocalTree, prune, prune, removeChild, rightCharEdge, score, setChild, setFromString, setLabel, setLabels, setScore, setSpans, setValue, siblings, size, skipRoot, spliceOut, spliceOut, subTreeList, subTrees, subTrees, taggedLabeledYield, taggedYield, taggedYield, toStringBuilder, toStringBuilder, transform, transform, treeSkeletonCopy, treeSkeletonCopy, upperMostUnary, value, valueOf, valueOf, yield, yield, yield, yieldHasWord, yieldHasWord, yieldWords, yieldWords
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
parallelStream, removeIf, spliterator, stream
protected CoreLabel label
protected TreeGraphNode parent
protected TreeGraphNode[] children
protected GrammaticalStructure tg
GrammaticalStructure
of which this
node is part.protected static final TreeGraphNode[] ZERO_TGN_CHILDREN
public TreeGraphNode()
TreeGraphNode
.public TreeGraphNode(Label label)
TreeGraphNode
with the supplied
label.label
- the label for this node.public TreeGraphNode(Label label, List<Tree> children)
TreeGraphNode
with the supplied
label and list of child nodes.label
- the label for this node.children
- the list of child TreeGraphNode
s
for this node.public TreeGraphNode(Tree t, GrammaticalStructure graph)
TreeGraphNode
having the same tree
structure and label values as an existing tree (but no shared
storage).t
- the tree to copygraph
- the graph of which this node is a partpublic TreeGraphNode(TreeGraphNode t)
protected TreeGraphNode(Tree t, TreeGraphNode parent)
TreeGraphNode
having the same tree
structure and label values as an existing tree (but no shared
storage). Operates recursively to construct an entire
subtree.t
- the tree to copyparent
- the parent nodepublic boolean equals(Object o)
TreeGraphNode
s. Unlike
Tree
s, TreeGraphNode
s should be
considered equal only if they are ==. Implementation note:
TODO: This should be changed via introducing a Tree interface with the current Tree and this class implementing it, since what is done here breaks the equals() contract.equals
in interface Collection<Tree>
equals
in class Tree
o
- The object to compare withpublic int hashCode()
Tree
hashCode
in interface Collection<Tree>
hashCode
in class Tree
public CoreLabel label()
public void setLabel(CoreLabel label)
label
- the new label to use.public int index()
protected void setIndex(int index)
public TreeGraphNode parent()
parent
in interface HasParent
parent
in class Tree
Tree
node or null
Tree.parent(Tree)
public void setParent(TreeGraphNode parent)
public TreeGraphNode[] children()
children
in class Tree
Tree.getChildrenAsList()
public void setChildren(Tree[] children)
TreeGraphNode
. If
given null
, this method sets
the node's children to the canonical zero-length Tree[] array.setChildren
in class Tree
children
- an array of child treesTree.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).setChildren
in class Tree
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).Tree.setChildren(Tree[])
protected GrammaticalStructure treeGraph()
GrammaticalStructure
of which this node is a
part.protected void setTreeGraph(GrammaticalStructure tg)
GrammaticalStructure
of which this node
is a part. Operates recursively to set pointer for all
descendants too.public void percolateHeads(HeadFinder hf)
HeadFinder
to determine the heads for this node and all its descendants,
and to store references to the head word node and head tag node
in this node's CoreLabel
and the
CoreLabel
s of all its descendants.Note that, in contrast to
Tree.percolateHeads()
, which assumes CategoryWordTag
labels and therefore stores head
words and head tags merely as String
s, this
method stores references to the actual nodes. This mitigates
potential problems in sentences which contain the same word
more than once.percolateHeads
in class Tree
hf
- The headfinding algorithm to usepublic TreeGraphNode headWordNode()
null
if none), as recorded in this node's CoreLabel
. (In contrast to CategoryWordTag
, we store head words and head
tags as references to nodes, not merely as
String
s.)public TreeGraphNode headTagNode()
null
if none), as recorded in this node's CoreLabel
. (In contrast to CategoryWordTag
, we store head words and head
tags as references to nodes, not merely as
String
s.)public TreeGraphNode highestNodeWithSameHead()
headWordNode
as this node.public TreeFactory treeFactory()
TreeFactory
that produces
TreeGraphNode
s. The Label
of
this
is examined, and providing it is not
null
, a LabelFactory
which will
produce that kind of Label
is supplied to the
TreeFactory
. If the Label
is
null
, a
CoreLabel.factory()
will be used. The factories
returned on different calls are different: a new one is
allocated each time.treeFactory
in class Tree
public static TreeFactory factory()
TreeFactory
that produces trees of type
TreeGraphNode
. The factory returned is always
the same one (a singleton).public static TreeFactory factory(LabelFactory lf)
TreeFactory
that produces trees of type
TreeGraphNode
, with the Label
made
by the supplied LabelFactory
. The factory
returned is a different one each time.lf
- The LabelFactory
to usepublic String toPrettyString(int indentLevel)
String
representation of this node and
its subtree with one node per line, indented according to
indentLevel
.indentLevel
- how many levels to indent (0 for root node)String
representation of this subtreepublic String toOneLineString()
String
representation of this node and
its subtree as a one-line parenthesized list.String
representation of this subtreepublic String toPrimes()
public String toString()
Tree
Implementation note: Internally, the method gains
efficiency by chaining use of a single StringBuilder
through all the printing.
public String toString(CoreLabel.OutputFormat format)
public static void main(String[] args)