|
|||||||||
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
edu.stanford.nlp.trees.TreeGraphNode
public class TreeGraphNode
A "treegraph" is a tree with additional directed, labeled arcs
between arbitrary pairs of nodes. (So, it's a graph with a tree
skeleton.) A TreeGraphNode
represents any node in a
treegraph. The additional labeled arcs are represented by using
labels at each node, which
contain CyclicCoreLabel
Map
s from arc label strings to
Set
s of TreeGraphNode
s. Each
TreeGraphNode
should contain a reference to a
object, which is a container for
the complete treegraph structure.TreeGraph
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.
TreeGraph
,
Serialized FormField Summary | |
---|---|
protected TreeGraphNode[] |
children
Children of this node. |
protected CyclicCoreLabel |
label
Label for this node. |
protected TreeGraphNode |
parent
Parent of this node. |
protected TreeGraph |
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. |
Fields inherited from class edu.stanford.nlp.trees.Tree |
---|
DISPLAY_SCORES, EMPTY_TREE_ARRAY |
Constructor Summary | |
---|---|
|
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(TreeGraphNode t)
|
|
TreeGraphNode(Tree t,
TreeGraph graph)
Create a new TreeGraphNode having the same tree
structure and label values as an existing tree (but no shared
storage). |
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). |
Method Summary | ||
---|---|---|
|
addArc(Class<GR> arcLabel,
TreeGraphNode node)
Add a labeled arc from this node to the argument node. |
|
Set<Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation>> |
arcLabelsToNode(TreeGraphNode destNode)
Finds all arcs between this node and destNode ,
and returns the Set of Object s which
label those arcs. |
|
Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> |
arcLabelToNode(TreeGraphNode destNode)
Returns the label of a single arc between this node and destNode ,
or null if no such arc exists. |
|
TreeGraphNode[] |
children()
Returns an array of the children of this node. |
|
Set<Dependency<Label,Label,Object>> |
dependencies(Filter<Dependency<Label,Label,Object>> f,
HeadFinder hf)
Return a set of node-node dependencies, represented as Dependency objects, for the Tree. |
|
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 . |
|
TreeGraphNode |
followArcToNode(Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> arcLabel)
Returns a single TreeGraphNode to which there
exists an arc bearing the specified label from this node, or
null if no such node exists. |
|
Set<TreeGraphNode> |
followArcToSet(Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> arcLabel)
Returns the Set of TreeGraphNode s to
which there exist arcs bearing the specified label from this
node, or null if no such nodes exist. |
|
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. |
|
protected void |
indexNodes()
Assign sequential integer indices (starting with 0) to all nodes of the subtree rooted at this TreeGraphNode . |
|
CyclicCoreLabel |
label()
Returns the label associated with the current node, or null if there is no label. |
|
static void |
main(String[] args)
Just for testing. |
|
Tree |
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
CyclicCoreLabel 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(CyclicCoreLabel label)
Sets the label associated with the current node. |
|
void |
setParent(TreeGraphNode parent)
Set the parent for the current node. |
|
protected void |
setTreeGraph(TreeGraph tg)
Set pointer to the TreeGraph 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. |
|
TreeFactory |
treeFactory()
Returns a TreeFactory that produces
TreeGraphNode s. |
|
protected TreeGraph |
treeGraph()
Get the TreeGraph of which this node is a
part. |
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 |
---|
protected CyclicCoreLabel label
protected TreeGraphNode parent
protected TreeGraphNode[] children
protected TreeGraph tg
TreeGraph
of which this
node is part.
protected static final TreeGraphNode[] ZERO_TGN_CHILDREN
Constructor Detail |
---|
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, TreeGraph 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 nodeMethod Detail |
---|
public 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 with
public int hashCode()
Tree
hashCode
in interface Collection<Tree>
hashCode
in class Tree
public CyclicCoreLabel label()
label
in interface Labeled
label
in class Tree
public void setLabel(CyclicCoreLabel label)
label
- the new label to use.public int index()
protected void setIndex(int index)
protected void indexNodes()
TreeGraphNode
. The leaves are indexed first,
from left to right. Then the internal nodes are indexed,
using a pre-order tree traversal.
public Tree parent()
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 TreeGraph treeGraph()
TreeGraph
of which this node is a
part.
protected void setTreeGraph(TreeGraph tg)
TreeGraph
of which this node
is a part. Operates recursively to set pointer for all
descendants too.
public <GR extends GrammaticalRelation.GrammaticalRelationAnnotation> boolean addArc(Class<GR> arcLabel, TreeGraphNode node)
arcLabel
- the Class<? extends GrammaticalRelationAnnotation>
with which the new arc
is to be labeled.node
- the TreeGraphNode
to which the new
arc should point.
true
iff the arc did not already exist.public Set<TreeGraphNode> followArcToSet(Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> arcLabel)
Set
of TreeGraphNode
s to
which there exist arcs bearing the specified label from this
node, or null
if no such nodes exist.
arcLabel
- the Object
which labels the
arc(s) to be followed.
Set
containing only and all the
TreeGraphNode
s to which there exist arcs bearing
the specified label from this node.public TreeGraphNode followArcToNode(Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> arcLabel)
TreeGraphNode
to which there
exists an arc bearing the specified label from this node, or
null
if no such node exists. If more than one
such node exists, this method will return an arbitrary node
from among them; if this is a possibility, you might want to
use followArcToSet
instead.
arcLabel
- a Object
containing the label of
the arc(s) to be followed
TreeGraphNode
to which there exists an
arc bearing the specified label from this nodepublic Set<Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation>> arcLabelsToNode(TreeGraphNode destNode)
destNode
,
and returns the Set
of Object
s which
label those arcs. If no such arcs exist, returns an empty
Set
.
destNode
- the destination node
Set
of Object
s which
label arcs between this node and destNode
public Class<? extends GrammaticalRelation.GrammaticalRelationAnnotation> arcLabelToNode(TreeGraphNode destNode)
destNode
,
or null
if no such arc exists. If more than one
such arc exists, this method will return an arbitrary arc label
from among them; if this is a possibility, you might want to
use arcLabelsToNode
instead.
destNode
- the destination node
Object
which
labels one arc between this node and destNode
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 CyclicCoreLabel
and the
CyclicCoreLabel
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 Set<Dependency<Label,Label,Object>> dependencies(Filter<Dependency<Label,Label,Object>> f, HeadFinder hf)
dependencies
in class Tree
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.f
- Dependencies are excluded for which the Dependency is not
accepted by the Filter
Dependency
)public TreeGraphNode headWordNode()
null
if none), as recorded in this node's CyclicCoreLabel
. (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 CyclicCoreLabel
. (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
CyclicCoreLabel.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 use
public 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.
toString
in interface Label
toString
in class Tree
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |