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