Class NameFinderAnnotator
- All Implemented Interfaces:
opennlp.tools.document.DocumentAnnotator
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 -
Constructor Summary
ConstructorsConstructorDescriptionNameFinderAnnotator(opennlp.tools.namefind.TokenNameFinder finder) Initializes the adapter. -
Method Summary
Modifier and TypeMethodDescriptionopennlp.tools.document.Documentannotate(opennlp.tools.document.Document document) Finds names sentence by sentence and adds theLayers.ENTITIESlayer.Set<opennlp.tools.document.LayerKey<?>> provides()Set<opennlp.tools.document.LayerKey<?>> requires()toString()Returns the adapter's simple class name, which names it in pipeline validation messages.
-
Field Details
-
UNTYPED
The entity type recorded when the wrapped finder returns a span without a type. It isNameSample.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 benull.- Throws:
IllegalArgumentException- Thrown iffinderisnull.
-
-
Method Details
-
annotate
public opennlp.tools.document.Document annotate(opennlp.tools.document.Document document) Finds names sentence by sentence and adds theLayers.ENTITIESlayer.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
UNTYPEDas the annotation value.- Specified by:
annotatein interfaceopennlp.tools.document.DocumentAnnotator- Parameters:
document- The document to annotate. Must not benulland must carry theLayers.SENTENCESandLayers.TOKENSlayers, with every token lying inside a sentence.- Returns:
- A new
Documentwith theLayers.ENTITIESlayer added. Nevernull. - Throws:
IllegalArgumentException- Thrown ifdocumentisnull, 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
- Specified by:
requiresin interfaceopennlp.tools.document.DocumentAnnotator
-
provides
- Specified by:
providesin interfaceopennlp.tools.document.DocumentAnnotator
-
toString
-