Class SentenceDetectorAnnotator

java.lang.Object
opennlp.tools.sentdetect.SentenceDetectorAnnotator
All Implemented Interfaces:
DocumentAnnotator

public final class SentenceDetectorAnnotator extends Object implements DocumentAnnotator
Adapts a SentenceDetector to the document pipeline: provides Layers.SENTENCES from the document text.

The wrapped detector stays the primary API for single-task use; this adapter calls it like any other caller would.

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

Since:
3.0.0
  • Field Details

  • Constructor Details

    • SentenceDetectorAnnotator

      public SentenceDetectorAnnotator(SentenceDetector detector)
      Initializes the adapter.
      Parameters:
      detector - The sentence detector to delegate to. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if detector is null.
  • Method Details

    • annotate

      public Document annotate(Document document)
      Detects sentences over the document text and adds the Layers.SENTENCES layer, each sentence annotated with its covered text on its span.
      Specified by:
      annotate in interface DocumentAnnotator
      Parameters:
      document - The document to annotate. Must not be null.
      Returns:
      A new Document with the Layers.SENTENCES layer added. Never null.
      Throws:
      IllegalArgumentException - Thrown if document is null or already carries the Layers.SENTENCES layer.
    • 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