Interface Annotation

  • All Superinterfaces:
    CharSequence, Comparable<Span>, HString, Serializable, Span, StringLike

    public interface Annotation
    extends HString

    An annotation is an HString that associates an AnnotationType, e.g. token, sentence, named entity, to a specific span of characters in a document, which may include the entire document. Annotations typically have attributes, e.g. part-of-speech, entity type, etc, and relations, e.g. dependency and co-reference, associated with them. Annotations are assigned a long id when attached to a document, which uniquely identifies it within that document.

    Commonly, annotations have an associated Tag attribute which acts as label. Examples of tags include part-of-speech and entity type. Tags can be retrieved using the getTag() method. Annotation types specify the tag attribute when it is created. Note that an annotation can have multiple attributes that are tags, but the getTag method returns the primary tag as defined by the annotation type.

    Author:
    David B. Bracewell
    • Field Detail

      • DETACHED_ID

        static final long DETACHED_ID
        The ID associated with a detached annotation
        See Also:
        Constant Field Values
    • Method Detail

      • attach

        default void attach()
        Attaches the annotation the document is contained in
      • attribute

        default <T> T attribute​(@NonNull
                                @NonNull AttributeType<T> attributeType)
        Description copied from interface: HString
        Gets the value for a given attribute type
        Specified by:
        attribute in interface HString
        Type Parameters:
        T - the type parameter
        Parameters:
        attributeType - the attribute type
        Returns:
        the value associated with the attribute or null
      • dependency

        default Tuple2<String,​Annotation> dependency()
        Specified by:
        dependency in interface HString
        Returns:
        the outgoing dependency relation and parent for this HString or an tuple of empty string and empty annotation if there is no parent.
      • getId

        long getId()
        Gets the unique id associated with the annotation.
        Returns:
        the id of the annotation that is unique with in its document or Annotation.DETACHED_ID if the annotation is not attached to the document.
      • setId

        void setId​(long id)
        Sets the unique id of the annotation.
        Parameters:
        id - the id
      • getTag

        default Tag getTag()
        Returns:
        The value of the tag attribute for the annotation.
      • getTag

        default Tag getTag​(@NonNull
                           @NonNull Tag defaultTag)
        Gets the tag, if one, associated with the annotation.
        Parameters:
        defaultTag - The default tag if one is not on the annotation
        Returns:
        An optional containing the tag if present
      • getType

        AnnotationType getType()
        Returns:
        the type of the annotation
      • hasTag

        default boolean hasTag()
        Returns:
        True if the annotation has an tag value set, false otherwise
      • isAnnotation

        default boolean isAnnotation()
        Description copied from interface: HString
        Is this HString an annotation?
        Specified by:
        isAnnotation in interface HString
        Returns:
        True if this HString represents an annotation
      • isDetached

        default boolean isDetached()
        Returns:
        True if the annotation is detached, False otherwise
      • isInstance

        default boolean isInstance​(@NonNull
                                   @NonNull AnnotationType type)
        Description copied from interface: HString
        Returns true this HString is an instance of the given annotation type
        Specified by:
        isInstance in interface HString
        Parameters:
        type - the annotation type
        Returns:
        True if this HString is an annotation of the given type
      • next

        default Annotation next()
        Returns:
        The next annotation with the same type as this one or an empty fragment
      • previous

        default Annotation previous()
        Returns:
        The previous annotation with the same type as this one or an empty fragment
      • put

        default <T> T put​(@NonNull
                          @NonNull AttributeType<T> attributeType,
                          T value)
        Description copied from interface: HString
        Sets the value of an attribute. Removes the attribute if the value is null and ignores setting a value if the attribute is null.
        Specified by:
        put in interface HString
        Type Parameters:
        T - the type parameter
        Parameters:
        attributeType - the attribute type
        value - the value
        Returns:
        The old value of the attribute or null
      • tagIsA

        default boolean tagIsA​(@NonNull
                               @NonNull Object tag)
        Determines if this annotation's tag is an instance of the given tag.
        Parameters:
        tag - the tag to check
        Returns:
        True if this annotation's tag is an instance of the given tag.
      • toSGML

        default String toSGML()
      • toSGML

        default String toSGML​(boolean includeConfidence)
      • toTagString

        default String toTagString()
      • toTagString

        default String toTagString​(char delimiter)