Class Layers

java.lang.Object
opennlp.tools.document.Layers

public final class Layers extends Object
The standard layer keys for the results the toolkit produces itself.

This class is a convenience, not a registry: the key space stays open, and any producer may define further keys in its own package. New capabilities must never require an addition here to function.

Namespace rule: every key the toolkit itself defines carries the opennlp: id prefix. An extension defines its keys under its own prefix, and a bare id without a prefix is legal for an application-local layer, so ids from independent producers cannot collide. Toolkit keys are created through key(String, Class) and documentKey(String, Class), which apply the prefix, so no producer spells it.

Gold versus predicted: a corpus may carry a hand-annotated version of a layer beside a produced one. The convention is a gold: id prefix on the same key scheme, for example gold:opennlp:tokens beside opennlp:tokens. Because adding a layer is once-only, competing versions of a layer always live under distinct keys and never replace each other.

Placement rule: this class holds only the keys of the core linguistic layers every pipeline shares (sentences, tokens, tags, entities). A capability-specific layer's key lives on the annotator that provides it, for example the lemma layer's key on its adapter, so adding a capability never touches this class.

Since:
3.0.0
  • Field Details

    • SENTENCES

      public static final LayerKey<String> SENTENCES
      Sentence boundaries; each annotation covers one sentence and carries its text.
    • TOKENS

      public static final LayerKey<String> TOKENS
      Token boundaries; each annotation covers one token and carries its text.
    • POS_TAGS

      public static final LayerKey<String> POS_TAGS
      Part-of-speech tags; one annotation per token, aligned with TOKENS by position, carrying the tag.
    • ENTITIES

      public static final LayerKey<String> ENTITIES
      Named entities; each annotation covers one mention and carries the entity type as its value. The annotation's span carries offsets only.
  • Method Details

    • key

      public static <T> LayerKey<T> key(String name, Class<T> type)
      Creates a positional key in the toolkit's opennlp: namespace, for a layer the toolkit itself produces.
      Type Parameters:
      T - The type of the annotation values.
      Parameters:
      name - The layer name without a namespace, for example tokens. Must not be null, blank, or contain ':'.
      type - The class of the annotation values stored under the key. Must not be null.
      Returns:
      A key whose id is the name under the opennlp: prefix. Never null.
      Throws:
      IllegalArgumentException - Thrown if name is null, blank, or contains ':', or type is null.
    • documentKey

      public static <T> LayerKey<T> documentKey(String name, Class<T> type)
      Creates a document-scoped key in the toolkit's opennlp: namespace, for a whole-document value the toolkit itself produces.
      Type Parameters:
      T - The type of the annotation values.
      Parameters:
      name - The layer name without a namespace, for example language. Must not be null, blank, or contain ':'.
      type - The class of the annotation values stored under the key. Must not be null.
      Returns:
      A document-scoped key whose id is the name under the opennlp: prefix. Never null.
      Throws:
      IllegalArgumentException - Thrown if name is null, blank, or contains ':', or type is null.