Search in sources :

Example 6 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLSimplePredicateASTFactoryTest method declareRuleFromSimplePredicateFinalLeaf.

@Test
public void declareRuleFromSimplePredicateFinalLeaf() {
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    SimplePredicate simplePredicate = getSimplePredicate("outlook", "VALUE", SimplePredicate.Operator.LESS_THAN, fieldTypeMap);
    String parentPath = "_will play";
    String currentRule = "_will play_will play";
    String declaredType = fieldTypeMap.get("outlook").getGeneratedType();
    String result = "RESULT";
    final List<KiePMMLDroolsRule> rules = new ArrayList<>();
    PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simplePredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
    KiePMMLSimplePredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimplePredicate(result, true);
    assertEquals(1, rules.size());
    final KiePMMLDroolsRule retrieved = rules.get(0);
    assertNotNull(retrieved);
    assertEquals(currentRule, retrieved.getName());
    assertEquals(DONE, retrieved.getStatusToSet());
    assertEquals(String.format(KiePMMLAbstractModelASTFactory.STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
    assertEquals(ResultCode.OK, retrieved.getResultCode());
    assertEquals(result, retrieved.getResult());
    final List<KiePMMLFieldOperatorValue> andConstraints = retrieved.getAndConstraints();
    assertNotNull(andConstraints);
    assertEquals(1, andConstraints.size());
    KiePMMLFieldOperatorValue kiePMMLFieldOperatorValue = retrieved.getAndConstraints().get(0);
    assertEquals(declaredType, kiePMMLFieldOperatorValue.getName());
    assertEquals(BOOLEAN_OPERATOR.AND, kiePMMLFieldOperatorValue.getOperator());
    String expectedValue = "value < \"" + simplePredicate.getValue() + "\"";
    assertEquals(expectedValue, kiePMMLFieldOperatorValue.getConstraintsAsString());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) KiePMMLFieldOperatorValue(org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue) SimplePredicate(org.dmg.pmml.SimplePredicate) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 7 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLTruePredicateASTFactoryTest method declareRuleFromTruePredicateFinalLeaf.

@Test
public void declareRuleFromTruePredicateFinalLeaf() {
    String parentPath = "_will play";
    String currentRule = "_will play_will play";
    final List<KiePMMLDroolsRule> rules = new ArrayList<>();
    String statusToSet = DONE;
    True truePredicate = new True();
    PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(truePredicate, Collections.emptyList(), rules, parentPath, currentRule, Collections.emptyMap());
    KiePMMLTruePredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromTruePredicateWithResult(statusToSet, 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());
    assertNull(retrieved.getAndConstraints());
    assertEquals(DONE, retrieved.getResult());
    assertEquals(ResultCode.OK, retrieved.getResultCode());
}
Also used : ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) True(org.dmg.pmml.True) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) Test(org.junit.Test)

Example 8 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLScorecardModelCharacteristicASTFactoryTest method declareRuleFromAttributeWithSimplePredicateUseReasonCodesTrue.

@Test
public void declareRuleFromAttributeWithSimplePredicateUseReasonCodesTrue() {
    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().withReasonCodes(null, REASONCODE_ALGORITHM.POINTS_ABOVE).declareRuleFromAttribute(attribute, parentPath, attributeIndex, rules, statusToSet, characteristicReasonCode, characteristicBaselineScore, isLastCharacteristic);
    assertEquals(1, rules.size());
    KiePMMLDroolsRule toValidate = rules.get(0);
    commonValidateRule(toValidate, attribute, statusToSet, parentPath, attributeIndex, isLastCharacteristic, 1, null, BOOLEAN_OPERATOR.AND, "value <= 5.0", 1);
    KiePMMLReasonCodeAndValue retrieved = toValidate.getReasonCodeAndValue();
    assertNotNull(retrieved);
    assertEquals(characteristicReasonCode, retrieved.getReasonCode());
    double expected = attribute.getPartialScore().doubleValue() - characteristicBaselineScore;
    assertEquals(expected, retrieved.getValue(), 0);
}
Also used : Attribute(org.dmg.pmml.scorecard.Attribute) ArrayList(java.util.ArrayList) KiePMMLReasonCodeAndValue(org.kie.pmml.models.drools.tuples.KiePMMLReasonCodeAndValue) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) Test(org.junit.Test)

Example 9 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLScorecardModelCharacteristicASTFactoryTest method declareRuleFromAttributeWithSimpleSetPredicate.

@Test
public void declareRuleFromAttributeWithSimpleSetPredicate() {
    Attribute attribute = getSimpleSetPredicateAttribute();
    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, null, 1, null, null, null);
}
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 10 with KiePMMLDroolsRule

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsRule in project drools by kiegroup.

the class KiePMMLScorecardModelCharacteristicASTFactoryTest method declareRuleFromAttributeWithCompoundPredicate.

@Test
public void declareRuleFromAttributeWithCompoundPredicate() {
    Attribute attribute = getCompoundPredicateAttribute();
    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 && value < 12.0", 2);
}
Also used : Attribute(org.dmg.pmml.scorecard.Attribute) ArrayList(java.util.ArrayList) 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