Class LemmatizerAnnotator

java.lang.Object
opennlp.tools.lemmatizer.LemmatizerAnnotator
All Implemented Interfaces:
opennlp.tools.document.DocumentAnnotator

public final class LemmatizerAnnotator extends Object implements opennlp.tools.document.DocumentAnnotator
Adapts a Lemmatizer to the document pipeline: reads Layers.SENTENCES, Layers.TOKENS, and Layers.POS_TAGS and provides LEMMAS, one annotation per token on the token's span.

Each sentence is lemmatized separately, the way the lemmatizer contract expects its input, so lemmatization decisions never cross a sentence boundary. Token spans already refer to the original document text, so only the token and tag sequences handed to the lemmatizer are sliced per sentence; the produced lemma layer stays aligned with Layers.TOKENS by position.

Since:
3.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final opennlp.tools.document.LayerKey<String>
    The lemma layer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LemmatizerAnnotator(opennlp.tools.lemmatizer.Lemmatizer lemmatizer)
    Initializes the adapter.
  • Method Summary

    Modifier and Type
    Method
    Description
    opennlp.tools.document.Document
    annotate(opennlp.tools.document.Document document)
    Lemmatizes the document sentence by sentence and adds the LEMMAS 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
  • Field Details

    • LEMMAS

      public static final opennlp.tools.document.LayerKey<String> LEMMAS
      The lemma layer. It is aligned with the token layer by position, and each annotation carries the lemma of its token on that token's span.
  • Constructor Details

    • LemmatizerAnnotator

      public LemmatizerAnnotator(opennlp.tools.lemmatizer.Lemmatizer lemmatizer)
      Initializes the adapter.
      Parameters:
      lemmatizer - The lemmatizer to delegate to. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if lemmatizer is null.
  • Method Details

    • annotate

      public opennlp.tools.document.Document annotate(opennlp.tools.document.Document document)
      Lemmatizes the document sentence by sentence and adds the LEMMAS layer.

      For every sentence, the tokens whose spans lie inside the sentence span are lemmatized as one sequence together with their tags, and each lemma 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 lemma 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 and a Layers.POS_TAGS layer with exactly one tag per token, with every token lying inside a sentence.
      Returns:
      A new Document with the LEMMAS layer added. Never null.
      Throws:
      IllegalArgumentException - Thrown if document is null, the sentence layer, the token layer, or the tag layer is absent, the tag layer does not have exactly one tag per token, a token lies outside every sentence, or the lemmatizer does not return one lemma 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