use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.
the class KiePMMLScorecardModelCharacteristicASTFactoryTest method declareRuleFromCharacteristicNotLastCharacteristic.
@Test
public void declareRuleFromCharacteristicNotLastCharacteristic() {
Characteristic characteristic = getCharacteristic();
final String parentPath = "parent_path";
final List<KiePMMLDroolsRule> rules = new ArrayList<>();
final String statusToSet = "status_to_set";
final boolean isLastCharacteristic = false;
String[] expectedConstraints = { "value <= 5.0", "value >= 5.0 && value < 12.0" };
int[] expectedOperatorValuesSizes = { 1, 2 };
getKiePMMLScorecardModelCharacteristicASTFactory().declareRuleFromCharacteristic(characteristic, parentPath, rules, statusToSet, isLastCharacteristic);
assertEquals(characteristic.getAttributes().size(), rules.size());
for (int i = 0; i < rules.size(); i++) {
commonValidateRule(rules.get(i), characteristic.getAttributes().get(i), statusToSet, parentPath + "_AgeScore", i, isLastCharacteristic, 1, null, BOOLEAN_OPERATOR.AND, expectedConstraints[i], expectedOperatorValuesSizes[i]);
}
}
use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.
the class KiePMMLScorecardModelCharacteristicASTFactoryTest method declareRuleFromAttributeWithSimplePredicateNotLastCharacteristic.
@Test
public void declareRuleFromAttributeWithSimplePredicateNotLastCharacteristic() {
Attribute attribute = getSimplePredicateAttribute();
final String parentPath = "parent_path";
final int attributeIndex = 2;
final List<KiePMMLDroolsRule> rules = new ArrayList<>();
final String statusToSet = "status_to_set";
final String characteristicReasonCode = "REASON_CODE";
final double characteristicBaselineScore = 12;
final boolean isLastCharacteristic = false;
getKiePMMLScorecardModelCharacteristicASTFactory().declareRuleFromAttribute(attribute, parentPath, attributeIndex, rules, statusToSet, characteristicReasonCode, characteristicBaselineScore, isLastCharacteristic);
assertEquals(1, rules.size());
commonValidateRule(rules.get(0), attribute, statusToSet, parentPath, attributeIndex, isLastCharacteristic, 1, null, BOOLEAN_OPERATOR.AND, "value <= 5.0", 1);
}
use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.
the class KiePMMLSimpleSetPredicateASTFactoryTest method declareRuleFromSimpleSetPredicateIsNotInFinalLeaf.
@Test
public void declareRuleFromSimpleSetPredicateIsNotInFinalLeaf() {
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
List<String> values = Arrays.asList("3", "8.5");
final SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate("input2", values, SimpleSetPredicate.BooleanOperator.IS_NOT_IN, fieldTypeMap);
String parentPath = "_classA";
String currentRule = "_classA_classC";
String result = "classC";
String declaredType = fieldTypeMap.get("input2").getGeneratedType();
final List<KiePMMLDroolsRule> rules = new ArrayList<>();
String statusToSet = DONE;
PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simpleSetPredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
KiePMMLSimpleSetPredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimpleSetPredicate(result, true);
assertEquals(1, rules.size());
final KiePMMLDroolsRule retrieved = rules.get(0);
assertNotNull(retrieved);
assertEquals(currentRule, retrieved.getName());
assertEquals(statusToSet, retrieved.getStatusToSet());
assertEquals(String.format(STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
assertEquals(ResultCode.OK, retrieved.getResultCode());
assertEquals(result, retrieved.getResult());
assertNotNull(retrieved.getNotInConstraints());
final Map<String, List<Object>> notInConstraints = retrieved.getNotInConstraints();
assertEquals(1, notInConstraints.size());
assertTrue(notInConstraints.containsKey(declaredType));
final List<Object> retrievedValues = notInConstraints.get(declaredType);
List<String> originalPredicateValues = Arrays.asList(((String) simpleSetPredicate.getArray().getValue()).split(" "));
assertEquals(originalPredicateValues.size(), retrievedValues.size());
retrievedValues.forEach(retrievedValue -> {
assertTrue(originalPredicateValues.contains(retrievedValue));
});
}
use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.
the class KiePMMLDescrFactoryTest method getBaseDescr.
@Test
public void getBaseDescr() {
List<KiePMMLDroolsType> types = new ArrayList<>();
types.add(KiePMMLDescrTestUtils.getDroolsType());
types.add(KiePMMLDescrTestUtils.getDottedDroolsType());
List<KiePMMLFieldOperatorValue> orConstraints = Arrays.asList(new KiePMMLFieldOperatorValue(PATTERN_TYPE, BOOLEAN_OPERATOR.OR, Collections.singletonList(new KiePMMLOperatorValue(OPERATOR.LESS_THAN, 35)), null), new KiePMMLFieldOperatorValue(PATTERN_TYPE, BOOLEAN_OPERATOR.AND, Collections.singletonList(new KiePMMLOperatorValue(OPERATOR.GREATER_THAN, 85)), null));
KiePMMLDroolsRule rule = KiePMMLDroolsRule.builder(RULE_NAME, STATUS_TO_SET, Collections.emptyList()).withOrConstraints(orConstraints).build();
List<KiePMMLDroolsRule> rules = new ArrayList<>();
rules.add(rule);
KiePMMLDroolsAST drooledAST = new KiePMMLDroolsAST(types, rules);
PackageDescr packageDescr = KiePMMLDescrFactory.getBaseDescr(drooledAST, PACKAGE_NAME);
assertEquals(PACKAGE_NAME, packageDescr.getName());
checkImports(packageDescr.getImports());
checkGlobals(packageDescr.getGlobals());
checkRules(packageDescr.getRules());
}
use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.
the class KiePMMLDescrRhsFactoryTest method declareRhsWithoutIfBreak.
@Test
public void declareRhsWithoutIfBreak() {
String name = "NAME";
String statusToSet = "STATUS_TO_SET";
KiePMMLDroolsRule rule = KiePMMLDroolsRule.builder(name, statusToSet, Collections.emptyList()).build();
KiePMMLDescrRhsFactory.factory(ruleBuilder).declareRhs(rule);
assertNotNull(ruleBuilder.getDescr().getConsequence());
String expectedConsequence = String.format(UPDATE_STATUS_HOLDER_STATUS, statusToSet);
assertTrue(ruleBuilder.getDescr().getConsequence().toString().contains(expectedConsequence));
assertNotNull(ruleBuilder.getDescr().getNamedConsequences());
assertTrue(ruleBuilder.getDescr().getNamedConsequences().isEmpty());
}
Aggregations