use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.
the class KiePMMLASTFactoryUtilsTest method setup.
@BeforeClass
public static void setup() {
fieldTypeMap = new HashMap<>();
simplePredicateNameType = new HashMap<>();
simplePredicateNameType.put("age", DataType.INTEGER);
simplePredicateNameType.put("weight", DataType.DOUBLE);
simplePredicateNameType.put("name", DataType.STRING);
simplePredicateNameType.put("runner", DataType.BOOLEAN);
simplePredicates = simplePredicateNameType.entrySet().stream().map(entry -> {
fieldTypeMap.put(entry.getKey(), new KiePMMLOriginalTypeGeneratedType(entry.getValue().value(), getSanitizedClassName(entry.getKey().toUpperCase())));
return PMMLModelTestUtils.getSimplePredicate(entry.getKey(), getRandomObject(entry.getValue()), getRandomSimplePredicateOperator());
}).collect(Collectors.toList());
compoundPredicates = IntStream.range(0, 4).mapToObj(index -> PMMLModelTestUtils.getCompoundPredicate(simplePredicates, index)).collect(Collectors.toList());
}
use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.
the class KiePMMLTreeModelFactoryTest method getKiePMMLDroolsAST.
@Test
public void getKiePMMLDroolsAST() {
final DataDictionary dataDictionary = pmml.getDataDictionary();
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(pmml.getDataDictionary(), pmml.getTransformationDictionary(), treeModel.getLocalTransformations());
KiePMMLDroolsAST retrieved = KiePMMLTreeModelFactory.getKiePMMLDroolsAST(getFieldsFromDataDictionary(dataDictionary), treeModel, fieldTypeMap, Collections.emptyList());
assertNotNull(retrieved);
List<DataField> dataFields = dataDictionary.getDataFields();
assertEquals(dataFields.size(), fieldTypeMap.size());
dataFields.forEach(dataField -> assertTrue(fieldTypeMap.containsKey(dataField.getName().getValue())));
}
use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.
the class KiePMMLSimplePredicateASTFactoryTest method declareRuleFromSimplePredicateSurrogateFinalLeaf.
@Test
public void declareRuleFromSimplePredicateSurrogateFinalLeaf() {
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
SimplePredicate simplePredicate = getSimplePredicate("outlook", "VALUE", SimplePredicate.Operator.LESS_THAN, fieldTypeMap);
String currentRule = "_will play_will play";
String agendaActivationGroup = "_will play_will play Group";
String result = "RESULT";
String parentPath = "parentPath";
final List<KiePMMLDroolsRule> rules = new ArrayList<>();
PredicateASTFactoryData predicateASTFactoryData = getPredicateASTFactoryData(simplePredicate, Collections.emptyList(), rules, parentPath, currentRule, fieldTypeMap);
KiePMMLSimplePredicateASTFactory.factory(predicateASTFactoryData).declareRuleFromSimplePredicateSurrogate(agendaActivationGroup, result, true);
assertEquals(2, rules.size());
// This is the "TRUE" matching rule
KiePMMLDroolsRule retrieved = rules.get(0);
assertNotNull(retrieved);
String baseExpectedRule = String.format(KiePMMLAbstractModelASTFactory.SURROGATE_RULENAME_PATTERN, currentRule, fieldTypeMap.get(simplePredicate.getField().getValue()).getGeneratedType());
String expectedRule = baseExpectedRule + "_TRUE";
assertEquals(expectedRule, retrieved.getName());
assertEquals(DONE, retrieved.getStatusToSet());
assertNull(retrieved.getStatusConstraint());
assertEquals(agendaActivationGroup, retrieved.getAgendaGroup());
assertEquals(agendaActivationGroup, retrieved.getActivationGroup());
assertNull(retrieved.getIfBreakField());
assertNull(retrieved.getIfBreakOperator());
assertNull(retrieved.getIfBreakValue());
assertNull(retrieved.getNotConstraints());
assertNotNull(retrieved.getAndConstraints());
assertEquals(1, retrieved.getAndConstraints().size());
KiePMMLFieldOperatorValue kiePMMLFieldOperatorValue = retrieved.getAndConstraints().get(0);
assertEquals("OUTLOOK", kiePMMLFieldOperatorValue.getName());
assertEquals(BOOLEAN_OPERATOR.SURROGATE, kiePMMLFieldOperatorValue.getOperator());
assertEquals("value < \"VALUE\"", kiePMMLFieldOperatorValue.getConstraintsAsString());
assertEquals(result, retrieved.getResult());
assertEquals(ResultCode.OK, retrieved.getResultCode());
// This is the "FALSE" matching rule
retrieved = rules.get(1);
assertNotNull(retrieved);
expectedRule = baseExpectedRule + "_FALSE";
assertEquals(expectedRule, retrieved.getName());
assertEquals(parentPath, retrieved.getStatusToSet());
assertNull(retrieved.getStatusConstraint());
assertEquals(agendaActivationGroup, retrieved.getAgendaGroup());
assertEquals(agendaActivationGroup, retrieved.getActivationGroup());
assertNull(retrieved.getIfBreakField());
assertNull(retrieved.getIfBreakOperator());
assertNull(retrieved.getIfBreakValue());
assertNull(retrieved.getAndConstraints());
assertNotNull(retrieved.getNotConstraints());
assertEquals(1, retrieved.getNotConstraints().size());
kiePMMLFieldOperatorValue = retrieved.getNotConstraints().get(0);
assertEquals("OUTLOOK", kiePMMLFieldOperatorValue.getName());
assertEquals(BOOLEAN_OPERATOR.SURROGATE, kiePMMLFieldOperatorValue.getOperator());
assertEquals("value < \"VALUE\"", kiePMMLFieldOperatorValue.getConstraintsAsString());
assertNull(retrieved.getResult());
assertNull(retrieved.getResultCode());
}
use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.
the class KiePMMLSimplePredicateASTFactoryTest method declareIntermediateRuleFromSimplePredicateNotFinalLeaf.
@Test
public void declareIntermediateRuleFromSimplePredicateNotFinalLeaf() {
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, false);
assertEquals(1, rules.size());
final KiePMMLDroolsRule retrieved = rules.get(0);
assertNotNull(retrieved);
assertEquals(currentRule, retrieved.getName());
assertEquals(currentRule, retrieved.getStatusToSet());
assertEquals(String.format(KiePMMLAbstractModelASTFactory.STATUS_PATTERN, parentPath), retrieved.getStatusConstraint());
assertEquals(currentRule, retrieved.getStatusToSet());
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.tuples.KiePMMLOriginalTypeGeneratedType 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());
}
Aggregations