// also mark as added
// start a new chain at each annotation that was not already added
// to a chain.
Set<Annotation> addedAnnotations = new HashSet<Annotation>();
for (AnnotationChain chain : chains) {
Annotation lastEl = chain.getLast();
// is the end of the last element not beyond the current offset?
// then the chain can potentially be made longer with annotations
// from this offset.
Object value = lastEl.getFeatures().get(feature);
if (endOffset(lastEl) <= offset) {
Set<Annotation> candidates = new HashSet<Annotation>();
for (Annotation offsetAnn : offsetAnns) {
Object annValue = offsetAnn.getFeatures().get(feature);
if (annValue == null) {
continue;
} // ignore anns with no value
if (annValue.equals(value)) {
candidates.add(offsetAnn);
}
}
if (candidates.isEmpty()) {
continue;
} // no candidates for this chain
if (candidates.size() == 1) {
// add the annotation to the current chain
Annotation a = candidates.iterator().next();
chain.addLast(a);
addedAnnotations.add(a);
} else {
// more than one canditate, we need to duplicate the current chain
System.err.println("Need to duplicate chain, not yet implemented!");
Annotation a = candidates.iterator().next();
chain.addLast(a);
addedAnnotations.add(a);
}
} // offset compatible with current chain
} // for each chain