Hello,

I have a problem accessing annotations, especially annotations of a given type in a window represented by another annotation. I am using type priorities but not in this concrete situation. Therefore i am not using the subiterator to access the contained annotations, but several other methods like this one:

public List<AnnotationFS> getAnnotationsInWindow(
       AnnotationFS windowAnnotation, Type type) {
   List<AnnotationFS> result = new ArrayList<AnnotationFS>();
   FSIterator completeIt = getCas().getAnnotationIndex().iterator();
   if (getDocumentAnnotation().getEnd() < windowAnnotation.getEnd()) {
       completeIt.moveToLast();
   } else {
       completeIt.moveTo(windowAnnotation);
   }
   while (completeIt.isValid()
       && ((Annotation) completeIt.get()).getBegin() >= windowAnnotation
           .getBegin()) {
       completeIt.moveToPrevious();
   }

   if (completeIt.isValid()) {
       completeIt.moveToNext();
   } else {
       completeIt.moveToFirst();
   }

   while (completeIt.isValid()
       && ((Annotation) completeIt.get()).getBegin() < windowAnnotation
           .getBegin()) {
       completeIt.moveToNext();
   }

   while (completeIt.isValid()
       && ((Annotation) completeIt.get()).getBegin() >= windowAnnotation
           .getBegin()) {
       Annotation annotation = (Annotation) completeIt.get();
       if (getCas().getTypeSystem().subsumes(type, annotation.getType())
           && annotation.getEnd() <= windowAnnotation.getEnd()) {
       result.add(annotation);
       }
       completeIt.moveToNext();
   }
   return result;
   }

I tried already many variations of this (e.g., with the index of the given type, using a new created frame with a higher type priority), but this method returns sometimes simply wrong annotations or no annotations at all. The only method that seems to work all the time is to iterate over all annotations of the given type and then filter those that are not contained in the window.

My problem occurs in many different shapes. Here's one short example:

Arguments:

windowAnnotation:
Annotation
  sofa: _InitialView
  begin: 10899
  end: 10906
Covered Text: {.8}Bar

type:
de.uniwue.casetrain.Answers.answerText


Information in the eclipse debug view (Variables):
SubAnnotations:
[0]
WordAnswer
  sofa: _InitialView
  begin: 10899
  end: 10906
  SimpleFeedback: <null>
  PosFactor: 0.8
  NegFactor: 0.0
  InstanceIsUserAnswer: false
  Text: <null>
  IsRegularExpression: false
  EditDistance: 0
[1]
WordAnswer
  sofa: _InitialView
  begin: 10886
  end: 10892
  SimpleFeedback: <null>
  PosFactor: 1.0
  NegFactor: 0.0
  InstanceIsUserAnswer: false
  Text: answerText
     sofa: _InitialView
     begin: 10889
     end: 10892
  IsRegularExpression: false
  EditDistance: 0
[2]
paragraph
  sofa: _InitialView
  begin: 10899
  end: 10906
...
[20]
answerText
  sofa: _InitialView
  begin: 10903
  end: 10906

...and so on....

In this example the method above simply stops at the second annotations since start offset is smaller than the one of the window. How can this be? Is the position in the index depending on the values of the features? Did I miss something here? In other examples the method above just steps over the important annotations. Using the brute force approach is not really a solution for me; it slows down my system by more than 50%.

I would really appreciate any hints to solve this problem since this method/functionality is quite essential for my application. Of course, i would also not reject any advice about performance.

Best regards

Peter

Reply via email to