gate
Interface SimpleAnnotationSet

All Superinterfaces:
Cloneable, Collection<Annotation>, Iterable<Annotation>, Serializable, Set<Annotation>
All Known Subinterfaces:
AnnotationSet, EventAwareAnnotationSet
All Known Implementing Classes:
AnnotationSetImpl, ImmutableAnnotationSetImpl

public interface SimpleAnnotationSet
extends Set<Annotation>, Cloneable, Serializable

A set of annotations on a document. Simple annotation sets support creation of new annotations and access to subsets of the annotations in the set by annotation type. 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 get all annotations of a particular type or set of types from the current set. 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.


Method Summary
 boolean add(Annotation a)
          Add an existing annotation, which should be an annotation on this set's document.
 Integer add(Long start, Long end, String type, FeatureMap features)
          Create and add an annotation and return its id.
 Integer add(Node start, Node end, String type, FeatureMap features)
          Create and add an annotation with pre-existing nodes, and return its id.
 AnnotationSet get()
          Get a copy of this annotation set.
 Annotation get(Integer id)
          Find annotations by id
 AnnotationSet get(Set<String> types)
          Select annotations by a set of types.
 AnnotationSet get(String type)
          Select annotations by type.
 Set<String> getAllTypes()
          Get a set of java.lang.String objects representing all the annotation types present in this annotation set.
 Document getDocument()
          Get the document this set is attached to.
 String getName()
          Get the name of this set.
 Iterator<Annotation> iterator()
          Get an iterator for this set
 boolean remove(Object o)
          Remove an element from this set.
 int size()
          Get the size of (i.e. number of annotations in) this set.
 
Methods inherited from interface java.util.Set
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Method Detail

add

Integer add(Node start,
            Node end,
            String type,
            FeatureMap features)
Create and add an annotation with pre-existing nodes, and return its id. The nodes provided must already exist in this set, i.e. they must have been obtained from an existing annotation which is in this set.

Parameters:
start - the start node for the new annotation
end - the end node for the new annotation
type - the annotation type
features - the features for the new annotation
Returns:
the newly generated annotation ID, which will be distinct from all other annotations in this set.

add

Integer add(Long start,
            Long end,
            String type,
            FeatureMap features)
            throws InvalidOffsetException
Create and add an annotation and return its id.

Parameters:
start - the start offset for the new annotation
end - the end offset for the new annotation
type - the annotation type
features - the features for the new annotation
Returns:
the newly generated annotation ID, which will be distinct from all other annotations in this set.
Throws:
InvalidOffsetException - 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.

add

boolean add(Annotation a)
Add an existing annotation, which should be an annotation on this set's document.

Specified by:
add in interface Collection<Annotation>
Specified by:
add in interface Set<Annotation>
Parameters:
a - the annotation to add
Returns:
true if the set was modified by this operation, false otherwise.

iterator

Iterator<Annotation> iterator()
Get an iterator for this set

Specified by:
iterator in interface Collection<Annotation>
Specified by:
iterator in interface Iterable<Annotation>
Specified by:
iterator in interface Set<Annotation>

size

int size()
Get the size of (i.e. number of annotations in) this set.

Specified by:
size in interface Collection<Annotation>
Specified by:
size in interface Set<Annotation>

remove

boolean remove(Object o)
Remove an element from this set.

Specified by:
remove in interface Collection<Annotation>
Specified by:
remove in interface Set<Annotation>
Parameters:
o - the element to remove
Returns:
true if the set was modified by this operation, false otherwise.

get

Annotation get(Integer id)
Find annotations by id

Parameters:
id - the ID to search for
Returns:
the annotation from this set with this ID, or null if there is no annotation with this ID in this set.

get

AnnotationSet get()
Get a copy of this annotation set.

Returns:
a snapshot copy of all annotations in this set. The returned annotation set is immutable.

get

AnnotationSet get(String type)
Select annotations by type.

Parameters:
type - the annotation type to search for.
Returns:
a snapshot copy of all annotations in this set that have the requested type. If there are no annotations of the requested type in this set, an empty set is returned. The returned set is immutable.

get

AnnotationSet get(Set<String> types)
Select annotations by a set of types.

Parameters:
types - the set of annotation types to search for.
Returns:
a snapshot copy of all annotations in this set that have one of the requested types. If there are no annotations of the requested types in this set, an empty set is returned. The returned set is immutable.

getName

String getName()
Get the name of this set.

Returns:
the name of this annotation set, or null if this set does not have a name (i.e. it is the default annotation set for a document, or it is a subset view of another annotation set).

getAllTypes

Set<String> getAllTypes()
Get a set of java.lang.String objects representing all the annotation types present in this annotation set.


getDocument

Document getDocument()
Get the document this set is attached to. Every annotation set must be attached to a document.