Record Class Annotation<T>

java.lang.Object
java.lang.Record
opennlp.tools.document.Annotation<T>
Type Parameters:
T - The type of the annotation value.
Record Components:
span - The location of the annotation in the original text, or null for a value under a document-scoped key.
value - The annotation value. Must not be null.

public record Annotation<T>(Span span, T value) extends Record
One annotation of a Document: a typed value anchored to a Span of the document's original text, or a span-less value under a document-scoped key.

The span always refers to the text the document was created with, never to a normalized or otherwise derived form, so any annotation can be highlighted in what the caller supplied. Whether a span is present is decided by the layer key's scope, not per annotation: the container rejects a span-less annotation under a positional key and a spanned annotation under a document-scoped key. Annotations that need to reference other annotations, for example a dependency arc naming its head token, do so by the index of the target annotation within its layer, never by object identity.

Since:
3.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    Annotation(Span span, T value)
    Validates the annotation.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    static <T> Annotation<T>
    of(T value)
    Creates a span-less annotation for a document-scoped layer.
    Returns the value of the span record component.
    final String
    Returns a string representation of this record class.
    Returns the value of the value record component.

    Methods inherited from class Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • of

      public static <T> Annotation<T> of(T value)
      Creates a span-less annotation for a document-scoped layer.
      Type Parameters:
      T - The type of the annotation value.
      Parameters:
      value - The annotation value. Must not be null.
      Returns:
      An Annotation without a span. Never null.
      Throws:
      IllegalArgumentException - Thrown if value is null.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • span

      public Span span()
      Returns the value of the span record component.
      Returns:
      the value of the span record component
    • value

      public T value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component