Class DependencyTree
java.lang.Object
opennlp.tools.depparse.DependencyTree
- All Implemented Interfaces:
Serializable
An immutable dependency tree over one sentence: for every token, the index of its head
and the label of the relation to that head.
Token indices are zero-based positions in the sentence the tree was built for.
Exactly one token carries the head value DependencyArc.ROOT_HEAD, marking it as
the sentence root. Instances are immutable and safe to share between threads.
- Since:
- 3.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionarcs()booleaninthashCode()intheadOf(int index) Retrieves the head of a token.static DependencyTreeCreates aDependencyTreefrom parallel head and relation arrays.relationOf(int index) Retrieves the relation label of a token.introot()intsize()toString()
-
Method Details
-
of
Creates aDependencyTreefrom parallel head and relation arrays.- Parameters:
heads- For each token, the zero-based index of its head token, orDependencyArc.ROOT_HEADfor the sentence root. Must not benullor empty, every value must be a valid token index orDependencyArc.ROOT_HEAD, no token may head itself, and exactly one token must be the root.relations- For each token, the label of the relation to its head. Must not benull, must have the same length asheads, and no entry may benullor blank.- Returns:
- A validated
DependencyTree. Nevernull. - Throws:
IllegalArgumentException- Thrown if any of the above constraints is violated.
-
size
public int size()- Returns:
- The number of tokens the tree spans.
-
headOf
public int headOf(int index) Retrieves the head of a token.- Parameters:
index- The zero-based token index. Must be within[0, size()).- Returns:
- The zero-based index of the head token, or
DependencyArc.ROOT_HEADwhen the token is the sentence root. - Throws:
IllegalArgumentException- Thrown ifindexis out of range.
-
relationOf
Retrieves the relation label of a token.- Parameters:
index- The zero-based token index. Must be within[0, size()).- Returns:
- The label of the relation between the token and its head. Never
null. - Throws:
IllegalArgumentException- Thrown ifindexis out of range.
-
root
public int root()- Returns:
- The zero-based index of the sentence root token.
-
arcs
- Returns:
- All arcs of the tree in token order, one per token, as a new unmodifiable
list allocated on every call. Never
null.
-
equals
-
hashCode
-
toString
-