Class AttributeType<T>

  • Type Parameters:
    T - the type parameter
    All Implemented Interfaces:
    AnnotatableType, Tag, Serializable, Cloneable, Comparable<AttributeType<T>>

    public final class AttributeType<T>
    extends EnumValue<AttributeType<T>>
    implements AnnotatableType

    An AttributeType defines a named Attribute that can be added to an HString. Each AttributeType has an associated value type which defines the class of value that the attribute accepts and is specified using Java Generics as follows:

     
        AttributeType<String> AUTHOR = AttributeType.make("AUTHOR", String.class);
        AttributeType<Set<BasicCategories>> CATEGORIES = AttributeType.make("CATEGORIES",
        parameterizedType(Set.class,BasicCategories.class))
     
     

    Annotating for AttributeType adds the attribute and value to an annotation or document. For example, when annotating for the AttributeType PART_OF_SPEECH, each token annotation has a POS value set for its PART_OF_SPEECH attribute of. Many AnnotationType will include attributes when being annotated, e.g. token annotations provide TOKEN_TYPE and CATEGORY attributes.

    Attribute names are normalized, so that an Attribute created with the name partofspeech and one created with the name PartOfSpeech are equal (see EnumValue for normalization information).

    Author:
    David B. Bracewell
    See Also:
    Serialized Form
    • Method Detail

      • isDefined

        public static boolean isDefined​(String name)
        checks if an attribute with the given name is defined
        Parameters:
        name - the name
        Returns:
        True - defined, False otherwise
      • make

        public static <T> AttributeType<T> make​(String name)
        Makes a new or retrieves an existing AttributeType with the given name
        Type Parameters:
        T - the type parameter
        Parameters:
        name - the name of the AttributeType
        Returns:
        the AttributeType
      • make

        public static <T> AttributeType<T> make​(String name,
                                                Type valueType)
        Makes a new or retrieves an existing AttributeType with the given name
        Type Parameters:
        T - the type parameter
        Parameters:
        name - the name of the AttributeType
        valueType - the value type
        Returns:
        the AttributeType
      • make

        public static <T> AttributeType<T> make​(String name,
                                                Class<? extends T> valueType)
        Makes a new or retrieves an existing AttributeType with the given name
        Type Parameters:
        T - the type parameter
        Parameters:
        name - the name of the AttributeType
        valueType - the value type
        Returns:
        the AttributeType
      • valueOf

        public static <T> AttributeType<T> valueOf​(String name)
        Returns the existing AttributeType for the given name throwing an exception if the type is not defined
        Type Parameters:
        T - the type parameter
        Parameters:
        name - the name of the attribute
        Returns:
        the attribute type
      • values

        public static Collection<AttributeType<?>> values()
        Returns:
        the collection of all known AttributeType in the enumeration.
      • decode

        public T decode​(Object o)
        Decodes an object into the correct value type for this Attribute
        Parameters:
        o - the object
        Returns:
        conversion of given object into correct object type for this attribute
      • getValueType

        public Type getValueType()
        Gets class information for the type of values this attribute is expected to have. Types are defined via configuration as follows: Attribute.NAME.type = class. If not defined String.class will be returned.
        Returns:
        The class associated with this attributes values
      • toJson

        public JsonEntry toJson​(Object o)
        Generates JsonEntry for the given object converted ensuring it is the correct type.
        Parameters:
        o - the object to to convert to Json
        Returns:
        the JsonEntry
      • type

        public String type()
        Specified by:
        type in interface AnnotatableType
        Returns:
        The type (Annotation, Attribute, Relation)