Search in sources :

Example 6 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 7 with Attribute

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

the class KiePMMLScorecardModelCharacteristicASTFactoryTest method getSimplePredicateAttribute.

private Attribute getSimplePredicateAttribute() {
    final double partialScore = 10.0;
    Attribute toReturn = new Attribute();
    toReturn.setPartialScore(partialScore);
    toReturn.setPredicate(getSimplePredicate(fieldName, DataType.DOUBLE, 5.0, SimplePredicate.Operator.LESS_OR_EQUAL, new HashMap<>()));
    return toReturn;
}
Also used : Attribute(org.dmg.pmml.scorecard.Attribute) HashMap(java.util.HashMap)

Example 8 with Attribute

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

the class KiePMMLScorecardModelCharacteristicASTFactoryTest method getSimpleSetPredicateAttribute.

private Attribute getSimpleSetPredicateAttribute() {
    final double partialScore = -10.0;
    Attribute toReturn = new Attribute();
    toReturn.setPartialScore(partialScore);
    toReturn.setPredicate(getSimpleSetPredicate("occupation", Array.Type.STRING, Arrays.asList("SKYDIVER", "ASTRONAUT"), SimpleSetPredicate.BooleanOperator.IS_IN, new HashMap<>()));
    return toReturn;
}
Also used : Attribute(org.dmg.pmml.scorecard.Attribute) HashMap(java.util.HashMap)

Example 9 with Attribute

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

the class KiePMMLScorecardModelCharacteristicASTFactoryTest method getKiePMMLReasonCodeAndValueUseReasonCodesTrue.

@Test
public void getKiePMMLReasonCodeAndValueUseReasonCodesTrue() {
    String characteristicReasonCode = "CHARACTERISTIC_REASON_CODE";
    String attributeReasonCode = "ATTRIBUTE_REASON_CODE";
    double baselineScore = 13;
    double characteristicBaselineScore = 24.45;
    double attributePartialScore = 13.17;
    Attribute attribute = new Attribute();
    attribute.setPartialScore(attributePartialScore);
    KiePMMLReasonCodeAndValue retrieved = getKiePMMLScorecardModelCharacteristicASTFactory().withReasonCodes(baselineScore, REASONCODE_ALGORITHM.POINTS_ABOVE).getKiePMMLReasonCodeAndValue(attribute, characteristicReasonCode, null);
    assertNotNull(retrieved);
    assertEquals(characteristicReasonCode, retrieved.getReasonCode());
    double expected = attributePartialScore - baselineScore;
    assertEquals(expected, retrieved.getValue(), 0);
    retrieved = getKiePMMLScorecardModelCharacteristicASTFactory().withReasonCodes(baselineScore, REASONCODE_ALGORITHM.POINTS_ABOVE).getKiePMMLReasonCodeAndValue(attribute, characteristicReasonCode, characteristicBaselineScore);
    assertNotNull(retrieved);
    assertEquals(characteristicReasonCode, retrieved.getReasonCode());
    expected = attributePartialScore - characteristicBaselineScore;
    assertEquals(expected, retrieved.getValue(), 0);
    attribute.setReasonCode(attributeReasonCode);
    retrieved = getKiePMMLScorecardModelCharacteristicASTFactory().withReasonCodes(baselineScore, REASONCODE_ALGORITHM.POINTS_ABOVE).getKiePMMLReasonCodeAndValue(attribute, characteristicReasonCode, characteristicBaselineScore);
    assertNotNull(retrieved);
    assertEquals(attributeReasonCode, retrieved.getReasonCode());
    assertEquals(expected, retrieved.getValue(), 0);
}
Also used : Attribute(org.dmg.pmml.scorecard.Attribute) KiePMMLReasonCodeAndValue(org.kie.pmml.models.drools.tuples.KiePMMLReasonCodeAndValue) Test(org.junit.Test)

Example 10 with Attribute

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

the class KiePMMLScorecardModelCharacteristicASTFactoryTest method declareRulesFromCharacteristics.

@Test
public void declareRulesFromCharacteristics() {
    Characteristics characteristics = scorecardModel.getCharacteristics();
    String parentPath = "_will";
    List<KiePMMLDroolsRule> retrieved = getKiePMMLScorecardModelCharacteristicASTFactory().declareRulesFromCharacteristics(characteristics, parentPath, null);
    final List<Characteristic> characteristicList = characteristics.getCharacteristics();
    List<Attribute> attributes = new ArrayList<>();
    AtomicInteger counter = new AtomicInteger(0);
    for (int i = 0; i < characteristicList.size(); i++) {
        Characteristic characteristic = characteristicList.get(i);
        attributes.addAll(characteristic.getAttributes());
        for (int j = 0; j < characteristic.getAttributes().size(); j++) {
            Attribute attribute = characteristic.getAttributes().get(j);
            KiePMMLDroolsRule rule = retrieved.get(counter.incrementAndGet());
            int expectedOperatorValuesSize = 1;
            Integer expectedAndConstraints = null;
            Integer expectedInConstraints = null;
            BOOLEAN_OPERATOR expectedOperator = BOOLEAN_OPERATOR.AND;
            if (attribute.getPredicate() instanceof SimplePredicate) {
                expectedAndConstraints = 1;
            }
            if (attribute.getPredicate() instanceof CompoundPredicate) {
                expectedOperatorValuesSize = ((CompoundPredicate) attribute.getPredicate()).getPredicates().size();
                expectedAndConstraints = 1;
            }
            if (attribute.getPredicate() instanceof SimpleSetPredicate) {
                expectedInConstraints = 1;
            }
            boolean isLastCharacteristic = (i == characteristicList.size() - 1);
            String statusToSet = isLastCharacteristic ? DONE : String.format(PATH_PATTERN, parentPath, characteristicList.get(i + 1).getName());
            commonValidateRule(rule, attribute, statusToSet, parentPath + "_" + characteristic.getName(), j, isLastCharacteristic, expectedAndConstraints, expectedInConstraints, expectedOperator, null, expectedOperatorValuesSize);
        }
    }
    assertEquals(attributes.size() + 1, retrieved.size());
}
Also used : Attribute(org.dmg.pmml.scorecard.Attribute) Characteristic(org.dmg.pmml.scorecard.Characteristic) ArrayList(java.util.ArrayList) BOOLEAN_OPERATOR(org.kie.pmml.api.enums.BOOLEAN_OPERATOR) SimplePredicate(org.dmg.pmml.SimplePredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Characteristics(org.dmg.pmml.scorecard.Characteristics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) CompoundPredicate(org.dmg.pmml.CompoundPredicate) Test(org.junit.Test)

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