Search in sources :

Example 1 with KiePMMLOriginalTypeGeneratedType

use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.

the class KiePMMLTreeModelASTFactoryTest method getKiePMMLDroolsSimpleSetAST.

@Test
public void getKiePMMLDroolsSimpleSetAST() {
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(simpleSetPmml.getDataDictionary(), simpleSetPmml.getTransformationDictionary(), simpleSetModel.getLocalTransformations());
    List<KiePMMLDroolsType> types = Collections.emptyList();
    KiePMMLDroolsAST retrieved = KiePMMLTreeModelASTFactory.getKiePMMLDroolsAST(getFieldsFromDataDictionary(simpleSetPmml.getDataDictionary()), simpleSetModel, fieldTypeMap, types);
    assertNotNull(retrieved);
    assertEquals(types, retrieved.getTypes());
    assertFalse(retrieved.getRules().isEmpty());
}
Also used : KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 2 with KiePMMLOriginalTypeGeneratedType

use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.

the class KiePMMLTreeModelNodeASTFactoryTest method declareIntermediateRuleFromGolfingNode.

@Test
public void declareIntermediateRuleFromGolfingNode() {
    Node finalNode = golfingModel.getNode().getNodes().get(0);
    assertEquals("will play", finalNode.getScore());
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    final List<Field<?>> fields = getFieldsFromDataDictionary(golfingPmml.getDataDictionary());
    DATA_TYPE targetType = getTargetFieldType(fields, golfingModel);
    KiePMMLDataDictionaryASTFactory.factory(fieldTypeMap).declareTypes(fields);
    final List<KiePMMLDroolsRule> rules = new ArrayList<>();
    KiePMMLTreeModelNodeASTFactory.factory(fieldTypeMap, Collections.emptyList(), TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION, targetType).declareIntermediateRuleFromNode(finalNode, "_will play", rules);
    assertFalse(rules.isEmpty());
}
Also used : Field(org.dmg.pmml.Field) HashMap(java.util.HashMap) LeafNode(org.dmg.pmml.tree.LeafNode) Node(org.dmg.pmml.tree.Node) ClassifierNode(org.dmg.pmml.tree.ClassifierNode) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 3 with KiePMMLOriginalTypeGeneratedType

use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.

the class KiePMMLTreeModelNodeASTFactoryTest method declareRulesFromRootGolfingNode.

@Test
public void declareRulesFromRootGolfingNode() {
    Node rootNode = golfingModel.getNode();
    assertEquals("will play", rootNode.getScore());
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    final List<Field<?>> fields = getFieldsFromDataDictionary(golfingPmml.getDataDictionary());
    DATA_TYPE targetType = getTargetFieldType(fields, golfingModel);
    KiePMMLDataDictionaryASTFactory.factory(fieldTypeMap).declareTypes(fields);
    KiePMMLTreeModelNodeASTFactory.factory(fieldTypeMap, Collections.emptyList(), TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION, targetType).declareRulesFromRootNode(rootNode, "_will");
    assertFalse(fieldTypeMap.isEmpty());
}
Also used : Field(org.dmg.pmml.Field) HashMap(java.util.HashMap) LeafNode(org.dmg.pmml.tree.LeafNode) Node(org.dmg.pmml.tree.Node) ClassifierNode(org.dmg.pmml.tree.ClassifierNode) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 4 with KiePMMLOriginalTypeGeneratedType

use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.

the class KiePMMLTreeModelNodeASTFactoryTest method declareIntermediateRuleFromIrisNode.

@Test
public void declareIntermediateRuleFromIrisNode() {
    Node finalNode = irisModel.getNode().getNodes().get(1);
    assertEquals("versicolor", finalNode.getScore());
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    final List<Field<?>> fields = getFieldsFromDataDictionary(irisPmml.getDataDictionary());
    DATA_TYPE targetType = getTargetFieldType(fields, irisModel);
    KiePMMLDataDictionaryASTFactory.factory(fieldTypeMap).declareTypes(fields);
    final List<KiePMMLDroolsRule> rules = new ArrayList<>();
    KiePMMLTreeModelNodeASTFactory.factory(fieldTypeMap, Collections.emptyList(), TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION, targetType).declareIntermediateRuleFromNode(finalNode, "_setosa", rules);
    assertFalse(rules.isEmpty());
}
Also used : Field(org.dmg.pmml.Field) HashMap(java.util.HashMap) LeafNode(org.dmg.pmml.tree.LeafNode) Node(org.dmg.pmml.tree.Node) ClassifierNode(org.dmg.pmml.tree.ClassifierNode) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 5 with KiePMMLOriginalTypeGeneratedType

use of org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType in project drools by kiegroup.

the class KiePMMLDerivedFieldASTFactory method declareType.

/**
 * Create a <code>KiePMMLDroolsType</code> out of original <code>DerivedField</code>,
 * and <b>populate</b> the <b>fieldNameTypeNameMap</b> with mapping between original field' name and <b>original type/generated type</b> tupla
 * @param derivedField
 */
public KiePMMLDroolsType declareType(DerivedField derivedField) {
    String generatedType = getSanitizedClassName(derivedField.getName().getValue().toUpperCase());
    String fieldName = derivedField.getName().getValue();
    String fieldType = derivedField.getDataType().value();
    fieldTypeMap.put(fieldName, new KiePMMLOriginalTypeGeneratedType(fieldType, generatedType));
    return new KiePMMLDroolsType(generatedType, DATA_TYPE.byName(fieldType).getMappedClass().getSimpleName());
}
Also used : KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType)

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