Class LayerKey<T>

java.lang.Object
opennlp.tools.document.LayerKey<T>
Type Parameters:
T - The type of the annotation values stored under this key.

public final class LayerKey<T> extends Object
Identifies one annotation layer of a Document and carries the type of that layer's annotation values, so reading a layer back is statically typed.

The key space is deliberately open: any producer may define new keys in its own package, and the container never enumerates them. Two keys are equal when their id, their value type, and their LayerKey.Scope are equal, so independently created constants for the same layer interoperate. Standard keys for the toolkit's own results live in Layers.

A key declares its LayerKey.Scope: a positional key guarantees a span on every annotation, and a document-scoped key carries whole-document values without spans, for example a language id or a category distribution. The scope is declared per key, never per annotation, so consumers of a positional layer never null-check a span.

Since:
3.0.0
  • Method Details

    • of

      public static <T> LayerKey<T> of(String id, Class<T> type)
      Creates a LayerKey.
      Type Parameters:
      T - The type of the annotation values.
      Parameters:
      id - The layer identifier, for example opennlp:tokens. Keys defined by the toolkit carry the opennlp: prefix, an extension uses its own prefix, and a bare id is legal for an application-local layer. Must not be null or blank.
      type - The class of the annotation values stored under the key. Must not be null.
      Returns:
      A positional LayerKey. Never null.
      Throws:
      IllegalArgumentException - Thrown if id is null or blank, or type is null.
    • document

      public static <T> LayerKey<T> document(String id, Class<T> type)
      Creates a document-scoped LayerKey for values that describe the document as a whole, for example a language id, a category distribution, or provenance. Annotations under such a key carry no span.
      Type Parameters:
      T - The type of the annotation values.
      Parameters:
      id - The layer identifier, following the same prefix rules as of(String, Class). Must not be null or blank.
      type - The class of the annotation values stored under the key. Must not be null.
      Returns:
      A document-scoped LayerKey. Never null.
      Throws:
      IllegalArgumentException - Thrown if id is null or blank, or type is null.
    • id

      public String id()
      Returns:
      The layer identifier. Never null.
    • type

      public Class<T> type()
      Returns:
      The class of the annotation values stored under this key. Never null.
    • scope

      public LayerKey.Scope scope()
      Returns:
      The declared scope of the layer. Never null.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object