this.opExpr = op;
}
@Override
public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
RutaBlock parent = element.getParent();
String op = opExpr.getStringValue(parent, match, element, stream);
List<Type> list = new ArrayList<Type>();
int indexOf = element.getContainer().getRuleElements().indexOf(element);
List<Integer> indexes = new ArrayList<Integer>();
indexes.add(indexOf + 1);
List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(indexes,
element.getContainer());
for (AnnotationFS matched : matchedAnnotations) {
if (TYPES_AT_BEGIN.equals(op)) {
RutaBasic beginAnchor = stream.getBeginAnchor(matched.getBegin());
Collection<Set<AnnotationFS>> values = beginAnchor.getBeginMap().values();
Set<AnnotationFS> aset = new HashSet<AnnotationFS>();
for (Set<AnnotationFS> set : values) {
aset.addAll(set);
}
for (AnnotationFS annotationFS : aset) {
list.add(annotationFS.getType());
}
} else if (TYPES_AT_END.equals(op)) {
RutaBasic endAnchor = stream.getEndAnchor(matched.getEnd());
Collection<Set<AnnotationFS>> values = endAnchor.getEndMap().values();
Set<AnnotationFS> aset = new HashSet<AnnotationFS>();
for (Set<AnnotationFS> set : values) {
aset.addAll(set);
}
for (AnnotationFS annotationFS : aset) {
list.add(annotationFS.getType());
}
} else if (TYPES.equals(op)) {
Type annotationType = stream.getCas().getAnnotationType();
List<AnnotationFS> inWindow = stream.getAnnotationsInWindow(matched, annotationType);
for (AnnotationFS each : inWindow) {
if (each.getBegin() == matched.getBegin() && each.getEnd() == matched.getEnd()) {
list.add(each.getType());
}
if (each.getBegin() > matched.getBegin() || each.getEnd() < matched.getEnd()) {
break;
}
}
}
}
parent.getEnvironment().setVariableValue(var, list);
}