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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations