public DebugRuleMatch createDebugRuleMatch(AbstractRuleMatch<? extends AbstractRule> match,
RutaStream stream, boolean addToIndex, boolean withMatches,
Map<RutaElement, Long> timeInfo) {
JCas cas = stream.getJCas();
DebugRuleMatch drm = null;
if (match.matchedCompletely()) {
drm = new DebugMatchedRuleMatch(cas);
} else {
drm = new DebugFailedRuleMatch(cas);
}
drm.setMatched(match.matchedCompletely());
if (match instanceof RuleMatch) {
ComposedRuleElementMatch rootMatch = ((RuleMatch) match).getRootMatch();
setInnerMatches(stream, addToIndex, cas, drm, rootMatch);
// if (match.matched()) {
List<DebugScriptApply> delegates = new ArrayList<DebugScriptApply>();
for (ScriptApply rem : ((RuleMatch) match).getDelegateApply().values()) {
delegates.add(createDebugScriptApply(rem, stream, addToIndex, withMatches, timeInfo));
}
drm.setDelegates(UIMAUtils.toFSArray(cas, delegates));
// }
} else if (match instanceof RegExpRuleMatch) {
RegExpRuleMatch rerm = (RegExpRuleMatch) match;
Map<Integer, List<AnnotationFS>> map = rerm.getMap();
Set<Entry<Integer, List<AnnotationFS>>> entrySet = map.entrySet();
List<DebugRuleElementMatches> ruleElementMatches = new ArrayList<DebugRuleElementMatches>();
for (Entry<Integer, List<AnnotationFS>> entry : entrySet) {
DebugRuleElementMatches drems = new DebugRuleElementMatches(cas);
RegExpRule rule = rerm.getRule();
Integer key = entry.getKey();
List<AnnotationFS> value = entry.getValue();
drems.setElement(verbalizer.verbalize(rule));
List<DebugRuleElementMatch> remList = new ArrayList<DebugRuleElementMatch>();
if (value != null) {
for (AnnotationFS each : value) {
DebugRuleElementMatch drem = new DebugRuleElementMatch(cas);
DebugEvaluatedCondition base = new DebugEvaluatedCondition(cas);
base.setValue(true);
String baseString = "Group " + key;
base.setElement(baseString);
drem.setBaseCondition(base);
drem.setBegin(each.getBegin());
drem.setEnd(each.getEnd());
if (addToIndex) {
drem.addToIndexes();
}
remList.add(drem);
}
}
drems.setMatches(UIMAUtils.toFSArray(cas, remList));
if (addToIndex) {
drems.addToIndexes();
}
ruleElementMatches.add(drems);
}
drm.setElements(UIMAUtils.toFSArray(cas, ruleElementMatches));
}
if (timeInfo != null) {
long time = timeInfo.get(match.getRule());
drm.setTime(time);
}
List<AnnotationFS> matchedAnnotationsOfRoot = match.getMatchedAnnotationsOfRoot();
if (!matchedAnnotationsOfRoot.isEmpty()) {
AnnotationFS matchedAnnotation = matchedAnnotationsOfRoot.get(0);
if (matchedAnnotation != null) {
drm.setBegin(matchedAnnotation.getBegin());
drm.setEnd(matchedAnnotation.getEnd());
if (addToIndex || withMatches)
drm.addToIndexes();
}
}
return drm;
}