use of org.kie.dmn.validation.dtanalysis.model.Interval in project drools by kiegroup.
the class DMNDTAnalyser method compileTableInputClauses.
private void compileTableInputClauses(DMNModel model, DecisionTable dt, DDTATable ddtaTable) {
for (int jColIdx = 0; jColIdx < dt.getInput().size(); jColIdx++) {
InputClause ie = dt.getInput().get(jColIdx);
Interval infDomain = new Interval(RangeBoundary.CLOSED, Interval.NEG_INF, Interval.POS_INF, RangeBoundary.CLOSED, 0, jColIdx + 1);
String allowedValues;
if (ie.getInputValues() != null) {
allowedValues = ie.getInputValues().getText();
} else {
QName typeRef = DMNCompilerImpl.getNamespaceAndName(dt, ((DMNModelImpl) model).getImportAliasesForNS(), ie.getInputExpression().getTypeRef(), model.getNamespace());
allowedValues = findAllowedValues(model, typeRef);
}
if (allowedValues != null) {
ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(allowedValues, FEEL.newCompilerContext());
UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
if (utln.getElements().size() != 1) {
verifyUnaryTestsAllEQ(utln, dt);
List<Comparable<?>> discreteValues = getDiscreteValues(utln);
Collections.sort((List) discreteValues);
Interval discreteDomainMinMax = new Interval(RangeBoundary.CLOSED, discreteValues.get(0), discreteValues.get(discreteValues.size() - 1), RangeBoundary.CLOSED, 0, jColIdx + 1);
DDTAInputClause ic = new DDTAInputClause(discreteDomainMinMax, discreteValues, getDiscreteValues(utln));
ddtaTable.getInputs().add(ic);
} else if (utln.getElements().size() == 1) {
UnaryTestNode utn0 = (UnaryTestNode) utln.getElements().get(0);
Interval interval = utnToInterval(utn0, infDomain, null, 0, jColIdx + 1);
DDTAInputClause ic = new DDTAInputClause(interval);
ddtaTable.getInputs().add(ic);
} else {
throw new IllegalStateException("inputValues not null but utln: " + utln);
}
} else {
DDTAInputClause ic = new DDTAInputClause(infDomain);
ddtaTable.getInputs().add(ic);
}
}
}
use of org.kie.dmn.validation.dtanalysis.model.Interval in project drools by kiegroup.
the class DMNDTAnalyser method findGaps.
private static void findGaps(DTAnalysis analysis, DDTATable ddtaTable, int jColIdx, Interval[] currentIntervals, Collection<Integer> activeRules) {
LOG.debug("findGaps jColIdx {}, currentIntervals {}, activeRules {}", jColIdx, currentIntervals, activeRules);
if (jColIdx < ddtaTable.inputCols()) {
findBoundsSorted(ddtaTable, jColIdx, activeRules);
List<Bound> bounds = findBoundsSorted(ddtaTable, jColIdx, activeRules);
Interval domainRange = ddtaTable.getInputs().get(jColIdx).getDomainMinMax();
// from domain start to the 1st bound
if (!domainRange.getLowerBound().equals(bounds.get(0))) {
currentIntervals[jColIdx] = lastDimensionUncoveredInterval(domainRange.getLowerBound(), bounds.get(0), domainRange);
Hyperrectangle gap = new Hyperrectangle(ddtaTable.inputCols(), buildEdgesForHyperrectangleFromIntervals(currentIntervals, jColIdx));
analysis.addGap(gap);
LOG.debug("STARTLEFT GAP DETECTED {}", gap);
}
// cycle rule's interval bounds
List<Interval> activeIntervals = new ArrayList<>();
Bound<?> lastBound = NullBoundImpl.NULL;
for (Bound<?> currentBound : bounds) {
LOG.debug("lastBound {} currentBound {} activeIntervals {} == rules {}", lastBound, currentBound, activeIntervals, activeIntervalsToRules(activeIntervals));
if (activeIntervals.isEmpty() && lastBound != NullBoundImpl.NULL && !Bound.adOrOver(lastBound, currentBound)) {
currentIntervals[jColIdx] = lastDimensionUncoveredInterval(lastBound, currentBound, domainRange);
Hyperrectangle gap = new Hyperrectangle(ddtaTable.inputCols(), buildEdgesForHyperrectangleFromIntervals(currentIntervals, jColIdx));
LOG.debug("GAP DETECTED {}", gap);
analysis.addGap(gap);
}
if (!activeIntervals.isEmpty() && canBeNewCurrInterval(lastBound, currentBound)) {
Interval missingInterval = new Interval(lastBound.isUpperBound() ? Interval.invertBoundary(lastBound.getBoundaryType()) : lastBound.getBoundaryType(), lastBound.getValue(), currentBound.getValue(), currentBound.isLowerBound() ? Interval.invertBoundary(currentBound.getBoundaryType()) : currentBound.getBoundaryType(), 0, 0);
currentIntervals[jColIdx] = missingInterval;
findGaps(analysis, ddtaTable, jColIdx + 1, currentIntervals, activeIntervalsToRules(activeIntervals));
}
if (currentBound.isLowerBound()) {
activeIntervals.add(currentBound.getParent());
} else {
activeIntervals.remove(currentBound.getParent());
}
lastBound = currentBound;
}
// from last Nth bound, to domain end.
if (!lastBound.equals(domainRange.getUpperBound())) {
currentIntervals[jColIdx] = lastDimensionUncoveredInterval(lastBound, domainRange.getUpperBound(), domainRange);
Hyperrectangle gap = new Hyperrectangle(ddtaTable.inputCols(), buildEdgesForHyperrectangleFromIntervals(currentIntervals, jColIdx));
LOG.debug("ENDRIGHT GAP DETECTED {}", gap);
analysis.addGap(gap);
}
// facilitate debugging.
currentIntervals[jColIdx] = null;
}
LOG.debug(".");
}
use of org.kie.dmn.validation.dtanalysis.model.Interval in project drools by kiegroup.
the class DMNDTAnalyser method compileTableRules.
private void compileTableRules(DecisionTable dt, DDTATable ddtaTable) {
for (int jRowIdx = 0; jRowIdx < dt.getRule().size(); jRowIdx++) {
DecisionRule r = dt.getRule().get(jRowIdx);
DDTARule ddtaRule = new DDTARule();
int jColIdx = 0;
for (UnaryTests ie : r.getInputEntry()) {
ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(ie.getText(), FEEL.newCompilerContext());
UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
DDTAInputClause ddtaInputClause = ddtaTable.getInputs().get(jColIdx);
DDTAInputEntry ddtaInputEntry = new DDTAInputEntry(utln.getElements(), toIntervals(utln.getElements(), utln.isNegated(), ddtaInputClause.getDomainMinMax(), ddtaInputClause.getDiscreteValues(), jRowIdx + 1, jColIdx + 1));
for (Interval interval : ddtaInputEntry.getIntervals()) {
Interval domainMinMax = ddtaTable.getInputs().get(jColIdx).getDomainMinMax();
if (!domainMinMax.includes(interval)) {
throw new IllegalStateException(MsgUtil.createMessage(Msg.DTANALYSIS_ERROR_RULE_OUTSIDE_DOMAIN, jRowIdx + 1, interval, domainMinMax, jColIdx + 1));
}
}
ddtaRule.getInputEntry().add(ddtaInputEntry);
jColIdx++;
}
for (LiteralExpression oe : r.getOutputEntry()) {
ProcessedExpression compile = (ProcessedExpression) FEEL.compile(oe.getText(), FEEL.newCompilerContext());
InterpretedExecutableExpression interpreted = compile.getInterpreted();
BaseNode outputEntryNode = (BaseNode) interpreted.getASTNode();
Comparable<?> value = valueFromNode(outputEntryNode, outputClauseVisitor);
ddtaRule.getOutputEntry().add(value);
jColIdx++;
}
ddtaTable.addRule(ddtaRule);
}
}
use of org.kie.dmn.validation.dtanalysis.model.Interval in project drools by kiegroup.
the class DMNDTAnalyser method compileTableOutputClauses.
private void compileTableOutputClauses(DMNModel model, DecisionTable dt, DDTATable ddtaTable) {
for (int jColIdx = 0; jColIdx < dt.getOutput().size(); jColIdx++) {
OutputClause oe = dt.getOutput().get(jColIdx);
Interval infDomain = new Interval(RangeBoundary.CLOSED, Interval.NEG_INF, Interval.POS_INF, RangeBoundary.CLOSED, 0, jColIdx + 1);
String allowedValues = null;
if (oe.getOutputValues() != null) {
allowedValues = oe.getOutputValues().getText();
} else {
QName outputTypeRef = (oe.getTypeRef() == null && dt.getOutput().size() == 1) ? dt.getTypeRef() : oe.getTypeRef();
if (outputTypeRef != null) {
QName typeRef = DMNCompilerImpl.getNamespaceAndName(dt, ((DMNModelImpl) model).getImportAliasesForNS(), outputTypeRef, model.getNamespace());
allowedValues = findAllowedValues(model, typeRef);
}
}
if (allowedValues != null) {
ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(allowedValues, FEEL.newCompilerContext());
UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
if (utln.getElements().size() != 1) {
verifyUnaryTestsAllEQ(utln, dt);
List<Comparable<?>> discreteValues = getDiscreteValues(utln);
List<Comparable<?>> outputOrder = new ArrayList<>(discreteValues);
Collections.sort((List) discreteValues);
Interval discreteDomainMinMax = new Interval(RangeBoundary.CLOSED, discreteValues.get(0), discreteValues.get(discreteValues.size() - 1), RangeBoundary.CLOSED, 0, jColIdx + 1);
DDTAOutputClause ic = new DDTAOutputClause(discreteDomainMinMax, discreteValues, outputOrder);
ddtaTable.getOutputs().add(ic);
} else if (utln.getElements().size() == 1) {
UnaryTestNode utn0 = (UnaryTestNode) utln.getElements().get(0);
Interval interval = utnToInterval(utn0, infDomain, null, 0, jColIdx + 1);
DDTAOutputClause ic = new DDTAOutputClause(interval);
ddtaTable.getOutputs().add(ic);
} else {
throw new IllegalStateException("inputValues not null but utln: " + utln);
}
} else {
DDTAOutputClause ic = new DDTAOutputClause(infDomain);
ddtaTable.getOutputs().add(ic);
}
}
}
use of org.kie.dmn.validation.dtanalysis.model.Interval in project drools by kiegroup.
the class DTAnalysisMeta method hrAsExpression.
private static Expression hrAsExpression(Hyperrectangle gap) {
int dimensions = gap.getDimensions();
MethodCallExpr edgesExpression = parseExpression("Arrays.asList()");
for (Interval edge : gap.getEdges()) {
Expression intervalAsExpression = intervalAsExpression(edge);
edgesExpression.addArgument(intervalAsExpression);
}
ObjectCreationExpr newExpression = parseExpression("new Hyperrectangle()");
newExpression.addArgument(new IntegerLiteralExpr(dimensions));
newExpression.addArgument(edgesExpression);
return newExpression;
}
Aggregations