btw, the work around I had posted is *much* slower than the fixed subiterator method - for both creating the iterator and iterating through it. More than an order of magnitude slower (roughly 15x's slower). Thanks for the fix!

Thilo Goetz wrote:
   public static FSIterator getWindowIterator(JCas jCas, Annotation
windowAnnotation, Type type)
   {
       ConstraintFactory constraintFactory = jCas.getConstraintFactory();
             FeaturePath beginFeaturePath = jCas.createFeaturePath();
       beginFeaturePath.addFeature(type.getFeatureByBaseName("begin"));
       FSIntConstraint intConstraint =
constraintFactory.createIntConstraint();
       intConstraint.geq(windowAnnotation.getBegin());
       FSMatchConstraint beginConstraint =
constraintFactory.embedConstraint(beginFeaturePath, intConstraint);

       FeaturePath endFeaturePath = jCas.createFeaturePath();
       endFeaturePath.addFeature(type.getFeatureByBaseName("end"));
       intConstraint = constraintFactory.createIntConstraint();
       intConstraint.leq(windowAnnotation.getEnd());
       FSMatchConstraint endConstraint =
constraintFactory.embedConstraint(endFeaturePath, intConstraint);

       FSMatchConstraint windowConstraint =
constraintFactory.and(beginConstraint,endConstraint);
       FSIndex windowIndex = jCas.getAnnotationIndex(type);
       FSIterator windowIterator =
jCas.createFilteredIterator(windowIndex.iterator(), windowConstraint);

       return windowIterator;
   }



Thilo Goetz wrote:
That's a bug.  The underlying implementation of the two
iterator types you mention is totally different, hence
you see this only in one of them.  Any chance you could
provide a self-contained test case that exhibits this?

--Thilo

Philip Ogren wrote:
I am having difficulty with using the FSIterator returned by the
AnnotationIndex.subiterator(AnnotationFS) method.
The following is a code fragment:

AnnotationIndex annotationIndex = jCas.getAnnotationIndex(tokenType);
FSIterator tokenIterator =
annotationIndex.subiterator(sentenceAnnotation);
annotationIterator.moveTo(tokenAnnotation);


Here is the relevant portion of the stack trace:

    java.lang.ClassCastException: edu.colorado.cslr.dessert.types.Token
    at java.util.Collections.indexedBinarySearch(Unknown Source)
    at java.util.Collections.binarySearch(Unknown Source)
    at org.apache.uima.cas.impl.Subiterator.moveTo(Subiterator.java:224)


If I change the second line to the following, then I do not have any
problems with an exception being thrown.

FSIterator tokenIterator = annotationIndex.iterator();


Is this a bug or some misunderstanding on my part of how subiterator
should work?

Thanks,
Philip


Reply via email to