On 8/8/2013 12:06 PM, Richard Eckart de Castilho wrote:
> 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.
It's possible to have the method return a class which implements Iterable, and
has the additional functions, of course; it would not need to implement
Collections.
The implementation of "size" would be potentially slow - since that's not kept;
it would require iterating through the entire thing and accumulating in a
counter. So that might be a "surprise" for users of this interface.
>
> 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));
True. This could also be done with a custom class. e.g.
List<Token> tokens = select_v2(jcas, Token.class).toList();
>
> 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
>