@Override
public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) {
BlockApply result = new BlockApply(this);
crowd.beginVisit(this, result);
RuleApply apply = rule.apply(stream, crowd, true);
for (AbstractRuleMatch<? extends AbstractRule> eachMatch : apply.getList()) {
if (eachMatch.matched()) {
List<AnnotationFS> matchedAnnotations = ((RuleMatch) eachMatch).getMatchedAnnotations(null,
null);
if (matchedAnnotations == null || matchedAnnotations.isEmpty()) {
continue;
}
AnnotationFS each = matchedAnnotations.get(0);
if (each == null) {
continue;
}
boolean stop = false;
List<Type> types = ((RutaRuleElement) rule.getRuleElements().get(0)).getMatcher().getTypes(
getParent() == null ? this : getParent(), stream);
for (Type eachType : types) {
RutaStream window = stream.getWindowStream(each, eachType);
for (RutaStatement element : getElements()) {
if (stop)
break;
if (element != null) {
ScriptApply elementApply = element.apply(window, crowd);
if (elementApply instanceof BlockApply) {
BlockApply ba = (BlockApply) elementApply;
if (ba.getRuleApply().getApplied() > 0) {
stop = true;
}
} else if (elementApply instanceof RuleApply) {
RuleApply ra = (RuleApply) elementApply;
if (ra.getApplied() > 0) {
stop = true;
}
}
}
}