public class AnnotationSetImpl extends AbstractSet<Annotation> implements AnnotationSet
There are four indices: annotation by id, annotations by type, annotations by start node and nodes by offset. The last two jointly provide positional indexing; construction of these is triggered by indexByStart(), or by calling a get method that selects on offset. The type index is triggered by indexByType(), or calling a get method that selects on type. The id index is always present.
NOTE: equality and hashCode of this implementation is exclusively based on the annotations which appear in the set (if any). The document the set comes from, the name of the set or the relations stored in that set are not taken into account for equality or hashSet!!
Modifier and Type | Field and Description |
---|---|
protected static AnnotationFactory |
annFactory |
protected Vector<AnnotationSetListener> |
annotationSetListeners |
protected HashMap<Integer,Annotation> |
annotsById
Maps annotation ids (Integers) to Annotations
|
protected Long |
longestAnnot
A caching value that greatly improves the performance of get
methods that have a defined beginning and end.
|
protected RelationSet |
relations |
Constructor and Description |
---|
AnnotationSetImpl(AnnotationSet c)
Construction from an existing AnnotationSet
|
AnnotationSetImpl(Document doc)
Construction from Document.
|
AnnotationSetImpl(Document doc,
String name)
Construction from Document and name.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Annotation a)
Add an existing annotation.
|
void |
add(Integer id,
Long start,
Long end,
String type,
FeatureMap features)
Create and add an annotation from database read data In this case the id is
already known being previously fetched from the database
|
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.
|
boolean |
addAll(Collection<? extends Annotation> c)
Adds multiple annotations to this set in one go.
|
protected boolean |
addAllKeepIDs(Collection<? extends Annotation> c)
Adds multiple annotations to this set in one go.
|
void |
addAnnotationSetListener(AnnotationSetListener l) |
void |
addGateListener(GateListener l) |
void |
clear() |
Object |
clone() |
void |
edit(Long start,
Long end,
DocumentContent replacement)
Propagate document content changes to this AnnotationSet.
|
protected AnnotationSet |
emptyAS() |
protected void |
fireAnnotationAdded(AnnotationSetEvent e) |
protected void |
fireAnnotationRemoved(AnnotationSetEvent e) |
protected void |
fireGateEvent(GateEvent e) |
Node |
firstNode()
Get the node with the smallest offset
|
AnnotationSet |
get()
Get all annotations.
|
Annotation |
get(Integer id)
Find annotations by id
|
AnnotationSet |
get(Long offset)
Select annotations by offset.
|
AnnotationSet |
get(Long startOffset,
Long endOffset)
Select annotations by offset.
|
AnnotationSet |
get(Set<String> types)
Select annotations by a set of types.
|
AnnotationSet |
get(String type)
Select annotations by type
|
AnnotationSet |
get(String type,
FeatureMap constraints)
Select annotations by type and features
This will return an annotation set containing just those annotations of a
particular type (i.e.
|
AnnotationSet |
get(String type,
FeatureMap constraints,
Long offset)
Select annotations by type, features and offset
|
AnnotationSet |
get(String neededType,
Long startOffset,
Long endOffset)
Select annotations by offset.
|
AnnotationSet |
get(String type,
Set<? extends Object> featureNames)
Select annotations by type and feature names
|
Set<String> |
getAllTypes()
Get a set of java.lang.String objects representing all the annotation types
present in this annotation set.
|
AnnotationSet |
getContained(Long startOffset,
Long endOffset)
Select annotations contained within an interval, i.e.
|
AnnotationSet |
getCovering(String neededType,
Long startOffset,
Long endOffset)
Select annotations of the given type that completely span the range.
|
Document |
getDocument()
Get the document this set is attached to.
|
String |
getName()
Get the name of this set.
|
RelationSet |
getRelations() |
AnnotationSet |
getStartingAt(long offset)
Select annotations by offset.
|
AnnotationSet |
getStrict(Long startOffset,
Long endOffset)
Select annotations by offset.
|
protected void |
indexByStartOffset()
Construct the positional indices for annotation start
|
protected void |
indexByType()
Construct the positional index.
|
List<Annotation> |
inDocumentOrder()
Return a list of annotations sorted by increasing start offset, i.e.
|
Iterator<Annotation> |
iterator()
Get an iterator for this set
|
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.
|
boolean |
remove(Object o)
Remove an element from this set.
|
void |
removeAnnotationSetListener(AnnotationSetListener l) |
protected boolean |
removeFromIdIndex(Annotation a)
Remove from the ID index.
|
protected void |
removeFromOffsetIndex(Annotation a)
Remove from the offset indices.
|
protected void |
removeFromTypeIndex(Annotation a)
Remove from the type index.
|
void |
removeGateListener(GateListener l) |
static void |
setAnnotationFactory(AnnotationFactory newFactory)
Set the annotation factory used to create annotation objects.
|
int |
size()
The size of this set
|
equals, hashCode, removeAll
contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
contains, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
protected transient HashMap<Integer,Annotation> annotsById
protected transient Vector<AnnotationSetListener> annotationSetListeners
protected transient Long longestAnnot
protected RelationSet relations
protected static AnnotationFactory annFactory
public AnnotationSetImpl(Document doc)
public AnnotationSetImpl(Document doc, String name)
public AnnotationSetImpl(AnnotationSet c) throws ClassCastException
ClassCastException
public void clear()
clear
in interface Collection<Annotation>
clear
in interface Set<Annotation>
clear
in class AbstractCollection<Annotation>
public Iterator<Annotation> iterator()
iterator
in interface SimpleAnnotationSet
iterator
in interface Iterable<Annotation>
iterator
in interface Collection<Annotation>
iterator
in interface Set<Annotation>
iterator
in class AbstractCollection<Annotation>
public boolean remove(Object o) throws ClassCastException
remove
in interface SimpleAnnotationSet
remove
in interface Collection<Annotation>
remove
in interface Set<Annotation>
remove
in class AbstractCollection<Annotation>
o
- the element to removetrue
if the set was modified by this
operation, false
otherwise.ClassCastException
protected boolean removeFromIdIndex(Annotation a)
protected void removeFromTypeIndex(Annotation a)
protected void removeFromOffsetIndex(Annotation a)
public int size()
size
in interface SimpleAnnotationSet
size
in interface Collection<Annotation>
size
in interface Set<Annotation>
size
in class AbstractCollection<Annotation>
public Annotation get(Integer id)
get
in interface SimpleAnnotationSet
id
- the ID to search fornull
if there is no annotation with this ID
in this set.public AnnotationSet get()
get
in interface SimpleAnnotationSet
public AnnotationSet get(String type)
get
in interface SimpleAnnotationSet
type
- the annotation type to search for.public AnnotationSet get(Set<String> types) throws ClassCastException
get
in interface SimpleAnnotationSet
types
- the set of annotation types to search for.ClassCastException
public AnnotationSet get(String type, FeatureMap constraints)
get
in interface AnnotationSet
type
- The name 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.public AnnotationSet get(String type, Set<? extends Object> featureNames)
get
in interface AnnotationSet
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.public AnnotationSet get(Long offset)
get
in interface AnnotationSet
offset
- the offset at which to start the search.offset
. The returned set is
immutable.public AnnotationSet getStartingAt(long offset)
offset
- The starting offset for which to return annotationspublic List<Annotation> inDocumentOrder()
inDocumentOrder
in interface AnnotationSet
public AnnotationSet get(Long startOffset, Long endOffset)
get
in interface AnnotationSet
startOffset
- the start of the intervalendOffset
- the end of the intervalpublic AnnotationSet getStrict(Long startOffset, Long endOffset)
public AnnotationSet get(String neededType, Long startOffset, Long endOffset)
get
in interface AnnotationSet
neededType
- the annotation type to search forstartOffset
- the start of the intervalendOffset
- the end of the intervalpublic AnnotationSet getCovering(String neededType, Long startOffset, Long endOffset)
getCovering
in interface AnnotationSet
neededType
- Type of annotation to return. If empty, all
annotation types will be returned.startOffset
- the start of the intervalendOffset
- the end of the intervalpublic AnnotationSet get(String type, FeatureMap constraints, Long offset)
get
in interface AnnotationSet
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.public AnnotationSet getContained(Long startOffset, Long endOffset)
startOffset
and whose end position is <=
endOffset
.getContained
in interface AnnotationSet
startOffset
- the start of the interval, inclusiveendOffset
- the end of the interval, inclusivepublic Node firstNode()
firstNode
in interface AnnotationSet
public Node lastNode()
lastNode
in interface AnnotationSet
public Node nextNode(Node node)
nextNode
in interface AnnotationSet
public static void setAnnotationFactory(AnnotationFactory newFactory)
DefaultAnnotationFactory
.public Integer add(Node start, Node end, String type, FeatureMap features)
add
in interface SimpleAnnotationSet
start
- the start node for the new annotationend
- the end node for the new annotationtype
- the annotation typefeatures
- the features for the new annotationpublic boolean add(Annotation a) throws ClassCastException
add
in interface SimpleAnnotationSet
add
in interface Collection<Annotation>
add
in interface Set<Annotation>
add
in class AbstractCollection<Annotation>
a
- the annotation to addtrue
if the set was modified by this
operation, false
otherwise.ClassCastException
public boolean addAll(Collection<? extends Annotation> c)
Annotation
type, otherwise a
ClassCastException will be thrown. The provided annotations will be used to
create new annotations using the appropriate add() methods from this set.
The new annotations will have different IDs from the old ones (which is
required in order to preserve the uniqueness of IDs inside an annotation
set).addAll
in interface Collection<Annotation>
addAll
in interface Set<Annotation>
addAll
in class AbstractCollection<Annotation>
c
- a collection of annotationsprotected boolean addAllKeepIDs(Collection<? extends Annotation> c)
Annotation
type, otherwise a
ClassCastException will be thrown. This method does not create copies of
the annotations like addAll() does but simply adds the new annotations to
the set. It is intended to be used solely by annotation sets in order to
construct the results for various get(...) methods.c
- a collection of annotationspublic Integer add(Long start, Long end, String type, FeatureMap features) throws InvalidOffsetException
add
in interface SimpleAnnotationSet
start
- 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.public void add(Integer id, Long start, Long end, String type, FeatureMap features) throws InvalidOffsetException
add
in interface AnnotationSet
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.protected void indexByType()
protected void indexByStartOffset()
public void edit(Long start, Long end, DocumentContent replacement)
GateConstants.DOCEDIT_INSERT_PREPEND
:
annotations immediately
ending before or starting after the point of insertion will either become
part of the inserted text or not. Currently it works like this:
GateConstants.DOCEDIT_INSERT_APPEND
but
this setting does currently not influence the behaviour of this method.
The behaviour of this method may change in the future so that
DOCEDIT_INSERT_APPEND is considered separately and in addition to
DOCEDIT_INSERT_PREPEND so that it can be controlled independently if
the annotation before and/or after an insertion point gets expanded or not.
NOTE 2: This method has, unfortunately, to be public, to allow DocumentImpls to get at it. Oh for a "friend" declaration. Doesn't throw InvalidOffsetException as DocumentImpl is the only client, and that checks the offsets before calling this method.
public String getName()
getName
in interface SimpleAnnotationSet
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).public Document getDocument()
getDocument
in interface SimpleAnnotationSet
public Set<String> getAllTypes()
getAllTypes
in interface SimpleAnnotationSet
public Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public void removeAnnotationSetListener(AnnotationSetListener l)
removeAnnotationSetListener
in interface AnnotationSet
public void addAnnotationSetListener(AnnotationSetListener l)
addAnnotationSetListener
in interface AnnotationSet
protected void fireAnnotationAdded(AnnotationSetEvent e)
protected void fireAnnotationRemoved(AnnotationSetEvent e)
public void removeGateListener(GateListener l)
removeGateListener
in interface AnnotationSet
public void addGateListener(GateListener l)
addGateListener
in interface AnnotationSet
protected void fireGateEvent(GateEvent e)
public RelationSet getRelations()
getRelations
in interface SimpleAnnotationSet
protected AnnotationSet emptyAS()
Copyright © 2024 GATE. All rights reserved.