Package com.gengoai.hermes
Class AnnotationSet
- java.lang.Object
-
- com.gengoai.hermes.AnnotationSet
-
- All Implemented Interfaces:
Serializable
,Iterable<Annotation>
public class AnnotationSet extends Object implements Iterable<Annotation>, Serializable
An AnnotationSet acts as the storage mechanism for annotations associated with a document. It provides methods for adding, removing, and navigating the annotations. In particular, an it defines sequential methods of accessing annotations (
next(Annotation, AnnotationType)
,previous(Annotation, AnnotationType)
), based on criteriaselect(Predicate)
andselect(Span, Predicate)
*, and by idget(long)
.- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AnnotationSet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Annotation annotation)
Adds an annotation to the setboolean
contains(Annotation annotation)
Checks if an annotation is in the set or notAnnotation
get(long id)
Gets the annotation for the given idString
getAnnotationProvider(AnnotatableType type)
Gets information on what annotator provided the annotation of the given typeSet<AnnotatableType>
getCompleted()
Gets the set of completed annotation types.Map<AnnotatableType,String>
getProviders()
boolean
isCompleted(AnnotatableType type)
Gets if the given annotation type is completed or notIterator<Annotation>
iterator()
Annotation
next(Annotation annotation, AnnotationType type)
Gets the first annotation after a given one of the given typeAnnotation
previous(Annotation annotation, AnnotationType type)
Gets the first annotation before a given one of the given typeboolean
remove(Annotation annotation)
Removes an annotation from the documentList<Annotation>
removeAll(AnnotationType type)
Removes all annotations of a given type and marks that type as not completed.List<Annotation>
select(Span span, Predicate<? super Annotation> criteria)
Selects all annotations of a given annotation type within a given range and matching a given criteria.List<Annotation>
select(Predicate<? super Annotation> criteria)
Selects all annotations of a given annotation type and matching a given criteria.void
setIsCompleted(AnnotatableType type, boolean isCompleted, String annotatorInformation)
Sets the given annotation type as being completed or notint
size()
The number of annotations in the setStream<Annotation>
stream()
String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
add
public boolean add(Annotation annotation)
Adds an annotation to the set- Parameters:
annotation
- The annotation to attach
-
contains
public boolean contains(Annotation annotation)
Checks if an annotation is in the set or not- Parameters:
annotation
- The annotation to check- Returns:
- True if the annotation is in the set, False if not
-
get
public Annotation get(long id)
Gets the annotation for the given id- Parameters:
id
- The id of the annotation- Returns:
- The annotation associated with that id or null if one does not exist
-
getAnnotationProvider
public String getAnnotationProvider(AnnotatableType type)
Gets information on what annotator provided the annotation of the given type- Parameters:
type
- The annotation type- Returns:
- String representing the annotation provider or null
-
getCompleted
public Set<AnnotatableType> getCompleted()
Gets the set of completed annotation types.- Returns:
- Set of classes for completed annotations
-
getProviders
public Map<AnnotatableType,String> getProviders()
-
isCompleted
public boolean isCompleted(AnnotatableType type)
Gets if the given annotation type is completed or not- Parameters:
type
- the annotation type- Returns:
- True if the annotation is completed, False if not.
-
iterator
public Iterator<Annotation> iterator()
- Specified by:
iterator
in interfaceIterable<Annotation>
-
next
public Annotation next(Annotation annotation, AnnotationType type)
Gets the first annotation after a given one of the given type- Parameters:
annotation
- The annotation we want the next fortype
- the type of the next annotation wanted- Returns:
- The next annotation of the same type or null
-
previous
public Annotation previous(Annotation annotation, AnnotationType type)
Gets the first annotation before a given one of the given type- Parameters:
annotation
- The annotation we want the previous fortype
- the type of the previous annotation wanted- Returns:
- The previous annotation of the same type or null
-
remove
public boolean remove(Annotation annotation)
Removes an annotation from the document- Parameters:
annotation
- The annotation to detach- Returns:
- the boolean
-
removeAll
public List<Annotation> removeAll(AnnotationType type)
Removes all annotations of a given type and marks that type as not completed.- Parameters:
type
- the type- Returns:
- The list of annotations that were removed
-
select
public List<Annotation> select(Span span, Predicate<? super Annotation> criteria)
Selects all annotations of a given annotation type within a given range and matching a given criteria.
- Parameters:
span
- the range in which to search form annotationscriteria
- the criteria that an annotation must match- Returns:
- A list of annotations that are an instance of the given class within the given range and matching the given criteria
-
select
public List<Annotation> select(Predicate<? super Annotation> criteria)
Selects all annotations of a given annotation type and matching a given criteria.
- Parameters:
criteria
- the criteria that an annotation must match- Returns:
- A list of annotations that are an instance of the given class and matching the given criteria
-
setIsCompleted
public void setIsCompleted(AnnotatableType type, boolean isCompleted, String annotatorInformation)
Sets the given annotation type as being completed or not- Parameters:
type
- the annotation typeisCompleted
- True if the annotation is completed, False if not.annotatorInformation
- the annotator information
-
size
public int size()
The number of annotations in the set- Returns:
- Number of annotations in the set
-
stream
public Stream<Annotation> stream()
- Returns:
- a stream over the annotations in the set
-
-