use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock in project drools by kiegroup.
the class DMNDTAnalyser method dmnDTAnalysis.
private DTAnalysis dmnDTAnalysis(DMNModel model, DecisionTable dt, Set<Validation> flags) {
DDTATable ddtaTable = new DDTATable();
compileTableInputClauses(model, dt, ddtaTable);
compileTableOutputClauses(model, dt, ddtaTable);
compileTableRules(dt, ddtaTable);
compileTableComputeColStringMissingEnum(model, dt, ddtaTable);
printDebugTableInfo(ddtaTable);
DTAnalysis analysis = new DTAnalysis(dt, ddtaTable);
analysis.computeOutputInLOV();
if (!dt.getHitPolicy().equals(HitPolicy.COLLECT)) {
if (ddtaTable.getColIDsStringWithoutEnum().isEmpty()) {
LOG.debug("findGaps");
findGaps(analysis, ddtaTable, 0, new Interval[ddtaTable.inputCols()], Collections.emptyList());
} else {
LOG.debug("findGaps Skipped because getColIDsStringWithoutEnum is not empty: {}", ddtaTable.getColIDsStringWithoutEnum());
}
LOG.debug("findOverlaps");
findOverlaps(analysis, ddtaTable, 0, new Interval[ddtaTable.inputCols()], Collections.emptyList());
} else {
LOG.debug("findGaps(), findOverlaps() are Skipped because getHitPolicy is COLLECT.");
}
LOG.debug("computeMaskedRules");
analysis.computeMaskedRules();
LOG.debug("computeMisleadingRules");
analysis.computeMisleadingRules();
LOG.debug("normalize");
analysis.normalize();
LOG.debug("computeSubsumptions");
analysis.computeSubsumptions();
LOG.debug("computeContractions");
analysis.computeContractions();
LOG.debug("compute1stNFViolations");
analysis.compute1stNFViolations();
LOG.debug("compute2ndNFViolations");
analysis.compute2ndNFViolations();
LOG.debug("computeHitPolicyRecommender");
analysis.computeHitPolicyRecommender();
if (flags.contains(Validation.COMPUTE_DECISION_TABLE_MCDC)) {
LOG.debug("mcdc.");
List<PosNegBlock> selectedBlocks = new MCDCAnalyser(ddtaTable, dt).compute();
analysis.setMCDCSelectedBlocks(selectedBlocks);
}
return analysis;
}
use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock in project drools by kiegroup.
the class MCDC2TCKGenerator method mcdc2tck.
public static String mcdc2tck(DecisionTable dt, List<PosNegBlock> selectedBlocks) throws JAXBException {
ObjectFactory factory = new ObjectFactory();
TestCases testCases = factory.createTestCases();
Set<Record> mcdcRecords = new LinkedHashSet<>();
int testCaseId = 1;
for (PosNegBlock b : selectedBlocks) {
boolean add = mcdcRecords.add(b.posRecord);
if (add) {
appendRecordToTestCases(dt, testCases, String.valueOf(testCaseId), b.posRecord);
testCaseId++;
}
for (Record negRecord : b.negRecords) {
add = mcdcRecords.add(negRecord);
if (add) {
appendRecordToTestCases(dt, testCases, String.valueOf(testCaseId), negRecord);
testCaseId++;
}
}
}
JAXBContext jaxbContext = JAXBContext.newInstance(TestCases.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(testCases, sw);
return sw.toString();
}
use of org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock in project drools by kiegroup.
the class ExampleMCDCTest method debugOutputAndOpenXLSX.
public static void debugOutputAndOpenXLSX(DecisionTable dt, List<PosNegBlock> selectedBlocks) {
XSSFWorkbook wb = new XSSFWorkbook();
CreationHelper ch = wb.getCreationHelper();
CellStyle styleColumn = wb.createCellStyle();
styleColumn.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
styleColumn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font font = wb.createFont();
font.setColor(IndexedColors.RED.getIndex());
CellStyle styleRepeated = wb.createCellStyle();
styleRepeated.setFont(font);
Sheet sheet = wb.createSheet("MC DC Analysis");
int r = 0, c = 0;
Row row = sheet.createRow(r++);
row.createCell(c++).setCellValue(ch.createRichTextString("Rule:"));
for (InputClause input : dt.getInput()) {
row.createCell(c++).setCellValue(input.getInputExpression().getText());
}
for (OutputClause output : dt.getOutput()) {
row.createCell(c++).setCellValue(dt.getOutputLabel());
}
row.createCell(c++).setCellValue(ch.createRichTextString("Rule:"));
for (InputClause input : dt.getInput()) {
row.createCell(c++).setCellValue(input.getInputExpression().getText());
}
for (OutputClause output : dt.getOutput()) {
row.createCell(c++).setCellValue(dt.getOutputLabel());
}
Set<Record> mcdcRecords = new LinkedHashSet<>();
for (PosNegBlock b : selectedBlocks) {
row = sheet.createRow(r++);
c = 0;
boolean add = mcdcRecords.add(b.posRecord);
Cell ruleIdxCell = row.createCell(c++);
ruleIdxCell.setCellValue(b.posRecord.ruleIdx + 1);
if (!add) {
ruleIdxCell.setCellStyle(styleRepeated);
}
for (int i = 0; i < b.posRecord.enums.length; i++) {
Object en = b.posRecord.enums[i];
Cell enCell = row.createCell(c++);
enCell.setCellValue(en.toString());
if (!add) {
enCell.setCellStyle(styleRepeated);
}
if (b.cMarker == i) {
enCell.setCellStyle(styleColumn);
}
}
for (Object out : b.posRecord.output) {
Cell outCell = row.createCell(c++);
outCell.setCellValue(out.toString());
if (!add) {
outCell.setCellStyle(styleRepeated);
}
}
for (int i = 0; i < b.negRecords.size(); i++) {
Record negRecord = b.negRecords.get(i);
if (i != 0) {
row = sheet.createRow(r++);
c = 0 + 1 + b.posRecord.enums.length + b.posRecord.output.size();
}
add = mcdcRecords.add(negRecord);
ruleIdxCell = row.createCell(c++);
ruleIdxCell.setCellValue(negRecord.ruleIdx + 1);
if (!add) {
ruleIdxCell.setCellStyle(styleRepeated);
}
for (Object en : negRecord.enums) {
Cell enCell = row.createCell(c++);
enCell.setCellValue(en.toString());
if (!add) {
enCell.setCellStyle(styleRepeated);
}
}
for (Object out : negRecord.output) {
Cell outCell = row.createCell(c++);
outCell.setCellValue(out.toString());
if (!add) {
outCell.setCellStyle(styleRepeated);
}
}
}
}
File file;
try {
file = Files.createTempFile("mcdc " + dt.getOutputLabel(), ".xlsx").toFile();
OutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
wb.close();
} catch (IOException e) {
e.printStackTrace();
// terminate early;
return;
}
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().open(file);
} catch (IOException e) {
e.printStackTrace();
}
} else {
throw new UnsupportedOperationException();
}
LOG.trace(System.getProperty("java.io.tmpdir"));
}
Aggregations