in ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java [72:170]
public List<RuleMatch> startMatch(RuleMatch ruleMatch, RuleApply ruleApply,
ComposedRuleElementMatch containerMatch, RuleElement entryPoint, RutaStream stream,
InferenceCrowd crowd) {
List<RuleMatch> result = new ArrayList<>();
if (conjunct == null) {
ComposedRuleElementMatch composedMatch = createComposedMatch(ruleMatch, containerMatch,
stream);
RuleElement anchorElement = getAnchoringRuleElement(stream);
result = anchorElement.startMatch(ruleMatch, ruleApply, composedMatch, entryPoint, stream,
crowd);
} else if (!conjunct) {
// disjunctive
Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new LinkedHashMap<>();
for (RuleElement each : elements) {
ComposedRuleElementMatch extendedContainerMatch = containerMatch.copy();
RuleMatch extendedMatch = ruleMatch.copy(extendedContainerMatch, true);
ComposedRuleElementMatch composedMatch = createComposedMatch(extendedMatch,
extendedContainerMatch, stream);
List<RuleMatch> startRuleMatches = each.startMatch(extendedMatch, null, composedMatch, this,
stream, crowd);
for (RuleMatch startRuleMatch : startRuleMatches) {
ComposedRuleElementMatch startElementMatch = (ComposedRuleElementMatch) startRuleMatch
.getLastMatch(this, true);
ruleMatches.put(startRuleMatch, startElementMatch);
}
}
Map<RuleMatch, ComposedRuleElementMatch> mergedMatches = mergeDisjunctiveRuleMatches(
ruleMatches, true, 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(null, this, eachRuleMatch, true);
AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
RuleElement sideStepOrigin = hasAncestor(false) ? this : null;
List<RuleMatch> fallbackContinue = fallbackContinue(true, failed, lastAnnotation,
eachRuleMatch, ruleApply, eachComposedMatch, sideStepOrigin, entryPoint, stream,
crowd);
result.addAll(fallbackContinue);
}
} else if (conjunct) {
// conjunctive
Map<RuleMatch, ComposedRuleElementMatch> ruleMatches = new LinkedHashMap<>();
RuleElement anchoringRuleElement = getAnchoringRuleElement(stream);
ComposedRuleElementMatch composedMatch = createComposedMatch(ruleMatch, containerMatch,
stream);
List<RuleMatch> startRuleMatches = anchoringRuleElement.startMatch(ruleMatch, null,
composedMatch, this, stream, crowd);
for (RuleMatch eachStartRuleMatch : startRuleMatches) {
if (eachStartRuleMatch.matched()) {
AnnotationFS prefixAnnotation = getPrefixAnnotation(eachStartRuleMatch, stream);
for (RuleElement each : elements) {
if (each.equals(anchoringRuleElement)) {
continue;
}
ComposedRuleElementMatch startElementMatch = (ComposedRuleElementMatch) eachStartRuleMatch
.getLastMatch(this, true);
List<RuleMatch> continueMatch = each.continueMatch(true, prefixAnnotation,
eachStartRuleMatch, null, startElementMatch, null, this, stream, crowd);
for (RuleMatch startRuleMatch : continueMatch) {
ComposedRuleElementMatch elementMatch = (ComposedRuleElementMatch) startRuleMatch
.getLastMatch(this, true);
ruleMatches.put(startRuleMatch, elementMatch);
}
}
}
}
Map<RuleMatch, ComposedRuleElementMatch> mergedMatches = mergeConjunctiveRuleMatches(
ruleMatches, true);
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 = eachComposedMatch.getTextsMatched();
if ((!stream.isGreedyAnchoring() && !stream.isOnlyOnce())
|| !earlyExit(textsMatched.get(0), ruleApply, stream)) {
RuleElement sideStepOrigin = hasAncestor(false) ? this : null;
List<RuleMatch> fallbackContinue = fallbackContinue(true, failed, lastAnnotation,
eachRuleMatch, ruleApply, eachComposedMatch, sideStepOrigin, entryPoint, stream,
crowd);
result.addAll(fallbackContinue);
}
}
}
return result;
}