Search in sources :

Example 1 with Attribute

use of org.dmg.pmml.scorecard.Attribute 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 2 with Attribute

use of org.dmg.pmml.scorecard.Attribute 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 3 with Attribute

use of org.dmg.pmml.scorecard.Attribute 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)

Example 4 with Attribute

use of org.dmg.pmml.scorecard.Attribute 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 5 with Attribute

use of org.dmg.pmml.scorecard.Attribute in project drools by kiegroup.

the class KiePMMLCharacteristicFactoryTest method getAttribute.

private Attribute getAttribute(List<String> values, int id) {
    Attribute toReturn = new Attribute();
    toReturn.setReasonCode(REASON_CODE + id);
    Array.Type arrayType = Array.Type.STRING;
    toReturn.setPredicate(getCompoundPredicate(values, arrayType));
    toReturn.setComplexPartialScore(getComplexPartialScore());
    return toReturn;
}
Also used : Array(org.dmg.pmml.Array) KiePMMLAttribute(org.kie.pmml.models.scorecard.model.KiePMMLAttribute) Attribute(org.dmg.pmml.scorecard.Attribute)

Aggregations

Attribute (org.dmg.pmml.scorecard.Attribute)15 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)6 KiePMMLDroolsRule (org.kie.pmml.models.drools.ast.KiePMMLDroolsRule)6 SimplePredicate (org.dmg.pmml.SimplePredicate)4 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)3 Array (org.dmg.pmml.Array)3 CompoundPredicate (org.dmg.pmml.CompoundPredicate)3 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicate)3 Characteristic (org.dmg.pmml.scorecard.Characteristic)3 Statement (com.github.javaparser.ast.stmt.Statement)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Constant (org.dmg.pmml.Constant)2 DataDictionary (org.dmg.pmml.DataDictionary)2 DataField (org.dmg.pmml.DataField)2