Class NameFinderAnnotator

java.lang.Object
opennlp.tools.namefind.NameFinderAnnotator
All Implemented Interfaces:
opennlp.tools.document.DocumentAnnotator

public final class NameFinderAnnotator extends Object implements opennlp.tools.document.DocumentAnnotator
Adapts a TokenNameFinder to the document pipeline: reads Layers.SENTENCES and Layers.TOKENS, maps the finder's token-index spans to character spans on the original text, and provides Layers.ENTITIES. The entity type is carried as the annotation value; the annotation's span carries offsets only.

Each sentence's tokens are passed to TokenNameFinder.find(String[]) as one sequence, the way the finder contract expects its input, so no mention can straddle a sentence boundary. The finder's adaptive data is cleared exactly once per call, as the TokenNameFinder.clearAdaptiveData() contract asks, whether annotation succeeds or fails, so no document can leak finder state into the next one.

Spans the finder returns without a type are recorded with the UNTYPED entity type.

Since:
3.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The entity type recorded when the wrapped finder returns a span without a type.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NameFinderAnnotator(opennlp.tools.namefind.TokenNameFinder finder)
    Initializes the adapter.
  • Method Summary

    Modifier and Type
    Method
    Description
    opennlp.tools.document.Document
    annotate(opennlp.tools.document.Document document)
    Finds names sentence by sentence and adds the Layers.ENTITIES 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

    • UNTYPED

      public static final String UNTYPED
      The entity type recorded when the wrapped finder returns a span without a type. It is NameSample.DEFAULT_TYPE. Type-aware consumers should treat this label as an unknown type rather than as a distinct one, since it carries no information about what kind of entity was found.
      See Also:
  • Constructor Details

    • NameFinderAnnotator

      public NameFinderAnnotator(opennlp.tools.namefind.TokenNameFinder finder)
      Initializes the adapter.
      Parameters:
      finder - The name finder to delegate to. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if finder is null.
  • Method Details

    • annotate

      public opennlp.tools.document.Document annotate(opennlp.tools.document.Document document)
      Finds names sentence by sentence and adds the Layers.ENTITIES layer.

      For every sentence, the tokens whose spans lie inside the sentence span are passed to the finder as one sequence, and each sentence-local mention is mapped through the sentence's first token position onto character spans of the original text. The required layers must be present, but they may be empty: a document without sentences or tokens yields a present-but-empty entity layer, and a sentence containing no tokens contributes nothing. A mention without a type is recorded with the type UNTYPED as the annotation value.

      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.ENTITIES 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 finder returns a mention that is empty or whose token indices lie outside its sentence's tokens.
    • 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