Class StemmerAnnotator

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

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

Since:
3.0.0
  • Field Summary

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

    Constructors
    Constructor
    Description
    StemmerAnnotator(opennlp.tools.stemmer.Stemmer stemmer)
    Initializes the adapter.
  • Method Summary

    Modifier and Type
    Method
    Description
    opennlp.tools.document.Document
    annotate(opennlp.tools.document.Document document)
    Stems the token layer and adds the STEMS 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

    • STEMS

      public static final opennlp.tools.document.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.
  • Constructor Details

    • StemmerAnnotator

      public StemmerAnnotator(opennlp.tools.stemmer.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 opennlp.tools.document.Document annotate(opennlp.tools.document.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 opennlp.tools.document.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<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