Class POSTaggerAnnotator

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

public final class POSTaggerAnnotator extends Object implements opennlp.tools.document.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.

Since:
3.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    POSTaggerAnnotator(opennlp.tools.postag.POSTagger tagger)
    Initializes the adapter.
  • Method Summary

    Modifier and Type
    Method
    Description
    opennlp.tools.document.Document
    annotate(opennlp.tools.document.Document document)
    Tags the document sentence by sentence and adds the Layers.POS_TAGS layer.
    Set<opennlp.tools.document.LayerKey<?>>
    Set<opennlp.tools.document.LayerKey<?>>
    Returns the adapter's simple class name, which names it in pipeline validation messages.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • POSTaggerAnnotator

      public POSTaggerAnnotator(opennlp.tools.postag.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 opennlp.tools.document.Document annotate(opennlp.tools.document.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 opennlp.tools.document.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<opennlp.tools.document.LayerKey<?>> requires()
      Specified by:
      requires in interface opennlp.tools.document.DocumentAnnotator
    • provides

      public Set<opennlp.tools.document.LayerKey<?>> provides()
      Specified by:
      provides in interface opennlp.tools.document.DocumentAnnotator
    • 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