Hi Isaac,
There is a simpler way to do this. Using FilteredIterators you can limit an
iterator to just returning types of interest. Using "type priorities" you
can guarantee the order that types are returned for annotations with the
same begin and end positions.
Using both of these would allow a single pass iteration to eliminate
unwanted type instances.
In the CDE for your component, on the Indexes tab, add a priority list that
puts Person in front of the other types. The resultant component descriptor
would look like this:
<typePriorities>
<priorityList>
<type>yourtype.Person</type>
<type>yourtype.Organization</type>
<type>yourtype.Company</type>
...
</priorityList>
</typePriorities>
Some code below.
FSIterator it = jcas.getAnnotationIndex().iterator();
FSTypeConstraint constraint = cas.getConstraintFactory
().createTypeConstraint();
constraint.add((new Person(jcas)).getType());
constraint.add((new Organization(jcas)).getType());
constraint.add((new Company(jcas)).getType());
it = jcas.createFilteredIterator(it, constraint);
it.moveToFirst();
Annotation a = null;
int pB = -1;
int pE = -1;
LinkedList<Annotation> toDel = new LinkedList<Annotation>();
while (it.hasNext()) {
a = (Annotation) it.get();
it.moveToNext();
if (a instanceof Person) {
// grab position for testing subsequent FS
pB = a.getBegin();
pE = a.getEnd();
}
else {
// not a Person; see if it has same position as the last
Person
if (pB == a.getBegin() && pE == a.getEnd()) {
toDel.add(a);
}
}
}
// must modify index outside iterator loop
for (int i = 0; i < toDel.size(); i++) {
toDel.get(i).removeFromIndexes();
}
Regards,
Eddie