private void fillSlotRulesWithMostSpecificRules() {
slotRules.clear();
for (TextRulerExample example : examples) {
RapierRule rule = new RapierRule(this, example.getTarget());
TextRulerAnnotation slotAnnotation = example.getAnnotation();
CAS docCas = example.getDocumentCAS();
TypeSystem ts = docCas.getTypeSystem();
Type tokensRootType = ts.getType(TextRulerToolkit.RUTA_ANY_TYPE_NAME);
// first, get all words/tokens:
List<AnnotationFS> before = TextRulerToolkit.getAnnotationsBeforePosition(
example.getDocumentCAS(), slotAnnotation.getBegin(), -1,
TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokensRootType);
List<AnnotationFS> after = TextRulerToolkit.getAnnotationsAfterPosition(
example.getDocumentCAS(), slotAnnotation.getEnd(), -1,
TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokensRootType);
List<AnnotationFS> inside = TextRulerToolkit.getAnnotationsWithinBounds(
example.getDocumentCAS(), slotAnnotation.getBegin(), slotAnnotation.getEnd(),
TextRulerToolkit.getFilterSetWithSlotNames(slotNames, filterSet), tokensRootType);
// the before annotations have to be reversed:
for (int i = before.size() - 1; i >= 0; i--) {
AnnotationFS afs = before.get(i);
RapierRuleItem ruleItem = new RapierRuleItem();
ruleItem.addWordConstraint(new TextRulerWordConstraint(new TextRulerAnnotation(afs, example
.getDocument())));
addAvailablePosTagConstraintToItem(ruleItem, afs, example);
rule.addPreFillerItem(ruleItem);
}
for (AnnotationFS afs : inside) {
RapierRuleItem ruleItem = new RapierRuleItem();
ruleItem.addWordConstraint(new TextRulerWordConstraint(new TextRulerAnnotation(afs, example
.getDocument())));
addAvailablePosTagConstraintToItem(ruleItem, afs, example);
rule.addFillerItem(ruleItem);
}
for (AnnotationFS afs : after) {
RapierRuleItem ruleItem = new RapierRuleItem();
ruleItem.addWordConstraint(new TextRulerWordConstraint(new TextRulerAnnotation(afs, example
.getDocument())));
addAvailablePosTagConstraintToItem(ruleItem, afs, example);
rule.addPostFillerItem(ruleItem);
}