}
public DebugRuleApply createDebugRuleApply(RuleApply ruleApply, RutaStream stream,
boolean addToIndex, boolean withMatches, Map<RutaElement, Long> timeInfo) {
JCas cas = stream.getJCas();
DebugRuleApply dra = new DebugRuleApply(cas);
List<DebugRuleMatch> ruleMatches = new ArrayList<DebugRuleMatch>();
int begin = Integer.MAX_VALUE;
int end = 0;
if (withMatches) {
for (AbstractRuleMatch<? extends AbstractRule> match : ruleApply.getList()) {
DebugRuleMatch debugRuleMatch = createDebugRuleMatch(match, stream, addToIndex,
withMatches, timeInfo);
begin = Math.min(begin, debugRuleMatch.getBegin());
end = Math.max(end, debugRuleMatch.getEnd());
ruleMatches.add(debugRuleMatch);
}
}
if (begin >= end) {
begin = end;
}
dra.setRules(UIMAUtils.toFSArray(cas, ruleMatches));
RutaElement element = ruleApply.getElement();
String namespace = "";
if(element instanceof RutaStatement) {
RutaStatement rs = (RutaStatement) element;
namespace = rs.getParent().getScript().getRootBlock().getNamespace();
} else if(element instanceof AbstractRuleElement) {
AbstractRuleElement are = (AbstractRuleElement) element;
are.getRule().getParent().getScript().getRootBlock().getNamespace();
}
dra.setElement(verbalizer.verbalize(element));
dra.setApplied(ruleApply.getApplied());
dra.setTried(ruleApply.getTried());
dra.setId(((AbstractRule) element).getId());
dra.setScript(namespace);
dra.setBegin(begin);
dra.setEnd(end);
if (timeInfo != null) {
Long time = timeInfo.get(element);
if(time != null) {
dra.setTime(time);
}
}
if (addToIndex)
dra.addToIndexes();
return dra;
}