Search in sources :

Example 11 with KiePMMLOriginalTypeGeneratedType

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());
}
Also used : KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) BeforeClass(org.junit.BeforeClass)

Example 12 with KiePMMLOriginalTypeGeneratedType

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())));
}
Also used : KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) DataField(org.dmg.pmml.DataField) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 13 with KiePMMLOriginalTypeGeneratedType

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) KiePMMLFieldOperatorValue(org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue) SimplePredicate(org.dmg.pmml.SimplePredicate) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 14 with KiePMMLOriginalTypeGeneratedType

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) KiePMMLFieldOperatorValue(org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue) SimplePredicate(org.dmg.pmml.SimplePredicate) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 15 with KiePMMLOriginalTypeGeneratedType

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) KiePMMLFieldOperatorValue(org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue) SimplePredicate(org.dmg.pmml.SimplePredicate) KiePMMLASTTestUtils.getPredicateASTFactoryData(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Aggregations

KiePMMLOriginalTypeGeneratedType (org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType)45 Test (org.junit.Test)32 HashMap (java.util.HashMap)29 ArrayList (java.util.ArrayList)16 KiePMMLDroolsRule (org.kie.pmml.models.drools.ast.KiePMMLDroolsRule)14 KiePMMLASTTestUtils.getPredicateASTFactoryData (org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getPredicateASTFactoryData)12 KiePMMLDroolsAST (org.kie.pmml.models.drools.ast.KiePMMLDroolsAST)11 SimplePredicate (org.dmg.pmml.SimplePredicate)9 KiePMMLDroolsType (org.kie.pmml.models.drools.ast.KiePMMLDroolsType)9 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)8 Field (org.dmg.pmml.Field)7 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)7 List (java.util.List)6 CompoundPredicate (org.dmg.pmml.CompoundPredicate)6 DataDictionary (org.dmg.pmml.DataDictionary)6 Map (java.util.Map)5 DataField (org.dmg.pmml.DataField)5 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)5 CommonTestingUtils.getFieldsFromDataDictionary (org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary)5 KiePMMLFieldOperatorValue (org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue)5