Skip to content

OPENNLP-1919: Expose dependency parses as a typed Document annotation layer - #1237

Draft
krickert wants to merge 9 commits into
OPENNLP-547-dependency-parserfrom
OPENNLP-1919-dependency-annotations
Draft

OPENNLP-1919: Expose dependency parses as a typed Document annotation layer#1237
krickert wants to merge 9 commits into
OPENNLP-547-dependency-parserfrom
OPENNLP-1919-dependency-annotations

Conversation

@krickert

Copy link
Copy Markdown
Contributor

Summary

  • add a DependencyAnnotator over the typed Document API
  • parse each sentence independently and anchor dependency arcs to document token indexes
  • validate graph alignment and emit a typed opennlp:dependencies layer
  • add pipeline, edge-case, contract, and documentation tests

Stack

This draft depends on OPENNLP-547 and OPENNLP-1888. It must remain draft until both dependencies land.

Wires the dependency parser into the document pipeline: reads the token and tag
layers, parses, and provides a dependencies layer with one DependencyArc per token
anchored on the dependent's span. Arc head and dependent are indices into the token
layer, exercising the container rule that annotations reference each other by layer
and index; the test resolves an arc's head through the token layer back to its span
in the original text.

(cherry picked from commit 902fbb3)
… boundaries

The annotator now rejects a parser that returns a graph over a different token
count than its sentence, instead of silently misaligning the dependency layer
with the token layer, and the javadoc states the text-order requirement the
walk has always relied on. New tests pin the empty-sentence index shift, a
token straddling two sentence spans, the stuck-scan path behind a gap token,
and the graph-size rejection. The staged copy of the document container was
refreshed to the current foundation, whose adapters parse per sentence and
whose empty-versus-missing layer distinction moves the empty-text failure into
this annotator's own validation.
…ample

Add a DependencyAnnotator section to the dependency chapter citing DependencyAnnotatorPipelineTest.
Open the CDATA on its own line so the rendered code block has no leading
blank line, matching the two listings above it and parser.xml.
…t cleanup

- Check each required layer for presence on its own, so a document missing the
  sentence, token, or tag layer is rejected with a message that names the key that
  is absent instead of being folded into the alignment complaint.
- Accept present-but-empty required layers: a document with no sentences and no
  tokens now yields a present-but-empty dependencies layer rather than an
  IllegalArgumentException, which is the empty-versus-absent distinction the rest
  of the container annotators already follow.
- Extract the shared rejection prefix into a MISSING_LAYER constant so all three
  absence checks emit one message shape.
- Restate the annotate() javadoc and its @throws list against the checks that are
  actually performed, and say explicitly that the required layers may be empty.
- Trim commentary that only repeated the javadoc: the class-level narration about
  being the first graph-shaped layer, the unwrap-the-slice comment, and the
  document-coordinate tail of the index-shift comment.
- Replace the three hand-rolled absent-layer assertions with a parameterized test
  over one document per required layer, asserting the message names that layer.
- Add pinning tests for the null-document message and for the empty document
  producing a present-but-empty arc layer, and flip the pipeline test on empty
  text to assert the same pass-through instead of a failure.
- Assert the exact message in testMissingLayersThrow rather than only the
  exception type.
- Hoist the one-token parser stub to a ONE_TOKEN_ROOT constant shared by the two
  tests that had declared it inline, and extract the repeated STRAY_TOKEN and
  MISALIGNED expected messages into constants.
- Drop the two docbook sentences that pointed readers at test class names, state
  the present-but-empty layer contract in the annotator section, and correct
  "indexes" to "indices" in the example comment.
krickert added a commit to ai-pipestream/opennlp that referenced this pull request Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant