public interface FSIndex<T extends FeatureStructure> extends Iterable<T>
Notice that each feature structure index uses its own ordering relation that will usually be different from index to index. In particular, equality with respect to the index ordering will in general not imply object identity for the feature structures.
We currently support three different kinds of indexes: sorted, set and bag indexes. The default index is a sorted index. In a sorted index, FSs that are committed (added to the indexes) are added, unless they are duplicates of already existing FSs in the index. Multiple different instances of FSs which compare equal may all be in the index, individually.
The index is sorted in the sense that iterators will output FSs in sorted order according to the comparator for that index. The order of FSs that are equal with respect to the comparator is arbitrary but fixed. That is, if you iterate over the same index several times, you will see the same relative order of FSs every time. We also guarantee that reverse iterators will produce exactly the reverse sequence of forward iteration.
A set index will contain no duplicates of the same type, where a duplicate is defined by the indexing comparator. That is, if you commit two feature structures of the same type that are equal with respect to the indexing comparator, only the first one will be entered into the index. Note that you can still have duplicates with respect to the indexing order if they are of a different type; different types are never "equal". A set index is not in any particular sort order.
A bag index finally simply stores everything, without any guaranteed order. Operations that depend on comparison, such as find(FeatureStructure fs) or FSIterator.moveTo(FeatureStructure fs) only compare for equality using FeatureStructure identity, since no ordering relationship is possible with bag indexes.
Indexes have a top-most type; let's call it T. They store only instances of that type or its subtypes. A given index definition specifies this top-most type. The APIs for obtaining an index include the ability to specify, in addition, a type T2 which is a subtype of T; indexes obtained using this will have only instances of type T2 or its subtypes.
Modifier and Type | Field and Description |
---|---|
static int |
BAG_INDEX
Indexing strategy: bag index.
|
static int |
DEFAULT_BAG_INDEX
Special indexes used by the framework to implement
FSIndexRepository.getAllIndexedFS(Type) . |
static int |
SET_INDEX
Indexing strategy: set index.
|
static int |
SORTED_INDEX
Indexing strategy: sorted 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.
|
T |
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.
|
default FSIterator<T> |
iterator(FeatureStructure fs)
Return an iterator over the index.
|
<N extends FeatureStructure> |
select() |
<N extends FeatureStructure> |
select(Class<N> clazz) |
<N extends FeatureStructure> |
select(int jcasType) |
<N extends FeatureStructure> |
select(String fullyQualifiedTypeName) |
<N extends FeatureStructure> |
select(Type type) |
int |
size()
Return the number of feature structures in this index.
|
FSIndex<T> |
withSnapshotIterators()
Creates a shared copy of this FSIndex configured to produce snapshot iterators
that don't throw ConcurrentModificationExceptions.
|
forEach, spliterator
static final int SORTED_INDEX
static final int SET_INDEX
static final int BAG_INDEX
static final int DEFAULT_BAG_INDEX
FSIndexRepository.getAllIndexedFS(Type)
. Not user-definable.int size()
Type getType()
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. For bag indexes (which have no comparators), the equality test means the identical feature structure. Note that this is in general not the same as feature structure identity.
The element is used as a template, and may be a supertype of the type of the index, as long as the keys specified for this index can be accessed.
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.T find(FeatureStructure fs)
fs
- A Feature Structure used a template to match with the Feature Structures in the index.
It must have the keys needed to do the compare as specified for the index that it's in.null
if no such FS exists.FSIterator.moveTo(FeatureStructure)
int compare(FeatureStructure fs1, FeatureStructure fs2)
fs1
- the first Feature Structure to comparefs2
- the second Feature Structure to compare-1
if fs1 < fs2
; 0
if
fs1 = fs2
; 1
else.default FSIterator<T> iterator(FeatureStructure fs)
get()
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.fs
- A feature structure template (may be a supertype of T) having keys used in the index compare function,
specifying where to initially position the iterator.fs
, if it exists; else, an invalid iterator.FSIterator<T> iterator()
iterator
in interface Iterable<T extends FeatureStructure>
int getIndexingStrategy()
SORTED_INDEX
, BAG_INDEX
or SET_INDEX
.FSIndex<T> withSnapshotIterators()
<N extends FeatureStructure> SelectFSs<N> select()
<N extends FeatureStructure> SelectFSs<N> select(Type type)
<N extends FeatureStructure> SelectFSs<N> select(Class<N> clazz)
<N extends FeatureStructure> SelectFSs<N> select(int jcasType)
<N extends FeatureStructure> SelectFSs<N> select(String fullyQualifiedTypeName)
Copyright © 2006–2017 The Apache Software Foundation. All rights reserved.