Interface Annotation
-
- All Superinterfaces:
CharSequence
,Comparable<Span>
,HString
,Serializable
,Span
,StringLike
public interface Annotation extends HString
An annotation is an
HString
that associates anAnnotationType
, 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 thegetTag()
method. Annotation types specify the tag attribute when it is created. Note that an annotation can have multiple attributes that are tags, but thegetTag
method returns the primary tag as defined by the annotation type.- Author:
- David B. Bracewell
-
-
Field Summary
Fields Modifier and Type Field Description static long
DETACHED_ID
The ID associated with a detached annotation
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
attach()
Attaches the annotation the document is contained indefault <T> T
attribute(@NonNull AttributeType<T> attributeType)
Gets the value for a given attribute typedefault Tuple2<String,Annotation>
dependency()
long
getId()
Gets the unique id associated with the annotation.default Tag
getTag()
default Tag
getTag(@NonNull Tag defaultTag)
Gets the tag, if one, associated with the annotation.AnnotationType
getType()
default boolean
hasTag()
default boolean
isAnnotation()
Is this HString an annotation?default boolean
isDetached()
default boolean
isInstance(@NonNull AnnotationType type)
Returns true this HString is an instance of the given annotation typedefault Annotation
next()
default Annotation
previous()
default <T> T
put(@NonNull AttributeType<T> attributeType, T value)
Sets the value of an attribute.void
setId(long id)
Sets the unique id of the annotation.default boolean
tagIsA(@NonNull Object tag)
Determines if this annotation's tag is an instance of the given tag.default String
toSGML()
default String
toSGML(boolean includeConfidence)
default String
toTagString()
default String
toTagString(char delimiter)
-
Methods inherited from interface java.lang.CharSequence
chars, codePoints, toString
-
Methods inherited from interface com.gengoai.hermes.HString
add, addAll, annotationGraph, annotations, annotations, annotations, annotationStream, annotationStream, asAnnotation, asAnnotation, atBeginningOfSentence, atEndOfSentence, attribute, attributeEquals, attributeIsA, attributeMap, categories, charAt, charNGrams, charNGrams, children, children, computeIfAbsent, context, context, dependencyGraph, dependencyGraph, dependencyIsA, document, embedding, embedding, enclosedAnnotations, enclosedAnnotations, encloses, find, find, findAll, first, firstToken, forEach, getLanguage, getLemma, getMorphologicalFeatures, getStemmedForm, hasAnnotation, hasAttribute, hasIncomingRelation, hasIncomingRelation, hasOutgoingRelation, hasOutgoingRelation, head, ifNotEmpty, incoming, incoming, incoming, incoming, incomingRelations, incomingRelations, incomingRelations, incomingRelations, incomingRelationStream, incomingRelationStream, interleaved, isA, isDocument, last, lastToken, leftContext, leftContext, length, next, outgoing, outgoing, outgoing, outgoing, outgoingRelations, outgoingRelations, outgoingRelations, outgoingRelations, outgoingRelationStream, outgoingRelationStream, overlaps, parent, pos, previous, putAdd, putAll, putAll, putIfAbsent, removeAttribute, removeRelation, rightContext, rightContext, sentence, sentences, sentenceStream, setLanguage, split, startingHere, substring, toDocument, tokenAt, tokenLength, tokens, tokenStream, toPOSString, toPOSString, trim, trimLeft, trimRight, union
-
Methods inherited from interface com.gengoai.collection.tree.Span
compareTo, encloses, end, isEmpty, overlaps, start
-
Methods inherited from interface com.gengoai.string.StringLike
contains, contentEquals, contentEqualsIgnoreCase, endsWith, indexOf, indexOf, matcher, matcher, matches, replace, replaceAll, replaceFirst, startsWith, subSequence, toCharArray, toLowerCase, toUpperCase
-
-
-
-
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
-
dependency
default Tuple2<String,Annotation> dependency()
- Specified by:
dependency
in interfaceHString
- 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 interfaceHString
- 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 interfaceHString
- 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.
-
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)
-
-