// TODO stop after the first found match or create one bad
// example for each found occurence ??!!
// for now: stop after one ! so create only ONE bad
// example...
int leftDistance = 0;
TextRulerExample leftCorrectTag = null;
for (int i = left.size() - 1; i >= 0; i--) {
leftDistance++;
TextRulerAnnotation needle = TextRulerToolkit.convertToTargetAnnotation(left.get(i),
doc, target, docCAS.getTypeSystem());
leftCorrectTag = TextRulerToolkit.exampleListContainsAnnotation(correctTags, needle);
if (leftCorrectTag != null)
break;
}
int rightDistance = 0;
TextRulerExample rightCorrectTag = null;
for (AnnotationFS fs : right) {
rightDistance++;
TextRulerAnnotation needle = TextRulerToolkit.convertToTargetAnnotation(fs, doc,
target, docCAS.getTypeSystem());
rightCorrectTag = TextRulerToolkit.exampleListContainsAnnotation(correctTags, needle);
if (rightCorrectTag != null)
break;
}
TextRulerExample theCorrectTag = null;
if (rightDistance < leftDistance && rightCorrectTag != null)
theCorrectTag = rightCorrectTag;
else if (rightDistance > leftDistance && leftCorrectTag != null)
theCorrectTag = leftCorrectTag;
else // use the one that would lie in the slot filler:
{
if (target.type == MLTargetType.SINGLE_LEFT_BOUNDARY && rightCorrectTag != null)
theCorrectTag = rightCorrectTag;
else
theCorrectTag = leftCorrectTag;
}
if (theCorrectTag != null) {
TextRulerToolkit.log("FOUND BAD EXAMPLE FOR SHIFTING !!");
TextRulerShiftExample shiftExample = new TextRulerShiftExample(doc,
wrongTag.getAnnotation(), theCorrectTag.getAnnotation(), true, target);
newExamples.add(shiftExample);
}
}
TextRulerToolkit
.writeCAStoXMIFile(testCAS, dir + File.pathSeparator + doc.getCasFileName());