in ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java [191:290]
public List<RuleMatch> continueMatch(boolean after, AnnotationFS annotation, RuleMatch ruleMatch,
RuleApply ruleApply, ComposedRuleElementMatch containerMatch, RuleElement sideStepOrigin,
RuleElement entryPoint, RutaStream stream, InferenceCrowd crowd) {
List<RuleMatch> result = new ArrayList<>();
if (conjunct == null) {
// inner next sequential
RuleElement nextElement = getNextElement(after, this);
if (nextElement != null) {
ComposedRuleElementMatch composedMatch = createComposedMatch(ruleMatch, containerMatch,
stream);
result = nextElement.continueMatch(after, annotation, ruleMatch, ruleApply, composedMatch,
sideStepOrigin, entryPoint, stream, crowd);
} else {
result = fallback(after, false, annotation, ruleMatch, ruleApply, containerMatch,
sideStepOrigin, entryPoint, stream, crowd);
}
} else if (!conjunct) {
// disjunctive
Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<>();
for (RuleElement each : elements) {
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
ComposedRuleElementMatch composedMatch = createComposedMatch(extendedMatch,
extendedContainerMatch, stream);
List<RuleMatch> continueRuleMatches = each.continueMatch(after, annotation, extendedMatch,
null, composedMatch, sideStepOrigin, this, stream, crowd);
for (RuleMatch continueRuleMatch : continueRuleMatches) {
ComposedRuleElementMatch startElementMatch = (ComposedRuleElementMatch) continueRuleMatch
.getLastMatch(this, true);
ruleMatches.put(continueRuleMatch, startElementMatch);
}
}
// TODO sort matches, no need to merge them, right?!
Map<RuleMatch, ComposedRuleElementMatch> mergedMatches = mergeDisjunctiveRuleMatches(
ruleMatches, after, stream);
Set<Entry<RuleMatch, ComposedRuleElementMatch>> entrySet = mergedMatches.entrySet();
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
MatchContext context = new MatchContext(annotation, this, eachRuleMatch, after);
AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
List<AnnotationFS> textsMatched = eachRuleMatch.getMatchedAnnotationsOfRoot();
if ((!stream.isGreedyAnchoring() && !stream.isOnlyOnce()) || (!textsMatched.isEmpty()
&& !earlyExit(textsMatched.get(0), ruleApply, stream))) {
List<RuleMatch> fallbackContinue = fallbackContinue(after, failed, lastAnnotation,
eachRuleMatch, ruleApply, eachComposedMatch, sideStepOrigin, entryPoint, stream,
crowd);
result.addAll(fallbackContinue);
}
}
} else if (conjunct) {
// conjunctive
Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new HashMap<>();
RuleElement anchoringRuleElement = getAnchoringRuleElement(stream);
ComposedRuleElementMatch composedMatch = createComposedMatch(ruleMatch, containerMatch,
stream);
List<RuleMatch> startRuleMatches = anchoringRuleElement.continueMatch(after, annotation,
ruleMatch, null, composedMatch, sideStepOrigin, this, stream, crowd);
for (RuleMatch eachStartRuleMatch : startRuleMatches) {
for (RuleElement each : elements) {
if (each.equals(anchoringRuleElement)) {
continue;
}
ComposedRuleElementMatch startElementMatch = (ComposedRuleElementMatch) eachStartRuleMatch
.getLastMatch(this, after);
List<RuleMatch> continueMatch = each.continueMatch(after, annotation, eachStartRuleMatch,
null, startElementMatch, null, this, stream, crowd);
for (RuleMatch startRuleMatch : continueMatch) {
ComposedRuleElementMatch elementMatch = (ComposedRuleElementMatch) startRuleMatch
.getLastMatch(this, after);
ruleMatches.put(startRuleMatch, elementMatch);
}
}
}
Map<RuleMatch, ComposedRuleElementMatch> mergedMatches = mergeConjunctiveRuleMatches(
ruleMatches, after);
Set<Entry<RuleMatch, ComposedRuleElementMatch>> entrySet = mergedMatches.entrySet();
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
MatchContext context = new MatchContext(this, eachRuleMatch);
AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
List<AnnotationFS> textsMatched = eachRuleMatch.getMatchedAnnotationsOfRoot();
if ((!stream.isGreedyAnchoring() && !stream.isOnlyOnce()) || (!textsMatched.isEmpty()
&& !earlyExit(textsMatched.get(0), ruleApply, stream))) {
List<RuleMatch> fallbackContinue = fallbackContinue(after, failed, lastAnnotation,
eachRuleMatch, ruleApply, eachComposedMatch, sideStepOrigin, entryPoint, stream,
crowd);
result.addAll(fallbackContinue);
}
}
}
return result;
}