public class AnnotationIndexImpl<T extends AnnotationFS> extends Object implements AnnotationIndex<T>
BAG_INDEX, DEFAULT_BAG_INDEX, SET_INDEX, SORTED_INDEX| Constructor and Description |
|---|
AnnotationIndexImpl(FSIndex<T> index) |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(FeatureStructure fs1,
FeatureStructure fs2)
Compare two feature structures according to the ordering relation of the index.
|
boolean |
contains(FeatureStructure fs)
Check if the index contains an element equal to the given feature structure
according to the comparators defined for this index.
|
FeatureStructure |
find(FeatureStructure fs)
Find an entry in the index "equal to" the given feature structure according to the comparators specified
for this index.
|
int |
getIndexingStrategy()
Return the indexing strategy.
|
Type |
getType()
Return the type of feature structures this index contains.
|
FSIterator<T> |
iterator()
Return an iterator over the index.
|
FSIterator<T> |
iterator(boolean ambiguous)
Return an iterator over annotations that can be constrained to be unambiguous.
|
FSIterator<T> |
iterator(FeatureStructure fs)
Return an iterator over the index.
|
int |
size()
Return the number of feature structures in this index.
|
FSIterator<T> |
subiterator(AnnotationFS annot)
Return a subiterator whose bounds are defined by the input annotation.
|
FSIterator<T> |
subiterator(AnnotationFS annot,
boolean ambiguous,
boolean strict)
Return a subiterator whose bounds are defined by the
annot. |
AnnotationTree<T> |
tree(T annot)
Create an annotation tree with
annot as root node. |
FSIndex<T> |
withSnapshotIterators()
Creates a shared copy of this FSIndex configured to produce snapshot iterators
that don't throw ConcurrentModificationExceptions.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic int size()
FSIndexsize in interface FSIndex<T extends AnnotationFS>public Type getType()
FSIndexgetType in interface FSIndex<T extends AnnotationFS>public boolean contains(FeatureStructure fs)
FSIndexcontains in interface FSIndex<T extends AnnotationFS>fs - A Feature Structure used a template to match for equality with the
FSs in the index.true if the index contains such an element.public FeatureStructure find(FeatureStructure fs)
FSIndexfind in interface FSIndex<T extends AnnotationFS>fs - A Feature Structure used a template to match with the Feature Structures in the index.null if no such FS exists.FSIterator.moveTo(FeatureStructure)public int compare(FeatureStructure fs1, FeatureStructure fs2)
FSIndexcompare in interface FSIndex<T extends AnnotationFS>fs1 - the first Feature Structure to comparefs2 - the second Feature Structure to compare-1 if fs1 < fs2; 0 if
fs1 = fs2; 1 else.public FSIterator<T> iterator()
FSIndexiterator in interface Iterable<T extends AnnotationFS>iterator in interface FSIndex<T extends AnnotationFS>public FSIterator<T> iterator(FeatureStructure fs)
FSIndexget() method is
greater than or equal to fs, and any previous FS is less than FS
(the iterator is positioned at the earliest of equal values).
If no such position exists, the iterator will be invalid.iterator in interface FSIndex<T extends AnnotationFS>fs - The feature structure at which the iterator should be positioned.fs, if it exists. An invalid iterator, else.public int getIndexingStrategy()
FSIndexgetIndexingStrategy in interface FSIndex<T extends AnnotationFS>SORTED_INDEX, BAG_INDEX or SET_INDEX.public FSIterator<T> iterator(boolean ambiguous)
AnnotationIndex
A disambiguated iterator is defined as follows. The first annotation returned is the same as
would be returned by the corresponding ambiguous iterator. If the unambiguous iterator has
returned a previously, it will next return the smallest b s.t. a < b and a.getEnd() <=
b.getBegin(). In other words, the b annotation's start will be large enough to not
overlap the span of a.
An unambiguous iterator makes a snapshot copy of the index containing just the disambiguated items, and iterates over that. It doesn't check for concurrent index modifications (the ambiguous iterator does check for this).
iterator in interface AnnotationIndex<T extends AnnotationFS>ambiguous - If set to false, iterator will be unambiguous.public FSIterator<T> subiterator(AnnotationFS annot)
AnnotationIndex
The annot is used for 3 purposes:
The starting position is computed by first finding a position
whose annotation compares equal with the annot (this might be one of several), and then
advancing until reaching a position where the annotation there is not equal to the
annot.
If no item in the index is equal (meaning it has the same begin, the same end, and is the same type
as the annot)
then the iterator is positioned to the first annotation
which is greater than the annot, or
if there are no annotations greater than the annot, the iterator is marked invalid.
The iterator will stop (become invalid) when
annot's end position, orWhile iterating, it operates like a strict iterator;
annotations whose end positions are > the end position of annot are skipped.
This is equivalent to returning annotations b such that
annot < b, andannot.getEnd() >= b.getBegin(), skipping b's
whose end position is > annot.getEnd().For annotations x, y, x < y
here is to be interpreted as "x comes before y in the index", according to the rules defined in
the description of this class.
This definition implies that annotations b that have the same span as
annot may or may not be returned by the subiterator. This is determined by the
type priorities; the subiterator will only return such an annotation b if the
type of annot precedes the type of b in the type priorities
definition. If you have not specified the priority, or if annot and
b are of the same type, then the behavior is undefined.
For example, if you have an annotation S of type Sentence and an
annotation P of type Paragraph that have the same span, and you
have defined Paragraph before Sentence in your type priorities,
then subiterator(P) will give you an iterator that will return S,
but subiterator(S) will give you an iterator that will NOT return P.
The intuition is that a Paragraph is conceptually larger than a Sentence, as defined by the
type priorities.
Calling subiterator(a) is equivalent to calling
subiterator(a, true, true).. See
subiterator(AnnotationFS, boolean, boolean).
subiterator in interface AnnotationIndex<T extends AnnotationFS>annot - Defines the boundaries of the subiterator.public FSIterator<T> subiterator(AnnotationFS annot, boolean ambiguous, boolean strict)
AnnotationIndexannot.
The annot is used in 2 or 3 ways.
strict is specified, the end point also specifies which annotations
will be skipped while iterating.The starting position is computed by first finding the position
whose annotation compares equal with the annot, and then
advancing until reaching a position where the annotation there is not equal to the
annot.
If no item in the index is equal (meaning it has the same begin, the same end, and is the same type
as the annot)
then the iterator is positioned to the first annotation
which is greater than the annot, or
if there are no annotations greater than the annot, the iterator is marked invalid.
The iterator will stop (become invalid) when
annot's end position, orIgnoring strict and ambiguous for a moment,
this is equivalent to returning annotations b such that
annot < b using the standard annotation comparator, andannot.getEnd() >= b.getBegin(), and also bounded by the index itself.
A strict subiterator skips annotations where
annot.getEnd() < b.getEnd().
A ambiguous = false specification produces an unambiguous iterator, which
computes a subset of the annotations, going forward, such that annotations whose begin
is contained within the previous returned annotation's span, are skipped.
For annotations x,y, x < y
here is to be interpreted as "x comes before y in the index", according to the rules defined in
the description of this class.
If strict = true then annotations whose end is > annot.getEnd()
are skipped.
These definitions imply that annotations b that have the same span as
annot may or may not be returned by the subiterator. This is determined by the
type priorities; the subiterator will only return such an annotation b if the
type of annot precedes the type of b in the type priorities
definition. If you have not specified the priority, or if annot and
b are of the same type, then the behavior is undefined.
For example, if you have an annotation S of type Sentence and an
annotation P of type Paragraph that have the same span, and you
have defined Paragraph before Sentence in your type priorities,
then subiterator(P) will give you an iterator that will return S,
but subiterator(S) will give you an iterator that will NOT return P.
The intuition is that a Paragraph is conceptually larger than a Sentence, as defined by the
type priorities.
subiterator in interface AnnotationIndex<T extends AnnotationFS>annot - Annotation setting boundary conditions for subiterator.ambiguous - If set to false, resulting iterator will be unambiguous.strict - Controls if annotations that overlap to the right are considered in or out.public AnnotationTree<T> tree(T annot)
AnnotationIndexannot as root node. The tree is defined as
follows: for each node in the tree, the children are the sequence of annotations that would be
obtained from a strict, unambiguous subiterator of the node's annotation.tree in interface AnnotationIndex<T extends AnnotationFS>annot - The annotation at the root of the tree. This must be of type T or a subtypeannot.public FSIndex<T> withSnapshotIterators()
FSIndexwithSnapshotIterators in interface FSIndex<T extends AnnotationFS>Copyright © 2006–2021 The Apache Software Foundation. All rights reserved.