Class AttributeType<T>
- java.lang.Object
-
- com.gengoai.EnumValue<AttributeType<T>>
-
- com.gengoai.hermes.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 namePartOfSpeech
are equal (seeEnumValue
for normalization information).- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.gengoai.hermes.AnnotatableType
AnnotatableType.Deserializer, AnnotatableType.KeyDeserializer, AnnotatableType.Serializer
-
-
Field Summary
Fields Modifier and Type Field Description static String
TYPE
Type information for AttributeType-
Fields inherited from interface com.gengoai.hermes.AnnotatableType
ANNOTATOR_PACKAGE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
decode(Object o)
Decodes an object into the correct value type for this AttributeType
getValueType()
Gets class information for the type of values this attribute is expected to have.static boolean
isDefined(String name)
checks if an attribute with the given name is definedstatic <T> AttributeType<T>
make(String name)
Makes a new or retrieves an existing AttributeType with the given namestatic <T> AttributeType<T>
make(String name, Class<? extends T> valueType)
Makes a new or retrieves an existing AttributeType with the given namestatic <T> AttributeType<T>
make(String name, Type valueType)
Makes a new or retrieves an existing AttributeType with the given nameprotected Registry<AttributeType<T>>
registry()
JsonEntry
toJson(Object o)
Generates JsonEntry for the given object converted ensuring it is the correct type.String
type()
static <T> AttributeType<T>
valueOf(String name)
Returns the existing AttributeType for the given name throwing an exception if the type is not definedstatic Collection<AttributeType<?>>
values()
-
Methods inherited from class com.gengoai.EnumValue
canonicalName, clone, compareTo, equals, hashCode, isInstance, main, name, readResolve, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.gengoai.hermes.AnnotatableType
canonicalName, getAnnotator, name
-
Methods inherited from interface com.gengoai.Tag
isInstance, label, parent
-
-
-
-
Field Detail
-
TYPE
public static final String TYPE
Type information for AttributeType- See Also:
- Constant Field Values
-
-
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 AttributeTypevalueType
- 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 AttributeTypevalueType
- 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
-
registry
protected Registry<AttributeType<T>> registry()
- Specified by:
registry
in classEnumValue<AttributeType<T>>
-
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 interfaceAnnotatableType
- Returns:
- The type (Annotation, Attribute, Relation)
-
-