use of org.dmg.pmml.SimpleSetPredicate in project drools by kiegroup.
the class KiePMMLSimpleSetPredicateASTFactoryTest method declareRuleFromSimpleSetPredicateIsInFinalLeaf.
@Test
public void declareRuleFromSimpleSetPredicateIsInFinalLeaf() {
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
List<String> values = Arrays.asList("-5", "0.5", "1", "10");
final SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate("input1", values, SimpleSetPredicate.BooleanOperator.IS_IN, fieldTypeMap);
String parentPath = "_classA";
String currentRule = "_classA_classB";
String result = "classB";
String declaredType = fieldTypeMap.get("input1").getGeneratedType();
final List<KiePMMLDroolsRule> rules = new ArrayList<>();
PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simpleSetPredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
KiePMMLSimpleSetPredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimpleSetPredicate(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(STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
assertEquals(ResultCode.OK, retrieved.getResultCode());
assertEquals(result, retrieved.getResult());
assertNotNull(retrieved.getInConstraints());
final Map<String, List<Object>> inConstraints = retrieved.getInConstraints();
assertEquals(1, inConstraints.size());
assertTrue(inConstraints.containsKey(declaredType));
final List<Object> retrievedValues = inConstraints.get(declaredType);
List<String> originalPredicateValues = Arrays.asList(((String) simpleSetPredicate.getArray().getValue()).split(" "));
assertEquals(originalPredicateValues.size(), retrievedValues.size());
retrievedValues.forEach(retrievedValue -> {
assertTrue(originalPredicateValues.contains(retrievedValue));
});
}
use of org.dmg.pmml.SimpleSetPredicate in project drools by kiegroup.
the class KiePMMLSimpleSetPredicateASTFactoryTest method declareRuleFromSimpleSetPredicateIsNotInNotFinalLeaf.
@Test
public void declareRuleFromSimpleSetPredicateIsNotInNotFinalLeaf() {
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
List<String> values = Arrays.asList("3", "8.5");
final SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate("input2", values, SimpleSetPredicate.BooleanOperator.IS_NOT_IN, fieldTypeMap);
String parentPath = "_classA";
String currentRule = "_classA_classC";
String result = "classC";
String declaredType = fieldTypeMap.get("input2").getGeneratedType();
final List<KiePMMLDroolsRule> rules = new ArrayList<>();
PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simpleSetPredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
KiePMMLSimpleSetPredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimpleSetPredicate(result, false);
assertEquals(1, rules.size());
final KiePMMLDroolsRule retrieved = rules.get(0);
assertNotNull(retrieved);
assertEquals(currentRule, retrieved.getName());
assertEquals(currentRule, retrieved.getStatusToSet());
assertEquals(String.format(STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
assertNull(retrieved.getResultCode());
assertNull(retrieved.getResult());
assertNotNull(retrieved.getNotInConstraints());
final Map<String, List<Object>> notInConstraints = retrieved.getNotInConstraints();
assertEquals(1, notInConstraints.size());
assertTrue(notInConstraints.containsKey(declaredType));
final List<Object> retrievedValues = notInConstraints.get(declaredType);
List<String> originalPredicateValues = Arrays.asList(((String) simpleSetPredicate.getArray().getValue()).split(" "));
assertEquals(originalPredicateValues.size(), retrievedValues.size());
retrievedValues.forEach(retrievedValue -> {
assertTrue(originalPredicateValues.contains(retrievedValue));
});
}
use of org.dmg.pmml.SimpleSetPredicate in project drools by kiegroup.
the class KiePMMLSimpleSetPredicateASTFactoryTest method declareRuleFromSimpleSetPredicateIsInNotFinalLeaf.
@Test
public void declareRuleFromSimpleSetPredicateIsInNotFinalLeaf() {
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
List<String> values = Arrays.asList("-5", "0.5", "1", "10");
final SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate("input1", values, SimpleSetPredicate.BooleanOperator.IS_IN, fieldTypeMap);
String parentPath = "_classA";
String currentRule = "_classA_classB";
String result = "classB";
String declaredType = fieldTypeMap.get("input1").getGeneratedType();
final List<KiePMMLDroolsRule> rules = new ArrayList<>();
PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simpleSetPredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
KiePMMLSimpleSetPredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimpleSetPredicate(result, false);
assertEquals(1, rules.size());
final KiePMMLDroolsRule retrieved = rules.get(0);
assertNotNull(retrieved);
assertEquals(currentRule, retrieved.getName());
assertEquals(currentRule, retrieved.getStatusToSet());
assertEquals(String.format(STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
assertNull(retrieved.getResultCode());
assertNull(retrieved.getResult());
assertNotNull(retrieved.getInConstraints());
final Map<String, List<Object>> inConstraints = retrieved.getInConstraints();
assertEquals(1, inConstraints.size());
assertTrue(inConstraints.containsKey(declaredType));
final List<Object> retrievedValues = inConstraints.get(declaredType);
List<String> originalPredicateValues = Arrays.asList(((String) simpleSetPredicate.getArray().getValue()).split(" "));
assertEquals(originalPredicateValues.size(), retrievedValues.size());
retrievedValues.forEach(retrievedValue -> {
assertTrue(originalPredicateValues.contains(retrievedValue));
});
}
use of org.dmg.pmml.SimpleSetPredicate 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());
}
use of org.dmg.pmml.SimpleSetPredicate in project drools by kiegroup.
the class KiePMMLCharacteristicFactoryTest method getCompoundPredicate.
private CompoundPredicate getCompoundPredicate(List<String> values, Array.Type arrayType) {
SimplePredicate simplePredicate1 = getSimplePredicate(PARAM_1, value1, operator1);
SimplePredicate simplePredicate2 = getSimplePredicate(PARAM_2, value2, operator2);
SimpleSetPredicate simpleSetPredicate = getSimpleSetPredicate(values, arrayType, SimpleSetPredicate.BooleanOperator.IS_IN);
CompoundPredicate toReturn = new CompoundPredicate();
toReturn.setBooleanOperator(CompoundPredicate.BooleanOperator.AND);
toReturn.getPredicates().add(0, simplePredicate1);
toReturn.getPredicates().add(1, simplePredicate2);
toReturn.getPredicates().add(2, simpleSetPredicate);
return toReturn;
}
Aggregations