Class DependencyContextGenerator

java.lang.Object
opennlp.tools.depparse.DependencyContextGenerator

@ThreadSafe class DependencyContextGenerator extends Object
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 Details

    • ROOT_VALUE

      static final String ROOT_VALUE
      The feature value standing for the artificial root position.
      See Also:
    • NONE_VALUE

      static final String NONE_VALUE
      The feature value standing for a position that does not exist.
      See Also:
    • WORD_TAG_SEPARATOR

      private static final char WORD_TAG_SEPARATOR
      Separates a word from the tag of the same position within one feature.
      See Also:
    • POSITION_SEPARATOR

      private static final char POSITION_SEPARATOR
      Separates the parts of a feature combining several positions.
      See Also:
    • FEATURE_COUNT

      private static final int FEATURE_COUNT
      See Also:
    • S0_WORD

      private static final String S0_WORD
      Feature prefix: the word on top of the stack.
      See Also:
    • S0_TAG

      private static final String S0_TAG
      Feature prefix: the tag on top of the stack.
      See Also:
    • S1_WORD

      private static final String S1_WORD
      Feature prefix: the second stack word.
      See Also:
    • S1_TAG

      private static final String S1_TAG
      Feature prefix: the second stack tag.
      See Also:
    • S2_TAG

      private static final String S2_TAG
      Feature prefix: the third stack tag.
      See Also:
    • B0_WORD

      private static final String B0_WORD
      Feature prefix: the first buffer word.
      See Also:
    • B0_TAG

      private static final String B0_TAG
      Feature prefix: the first buffer tag.
      See Also:
    • B1_WORD

      private static final String B1_WORD
      Feature prefix: the second buffer word.
      See Also:
    • B1_TAG

      private static final String B1_TAG
      Feature prefix: the second buffer tag.
      See Also:
    • B2_TAG

      private static final String B2_TAG
      Feature prefix: the third buffer tag.
      See Also:
    • S0_WORD_TAG

      private static final String S0_WORD_TAG
      Feature prefix: word and tag on top of the stack.
      See Also:
    • S1_WORD_TAG

      private static final String S1_WORD_TAG
      Feature prefix: word and tag of the second stack position.
      See Also:
    • B0_WORD_TAG

      private static final String B0_WORD_TAG
      Feature prefix: word and tag of the first buffer position.
      See Also:
    • S0_WORD_B0_WORD

      private static final String S0_WORD_B0_WORD
      Feature prefix: stack top word with first buffer word.
      See Also:
    • S0_TAG_B0_TAG

      private static final String S0_TAG_B0_TAG
      Feature prefix: stack top tag with first buffer tag.
      See Also:
    • S0_WORD_B0_TAG

      private static final String S0_WORD_B0_TAG
      Feature prefix: stack top word with first buffer tag.
      See Also:
    • S0_TAG_B0_WORD

      private static final String S0_TAG_B0_WORD
      Feature prefix: stack top tag with first buffer word.
      See Also:
    • S0_WORD_TAG_B0_TAG

      private static final String S0_WORD_TAG_B0_TAG
      Feature prefix: stack top word and tag with first buffer tag.
      See Also:
    • S1_TAG_S0_TAG

      private static final String S1_TAG_S0_TAG
      Feature prefix: second stack tag with stack top tag.
      See Also:
    • S1_TAG_S0_WORD

      private static final String S1_TAG_S0_WORD
      Feature prefix: second stack tag with stack top word.
      See Also:
    • S1_WORD_S0_TAG

      private static final String S1_WORD_S0_TAG
      Feature prefix: second stack word with stack top tag.
      See Also:
    • S1_TAG_S0_TAG_B0_TAG

      private static final String S1_TAG_S0_TAG_B0_TAG
      Feature prefix: second stack, stack top and first buffer tags.
      See Also:
    • S0_TAG_B0_TAG_B1_TAG

      private static final String S0_TAG_B0_TAG_B1_TAG
      Feature prefix: stack top, first and second buffer tags.
      See Also:
    • S2_TAG_S1_TAG_S0_TAG

      private static final String S2_TAG_S1_TAG_S0_TAG
      Feature prefix: the three topmost stack tags.
      See Also:
    • S0_LEFT_DEPENDENT_TAG

      private static final String S0_LEFT_DEPENDENT_TAG
      Feature prefix: tag of the leftmost dependent of the stack top.
      See Also:
    • S0_RIGHT_DEPENDENT_TAG

      private static final String S0_RIGHT_DEPENDENT_TAG
      Feature prefix: tag of the rightmost dependent of the stack top.
      See Also:
    • S1_LEFT_DEPENDENT_TAG

      private static final String S1_LEFT_DEPENDENT_TAG
      Feature prefix: tag of the leftmost dependent of the second stack position.
      See Also:
    • S1_RIGHT_DEPENDENT_TAG

      private static final String S1_RIGHT_DEPENDENT_TAG
      Feature prefix: tag of the rightmost dependent of the second stack position.
      See Also:
    • S0_LEFT_DEPENDENT_RELATION

      private static final String S0_LEFT_DEPENDENT_RELATION
      Feature prefix: relation of the leftmost dependent of the stack top.
      See Also:
    • S0_RIGHT_DEPENDENT_RELATION

      private static final String S0_RIGHT_DEPENDENT_RELATION
      Feature prefix: relation of the rightmost dependent of the stack top.
      See Also:
    • S1_RIGHT_DEPENDENT_RELATION

      private static final String 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

      private static final String 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

      private static final String 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

      private static final String S0_DEPENDENTS
      Feature prefix: dependent count of the stack top.
      See Also:
    • S1_DEPENDENTS

      private static final String S1_DEPENDENTS
      Feature prefix: dependent count of the second stack position.
      See Also:
    • DISTANCE

      private static final String DISTANCE
      Feature prefix: distance between stack top and first buffer position.
      See Also:
    • DISTANCE_S0_TAG_B0_TAG

      private static final String DISTANCE_S0_TAG_B0_TAG
      Feature prefix: distance with stack top and first buffer tags.
      See Also:
    • MAX_VALENCY

      private static final int MAX_VALENCY
      Valency counts at or above this bound share one feature value.
      See Also:
    • MAX_DISTANCE

      private static final int MAX_DISTANCE
      Distances at or above this bound share the LONG_DISTANCE feature value.
      See Also:
    • LONG_DISTANCE

      private static final String LONG_DISTANCE
      The feature value standing for every distance of MAX_DISTANCE or more.
      See Also:
  • Constructor Details

    • DependencyContextGenerator

      DependencyContextGenerator()
  • Method Details

    • getContext

      String[] getContext(ArcStandardState state, String[] tokens, String[] tags)
      Generates the features of the current configuration.
      Parameters:
      state - The configuration to describe. Must not be null.
      tokens - The input tokens. Must satisfy the token contract of DependencyParser.parse(String[], String[]) and match the state.
      tags - The part-of-speech tags aligned with tokens. Must not be null and 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

      private String valueAt(String[] values, int index)
      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.ROOT or ArcStandardState.NONE.
      Returns:
      The value, or the marker value for the root and absent positions.
    • dependentTag

      private String dependentTag(ArcStandardState state, String[] tags, int index, boolean leftmost)
      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 - true for the leftmost dependent, false for the rightmost.
      Returns:
      The dependent's tag, or the marker value if there is no such dependent.
    • dependentRelation

      private String dependentRelation(ArcStandardState state, int index, boolean leftmost)
      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 - true for the leftmost dependent, false for the rightmost.
      Returns:
      The dependent's relation, or the marker value if there is no such dependent.
    • dependents

      private String dependents(ArcStandardState state, int index)
      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

      private String distance(int s0, int b0)
      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_DISTANCE at MAX_DISTANCE or more, or the marker value if either position is not a token.