Package opennlp.tools.depparse
Class DependencyContextGenerator
java.lang.Object
opennlp.tools.depparse.DependencyContextGenerator
Generates the classification features for one arc-standard configuration: words and
tags of the topmost stack and frontmost buffer positions, their pairings, the partial
structure built so far (tags and relations of the leftmost and rightmost dependents,
valency counts), and a bucketed distance between stack top and buffer front.
Instances hold no state and are safe to share between threads.
- Since:
- 3.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringFeature prefix: the first buffer tag.private static final StringFeature prefix: the first buffer word.private static final StringFeature prefix: word and tag of the first buffer position.private static final StringFeature prefix: the second buffer tag.private static final StringFeature prefix: the second buffer word.private static final StringFeature prefix: the third buffer tag.private static final StringFeature prefix: distance between stack top and first buffer position.private static final StringFeature prefix: distance with stack top and first buffer tags.private static final intThe number of featuresgetContext(ArcStandardState, String[], String[])emits.private static final StringThe feature value standing for every distance ofMAX_DISTANCEor more.private static final intDistances at or above this bound share theLONG_DISTANCEfeature value.private static final intValency counts at or above this bound share one feature value.(package private) static final StringThe feature value standing for a position that does not exist.private static final charSeparates the parts of a feature combining several positions.(package private) static final StringThe feature value standing for the artificial root position.private static final StringFeature prefix: dependent count of the stack top.private static final StringFeature prefix: relation of the leftmost dependent of the stack top.private static final StringFeature prefix: tag of the leftmost dependent of the stack top.private static final StringFeature prefix: relation of the rightmost dependent of the stack top.private static final StringFeature prefix: tag of the rightmost dependent of the stack top.private static final StringFeature prefix: the tag on top of the stack.private static final StringFeature prefix: stack top tag with first buffer tag.private static final StringFeature prefix: stack top, first and second buffer tags.private static final StringFeature prefix: stack top tag with first buffer word.private static final StringFeature prefix: stack top tag, its leftmost dependent tag, and first buffer tag.private static final StringFeature prefix: the word on top of the stack.private static final StringFeature prefix: stack top word with first buffer tag.private static final StringFeature prefix: stack top word with first buffer word.private static final StringFeature prefix: word and tag on top of the stack.private static final StringFeature prefix: stack top word and tag with first buffer tag.private static final StringFeature prefix: dependent count of the second stack position.private static final StringFeature prefix: tag of the leftmost dependent of the second stack position.private static final StringFeature prefix: relation of the rightmost dependent of the second stack position.private static final StringFeature prefix: tag of the rightmost dependent of the second stack position.private static final StringFeature prefix: the second stack tag.private static final StringFeature prefix: second stack tag with stack top tag.private static final StringFeature prefix: second stack, stack top and first buffer tags.private static final StringFeature prefix: second stack tag with stack top word.private static final StringFeature prefix: second stack tag, its rightmost dependent tag, and stack top tag.private static final StringFeature prefix: the second stack word.private static final StringFeature prefix: second stack word with stack top tag.private static final StringFeature prefix: word and tag of the second stack position.private static final StringFeature prefix: the third stack tag.private static final StringFeature prefix: the three topmost stack tags.private static final charSeparates a word from the tag of the same position within one feature. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringdependentRelation(ArcStandardState state, int index, boolean leftmost) Looks up the relation of a token's leftmost or rightmost dependent attached so far.private Stringdependents(ArcStandardState state, int index) Counts the dependents a token has been assigned so far.private StringdependentTag(ArcStandardState state, String[] tags, int index, boolean leftmost) Looks up the tag of a token's leftmost or rightmost dependent attached so far.private Stringdistance(int s0, int b0) Buckets the distance between the stack top and the buffer front.(package private) String[]getContext(ArcStandardState state, String[] tokens, String[] tags) Generates the features of the current configuration.private StringLooks up the word or tag at a stack or buffer position.
-
Field Details
-
ROOT_VALUE
The feature value standing for the artificial root position.- See Also:
-
NONE_VALUE
The feature value standing for a position that does not exist.- See Also:
-
WORD_TAG_SEPARATOR
private static final char WORD_TAG_SEPARATORSeparates a word from the tag of the same position within one feature.- See Also:
-
POSITION_SEPARATOR
private static final char POSITION_SEPARATORSeparates the parts of a feature combining several positions.- See Also:
-
FEATURE_COUNT
private static final int FEATURE_COUNTThe number of featuresgetContext(ArcStandardState, String[], String[])emits.- See Also:
-
S0_WORD
Feature prefix: the word on top of the stack.- See Also:
-
S0_TAG
Feature prefix: the tag on top of the stack.- See Also:
-
S1_WORD
Feature prefix: the second stack word.- See Also:
-
S1_TAG
Feature prefix: the second stack tag.- See Also:
-
S2_TAG
Feature prefix: the third stack tag.- See Also:
-
B0_WORD
Feature prefix: the first buffer word.- See Also:
-
B0_TAG
Feature prefix: the first buffer tag.- See Also:
-
B1_WORD
Feature prefix: the second buffer word.- See Also:
-
B1_TAG
Feature prefix: the second buffer tag.- See Also:
-
B2_TAG
Feature prefix: the third buffer tag.- See Also:
-
S0_WORD_TAG
Feature prefix: word and tag on top of the stack.- See Also:
-
S1_WORD_TAG
Feature prefix: word and tag of the second stack position.- See Also:
-
B0_WORD_TAG
Feature prefix: word and tag of the first buffer position.- See Also:
-
S0_WORD_B0_WORD
Feature prefix: stack top word with first buffer word.- See Also:
-
S0_TAG_B0_TAG
Feature prefix: stack top tag with first buffer tag.- See Also:
-
S0_WORD_B0_TAG
Feature prefix: stack top word with first buffer tag.- See Also:
-
S0_TAG_B0_WORD
Feature prefix: stack top tag with first buffer word.- See Also:
-
S0_WORD_TAG_B0_TAG
Feature prefix: stack top word and tag with first buffer tag.- See Also:
-
S1_TAG_S0_TAG
Feature prefix: second stack tag with stack top tag.- See Also:
-
S1_TAG_S0_WORD
Feature prefix: second stack tag with stack top word.- See Also:
-
S1_WORD_S0_TAG
Feature prefix: second stack word with stack top tag.- See Also:
-
S1_TAG_S0_TAG_B0_TAG
Feature prefix: second stack, stack top and first buffer tags.- See Also:
-
S0_TAG_B0_TAG_B1_TAG
Feature prefix: stack top, first and second buffer tags.- See Also:
-
S2_TAG_S1_TAG_S0_TAG
Feature prefix: the three topmost stack tags.- See Also:
-
S0_LEFT_DEPENDENT_TAG
Feature prefix: tag of the leftmost dependent of the stack top.- See Also:
-
S0_RIGHT_DEPENDENT_TAG
Feature prefix: tag of the rightmost dependent of the stack top.- See Also:
-
S1_LEFT_DEPENDENT_TAG
Feature prefix: tag of the leftmost dependent of the second stack position.- See Also:
-
S1_RIGHT_DEPENDENT_TAG
Feature prefix: tag of the rightmost dependent of the second stack position.- See Also:
-
S0_LEFT_DEPENDENT_RELATION
Feature prefix: relation of the leftmost dependent of the stack top.- See Also:
-
S0_RIGHT_DEPENDENT_RELATION
Feature prefix: relation of the rightmost dependent of the stack top.- See Also:
-
S1_RIGHT_DEPENDENT_RELATION
Feature prefix: relation of the rightmost dependent of the second stack position.- See Also:
-
S1_TAG_S1_RIGHT_DEPENDENT_TAG_S0_TAG
Feature prefix: second stack tag, its rightmost dependent tag, and stack top tag.- See Also:
-
S0_TAG_S0_LEFT_DEPENDENT_TAG_B0_TAG
Feature prefix: stack top tag, its leftmost dependent tag, and first buffer tag.- See Also:
-
S0_DEPENDENTS
Feature prefix: dependent count of the stack top.- See Also:
-
S1_DEPENDENTS
Feature prefix: dependent count of the second stack position.- See Also:
-
DISTANCE
Feature prefix: distance between stack top and first buffer position.- See Also:
-
DISTANCE_S0_TAG_B0_TAG
Feature prefix: distance with stack top and first buffer tags.- See Also:
-
MAX_VALENCY
private static final int MAX_VALENCYValency counts at or above this bound share one feature value.- See Also:
-
MAX_DISTANCE
private static final int MAX_DISTANCEDistances at or above this bound share theLONG_DISTANCEfeature value.- See Also:
-
LONG_DISTANCE
The feature value standing for every distance ofMAX_DISTANCEor more.- See Also:
-
-
Constructor Details
-
DependencyContextGenerator
DependencyContextGenerator()
-
-
Method Details
-
getContext
Generates the features of the current configuration.- Parameters:
state- The configuration to describe. Must not benull.tokens- The input tokens. Must satisfy the token contract ofDependencyParser.parse(String[], String[])and match the state.tags- The part-of-speech tags aligned withtokens. Must not benulland must match the state.- Returns:
- The feature strings. Never
null. - Throws:
IllegalArgumentException- Thrown if a parameter is invalid or the arrays do not match the state.
-
valueAt
Looks up the word or tag at a stack or buffer position.- Parameters:
values- The sentence tokens or their part-of-speech tags.index- The token index,ArcStandardState.ROOTorArcStandardState.NONE.- Returns:
- The value, or the marker value for the root and absent positions.
-
dependentTag
Looks up the tag of a token's leftmost or rightmost dependent attached so far.- Parameters:
state- The current configuration.tags- The part-of-speech tags of the sentence.index- The token index, or a negative value for the root and absent positions.leftmost-truefor the leftmost dependent,falsefor the rightmost.- Returns:
- The dependent's tag, or the marker value if there is no such dependent.
-
dependentRelation
Looks up the relation of a token's leftmost or rightmost dependent attached so far.- Parameters:
state- The current configuration.index- The token index, or a negative value for the root and absent positions.leftmost-truefor the leftmost dependent,falsefor the rightmost.- Returns:
- The dependent's relation, or the marker value if there is no such dependent.
-
dependents
Counts the dependents a token has been assigned so far.- Parameters:
state- The current configuration.index- The token index, or a negative value for the root and absent positions.- Returns:
- The count, capped at
MAX_VALENCY, or the marker value for the root and absent positions.
-
distance
Buckets the distance between the stack top and the buffer front.- Parameters:
s0- The token index on top of the stack, negative for the root or none.b0- The token index at the buffer front, negative for none.- Returns:
- The distance,
LONG_DISTANCEatMAX_DISTANCEor more, or the marker value if either position is not a token.
-