Search in sources :

Example 11 with KiePMMLDroolsRule

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]);
    }
}
Also used : Characteristic(org.dmg.pmml.scorecard.Characteristic) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) Test(org.junit.Test)

Example 12 with KiePMMLDroolsRule

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);
}
Also used : Attribute(org.dmg.pmml.scorecard.Attribute) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) Test(org.junit.Test)

Example 13 with KiePMMLDroolsRule

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));
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 14 with KiePMMLDroolsRule

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());
}
Also used : KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) KiePMMLOperatorValue(org.kie.pmml.models.drools.tuples.KiePMMLOperatorValue) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) KiePMMLFieldOperatorValue(org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 15 with KiePMMLDroolsRule

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());
}
Also used : KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) Test(org.junit.Test)

Aggregations

KiePMMLDroolsRule (org.kie.pmml.models.drools.ast.KiePMMLDroolsRule)36 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)14 KiePMMLOriginalTypeGeneratedType (org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType)14 KiePMMLASTTestUtils.getPredicateASTFactoryData (org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData)14 SimplePredicate (org.dmg.pmml.SimplePredicate)9 Attribute (org.dmg.pmml.scorecard.Attribute)6 KiePMMLFieldOperatorValue (org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue)6 CompoundPredicate (org.dmg.pmml.CompoundPredicate)5 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicate)5 List (java.util.List)4 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)4 OutputField (org.dmg.pmml.OutputField)3 Characteristic (org.dmg.pmml.scorecard.Characteristic)3 ResultCode (org.kie.pmml.api.enums.ResultCode)3 KiePMMLDroolsAST (org.kie.pmml.models.drools.ast.KiePMMLDroolsAST)3 Map (java.util.Map)2 Field (org.dmg.pmml.Field)2 True (org.dmg.pmml.True)2