Class POSTaggerAnnotator

java.lang.Object
opennlp.tools.postag.POSTaggerAnnotator
All Implemented Interfaces:
DocumentAnnotator

public final class POSTaggerAnnotator extends Object implements DocumentAnnotator
Adapts a POSTagger to the document pipeline: reads Layers.SENTENCES and Layers.TOKENS and provides Layers.POS_TAGS, one tag annotation per token on the token's span.

Each sentence is tagged separately, the way the tagger contract expects its input, so tagging decisions never cross a sentence boundary. Token spans already refer to the original document text, so only the token sequence handed to the tagger is sliced per sentence; the produced tag layer stays aligned with Layers.TOKENS by position.

The adapter holds no per-call state; it is as thread-safe as the tagger it wraps.

Since:
3.0.0
  • Field Details

  • Constructor Details

    • POSTaggerAnnotator

      public POSTaggerAnnotator(POSTagger tagger)
      Initializes the adapter.
      Parameters:
      tagger - The tagger to delegate to. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if tagger is null.
  • Method Details

    • annotate

      public Document annotate(Document document)
      Tags the document sentence by sentence and adds the Layers.POS_TAGS layer.

      For every sentence, the tokens whose spans lie inside the sentence span are tagged as one sequence, and each tag is emitted on its token's span. The required layers must be present, but they may be empty: a document without sentences or tokens yields a present-but-empty tag layer, and a sentence containing no tokens contributes nothing.

      Specified by:
      annotate in interface DocumentAnnotator
      Parameters:
      document - The document to annotate. Must not be null and must carry the Layers.SENTENCES and Layers.TOKENS layers, with every token lying inside a sentence.
      Returns:
      A new Document with the Layers.POS_TAGS layer added. Never null.
      Throws:
      IllegalArgumentException - Thrown if document is null, the sentence layer or the token layer is absent, a token lies outside every sentence, or the tagger does not return one tag per token of a sentence.
    • requires

      public Set<LayerKey<?>> requires()
      Specified by:
      requires in interface DocumentAnnotator
      Returns:
      The keys of the layers this annotator reads. Never null.
    • provides

      public Set<LayerKey<?>> provides()
      Specified by:
      provides in interface DocumentAnnotator
      Returns:
      The keys of the layers this annotator adds. Never null.
    • toString

      public String toString()
      Returns the adapter's simple class name, which names it in pipeline validation messages.
      Overrides:
      toString in class Object
      Returns:
      the adapter's simple class name, which names it in pipeline validation messages