Class StemmerAnnotator

java.lang.Object
opennlp.tools.stemmer.StemmerAnnotator
All Implemented Interfaces:
DocumentAnnotator

public final class StemmerAnnotator extends Object implements DocumentAnnotator
Adapts a Stemmer to the document pipeline: stems the token layer and provides STEMS, one annotation per token on the token's span.

Stemming operates on the token surface alone, so this annotator requires only the token layer; no part-of-speech tags are involved.

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

Since:
3.0.0
  • Field Details

    • STEMS

      public static final LayerKey<String> STEMS
      The stem layer. It is aligned with the token layer by position, and each annotation carries the stem of its token on that token's span.
    • stemmer

      private final Stemmer stemmer
  • Constructor Details

    • StemmerAnnotator

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

    • annotate

      public Document annotate(Document document)
      Stems the token layer and adds the STEMS layer.

      The token layer must be present, but it may be empty: a document without tokens yields a present-but-empty stem layer.

      Specified by:
      annotate in interface DocumentAnnotator
      Parameters:
      document - The document to annotate. Must not be null and must carry the Layers.TOKENS layer.
      Returns:
      A new Document with the STEMS layer added. Never null.
      Throws:
      IllegalArgumentException - Thrown if document is null or the token layer is absent.
    • 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