Class FeedforwardContext

java.lang.Object
opennlp.tools.depparse.FeedforwardContext

final class FeedforwardContext extends Object
The feature template of the feedforward parser for one sentence: a fixed set of configuration positions whose words, tags, and arc labels are embedded and concatenated into the network input, following Chen and Manning (2014).

Positions: the top three stack and buffer items; the leftmost and rightmost dependents of the top two stack items; and the leftmost dependent of the leftmost dependent and rightmost dependent of the rightmost dependent of the top two stack items, capturing second-order structure. Words and tags are read for all positions, labels only for the dependent positions, whose relations are already assigned.

The tokens and tags are resolved to embedding rows once per instance, so extracting the features of a configuration only indexes. An instance holds scratch state for that purpose and is used by one thread for one sentence.

Since:
3.0.0
  • Field Details

    • POSITIONS

      static final int POSITIONS
      The number of positions whose word and tag are embedded.
      See Also:
    • LABEL_POSITIONS

      static final int LABEL_POSITIONS
      The number of dependent positions whose arc label is embedded.
      See Also:
    • FEATURE_COUNT

      static final int FEATURE_COUNT
      The number of features in one parser configuration.
      See Also:
    • FIRST_DEPENDENT_POSITION

      private static final int FIRST_DEPENDENT_POSITION
      The index of the first dependent position; the stack and buffer items precede it.
      See Also:
    • network

      private final FeedforwardNetwork network
    • wordRows

      private final int[] wordRows
    • tagRows

      private final int[] tagRows
    • positions

      private final int[] positions
      Scratch for the token index of every position.
  • Constructor Details

    • FeedforwardContext

      FeedforwardContext(FeedforwardNetwork network, String[] tokens, String[] tags)
      Resolves a sentence against the network vocabularies.
      Parameters:
      network - The network whose rows the features index.
      tokens - The sentence tokens. Must not contain null.
      tags - The part-of-speech tags aligned with tokens. Must not contain null.
  • Method Details

    • featureIds

      int[] featureIds(ArcStandardState state)
      Extracts the embedding rows of a configuration into a new array.
      Parameters:
      state - The configuration to describe.
      Returns:
      POSITIONS word rows, then POSITIONS tag rows, then LABEL_POSITIONS label rows. Never null.
    • featureIds

      void featureIds(ArcStandardState state, int[] features)
      Extracts the embedding rows of a configuration into features: absent positions take the absent-position row of their vocabulary and the artificial root takes the root row.
      Parameters:
      state - The configuration to describe.
      features - Receives the rows in the order of featureIds(ArcStandardState); overwritten. Must have FEATURE_COUNT entries.
    • leftmost

      private static int leftmost(ArcStandardState state, int index)
      Parameters:
      state - The configuration.
      index - The token index of a position, or ArcStandardState.NONE.
      Returns:
      The leftmost dependent of the position, or ArcStandardState.NONE if the position is absent or has no dependent.
    • rightmost

      private static int rightmost(ArcStandardState state, int index)
      Parameters:
      state - The configuration.
      index - The token index of a position, or ArcStandardState.NONE.
      Returns:
      The rightmost dependent of the position, or ArcStandardState.NONE if the position is absent or has no dependent.