The methods returned Iterable in earlier versions of uimaFIT, but the ability to
get the number of annotations of the selected type or to check if it was
(non-)empty
was sufficiently common that it has been changed to Collection.
Also, having it as a Collection allows
easily copying of the data into another collection, e.g.
List<Token> tokens = new ArrayList<Token>(select(jcas, Token.class));
Since the collections are backed by the CAS (if possible), this comes in handy
when
removing annotations, e.g.
for (Token t : new ArrayList<Token>(select(jcas, Token.class))) {
if (t has some condition) {
t.removeFromIndexes();
}
}
Unfortunately (for what reason I don't know), Java doesn't provide an easy
way to dump an Iterable into a collection.
Cheers,
-- Richard
Am 08.08.2013 um 17:55 schrieb Marshall Schor <[email protected]>:
> In looking at uimaFIT's select, and some of the discussion on the issue
> tracking, I'm wondering if it would better to have the things that support
> the
> use cases:
>
> for (Token t : select(jcas, Token.class) {
>
> return an Iterable, instead of a Collection.
>
> That would drop the methods in Collection except for iterator(). These
> methods,
> for the most part, deal with things that CAS iterators don't have an easy
> ability to deal with, or can't implement due to logical differences between
> the
> CAS/Indexes/Iterators and Collections. These methods are:
> - size (requires iterating and counting all the elements)
> - add, addAll (not supported, instead, add to the CAS, and choose to index
> or not)
> - remove, removeAll, clear (not supported, but remove-from-all-indexes is)
> - contains, containsAll, retainAll (not supported because depends on a
> particular index's definition of equal)
>
> The only method of Collection that seems like it could be useful (besides, of
> course, iterator) for UIMA iterators is toArray, and the general object
> methods
> toString, equals, and hashCode.
>
> -Marshall