public interface AnnotationSet extends SimpleAnnotationSet, Serializable
A set of annotations on a document. In addition to the methods
provided by SimpleAnnotationSet
, Annotation sets support
access to subsets of the annotations in the set by various more
complex criteria. Annotation sets are attached to documents - they
cannot be constructed directly, but are obtained via the
getAnnotations
methods of Document
.
This interface provides methods to extract subsets of annotations
from the current set given various constraints. Note that the
annotation sets returned by these get
methods are
immutable snapshots of the set as it was at the time the method was
called. Subsequent changes to the underlying set are not reflected in
the subset view.
This interface extends Set
<Annotation>, so
can be used anywhere a Java Collections Framework Set
or Collection
is required.
Modifier and Type | Method and Description |
---|---|
void |
add(Integer id,
Long start,
Long end,
String type,
FeatureMap features)
Create and add an annotation with a pre-existing ID.
|
void |
addAnnotationSetListener(AnnotationSetListener l) |
void |
addGateListener(GateListener l) |
Node |
firstNode()
Get the node with the smallest offset
|
AnnotationSet |
get(Long offset)
Select annotations by offset.
|
AnnotationSet |
get(Long startOffset,
Long endOffset)
Select annotations by offset.
|
AnnotationSet |
get(String type,
FeatureMap constraints)
Select annotations by type and feature values.
|
AnnotationSet |
get(String type,
FeatureMap constraints,
Long offset)
Select annotations by type, features and offset.
|
AnnotationSet |
get(String type,
Long startOffset,
Long endOffset)
Select annotations by offset and type.
|
AnnotationSet |
get(String type,
Set<? extends Object> featureNames)
Select annotations by type and feature names It returns all
annotations of the given type that have the given set of features,
regardless of their concrete values If the type == null, then
select regardless of type
|
AnnotationSet |
getContained(Long startOffset,
Long endOffset)
Select annotations by offset.
|
AnnotationSet |
getCovering(String neededType,
Long startOffset,
Long endOffset)
Select annotations of the given type that completely span the range.
|
List<Annotation> |
inDocumentOrder()
Return a list of annotations sorted by increasing start offset, i.e.
|
Node |
lastNode()
Get the node with the largest offset
|
Node |
nextNode(Node node)
Get the first node that is relevant for this annotation set and
which has the offset larger than the one of the node provided.
|
void |
removeAnnotationSetListener(AnnotationSetListener l) |
void |
removeGateListener(GateListener l) |
add, add, add, get, get, get, get, getAllTypes, getDocument, getName, getRelations, iterator, remove, size
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
void add(Integer id, Long start, Long end, String type, FeatureMap features) throws InvalidOffsetException
SimpleAnnotationSet.add(Long, Long, String, FeatureMap)
,
which allows the set to assign a unique ID.id
- the ID for the new annotationstart
- the start offset for the new annotationend
- the end offset for the new annotationtype
- the annotation typefeatures
- the features for the new annotationInvalidOffsetException
- if the start or end offsets are
null
, or if the start offset is less than
0 or the end offset is greater than the length of the
document.AnnotationSet get(String type, FeatureMap constraints)
Select annotations by type and feature values. This will return an annotation set containing just those annotations of a particular type which have features with specific names and values. (It will also return annotations that have features besides those specified, but it will not return any annotations that do not have all the specified feature-value pairs.)
However, if constraints contains a feature whose value is equal to
ANNIEConstants.LOOKUP_CLASS_FEATURE_NAME
(which
is normally "class"), then GATE will attempt to match that feature
using an ontology which it will try to retreive from a feature
ANNIEConstants.LOOKUP_ONTOLOGY_FEATURE_NAME
on
both the annotation and in constraints
. If these do
not return identical ontologies, or if either the annotation or
constraints does not contain an ontology, then matching will fail,
and the annotation will not be added. In summary, this method will
not work normally for features with the name "class".
type
- The type of the annotations to return.constraints
- A feature map containing all of the feature
value pairs that the annotation must have in order for
them to be returned.AnnotationSet get(String type, Set<? extends Object> featureNames)
type
- the annotation type to return. If null
then all annotation types are searched.featureNames
- the feature names which an annotation must have
to be matched.AnnotationSet get(String type, FeatureMap constraints, Long offset)
get(Long)
and
get(String, FeatureMap)
, in that it matches annotations
by type and feature constraints but considers only those
annotations that start as close as possible to the right of the
given offset.type
- the annotation type to search forconstraints
- the set of features an annotation must have to
be matchedoffset
- the offset at which to anchor the search.AnnotationSet get(Long offset)
offset
. In other words it finds the first
annotation that starts at or after the given offset and returns all
annotations which start at the same place.offset
- the offset at which to start the search.offset
. The returned set is
immutable.AnnotationSet get(Long startOffset, Long endOffset)
endOffset
and end strictly after
startOffset
.startOffset
- the start of the intervalendOffset
- the end of the intervalAnnotationSet get(String type, Long startOffset, Long endOffset)
get(Long, Long)
and
SimpleAnnotationSet.get(String)
but may admit more
efficient implementation.type
- the annotation type to search forstartOffset
- the start of the intervalendOffset
- the end of the intervalAnnotationSet getCovering(String neededType, Long startOffset, Long endOffset)
neededType
- Type of annotation to return. If empty, all
annotation types will be returned.startOffset
- the start of the intervalendOffset
- the end of the intervalAnnotationSet getContained(Long startOffset, Long endOffset)
startOffset
and whose end position is <= endOffset
.startOffset
- the start of the interval, inclusiveendOffset
- the end of the interval, inclusiveList<Annotation> inDocumentOrder()
Node firstNode()
Node lastNode()
Node nextNode(Node node)
void addAnnotationSetListener(AnnotationSetListener l)
void removeAnnotationSetListener(AnnotationSetListener l)
void addGateListener(GateListener l)
void removeGateListener(GateListener l)
Copyright © 2024 GATE. All rights reserved.