Search in sources :

Example 1 with KiePMMLDroolsType

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsType 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 KiePMMLDroolsType

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsType 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)

Example 3 with KiePMMLDroolsType

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsType in project drools by kiegroup.

the class KiePMMLDataDictionaryASTFactoryTest method declareType.

@Test
public void declareType() {
    DataField dataField = getTypeDataField();
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    KiePMMLDroolsType retrieved = KiePMMLDataDictionaryASTFactory.factory(fieldTypeMap).declareType(dataField);
    assertNotNull(retrieved);
    commonVerifyTypeDeclarationDescr(dataField, fieldTypeMap, retrieved);
}
Also used : KiePMMLASTTestUtils.getDottedTypeDataField(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getDottedTypeDataField) DataField(org.dmg.pmml.DataField) KiePMMLASTTestUtils.getTypeDataField(org.kie.pmml.models.drools.utils.KiePMMLASTTestUtils.getTypeDataField) HashMap(java.util.HashMap) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 4 with KiePMMLDroolsType

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsType in project drools by kiegroup.

the class KiePMMLDescrTypesFactoryTest method declareType.

@Test
public void declareType() {
    KiePMMLDroolsType type = KiePMMLDescrTestUtils.getDroolsType();
    KiePMMLDescrTypesFactory.factory(builder).declareType(type);
    assertEquals(1, builder.getDescr().getTypeDeclarations().size());
    commonVerifyTypeDeclarationDescr(type, builder.getDescr().getTypeDeclarations().get(0));
}
Also used : KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) Test(org.junit.Test)

Example 5 with KiePMMLDroolsType

use of org.kie.pmml.models.drools.ast.KiePMMLDroolsType in project drools by kiegroup.

the class KiePMMLDescrFactoryTest method getBaseDescr.

@Test
public void getBaseDescr() {
    List<KiePMMLDroolsType> types = new ArrayList<>();
    types.add(KiePMMLDescrTestUtils.getDroolsType());
    types.add(KiePMMLDescrTestUtils.getDottedDroolsType());
    List<KiePMMLFieldOperatorValue> orConstraints = Arrays.asList(new KiePMMLFieldOperatorValue(PATTERN_TYPE, BOOLEAN_OPERATOR.OR, Collections.singletonList(new KiePMMLOperatorValue(OPERATOR.LESS_THAN, 35)), null), new KiePMMLFieldOperatorValue(PATTERN_TYPE, BOOLEAN_OPERATOR.AND, Collections.singletonList(new KiePMMLOperatorValue(OPERATOR.GREATER_THAN, 85)), null));
    KiePMMLDroolsRule rule = KiePMMLDroolsRule.builder(RULE_NAME, STATUS_TO_SET, Collections.emptyList()).withOrConstraints(orConstraints).build();
    List<KiePMMLDroolsRule> rules = new ArrayList<>();
    rules.add(rule);
    KiePMMLDroolsAST drooledAST = new KiePMMLDroolsAST(types, rules);
    PackageDescr packageDescr = KiePMMLDescrFactory.getBaseDescr(drooledAST, PACKAGE_NAME);
    assertEquals(PACKAGE_NAME, packageDescr.getName());
    checkImports(packageDescr.getImports());
    checkGlobals(packageDescr.getGlobals());
    checkRules(packageDescr.getRules());
}
Also used : KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) KiePMMLOperatorValue(org.kie.pmml.models.drools.tuples.KiePMMLOperatorValue) ArrayList(java.util.ArrayList) KiePMMLDroolsRule(org.kie.pmml.models.drools.ast.KiePMMLDroolsRule) KiePMMLFieldOperatorValue(org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Aggregations

KiePMMLDroolsType (org.kie.pmml.models.drools.ast.KiePMMLDroolsType)12 Test (org.junit.Test)9 KiePMMLOriginalTypeGeneratedType (org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType)9 KiePMMLDroolsAST (org.kie.pmml.models.drools.ast.KiePMMLDroolsAST)6 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 DataField (org.dmg.pmml.DataField)2 PackageDescr (org.drools.drl.ast.descr.PackageDescr)2 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 DataDictionary (org.dmg.pmml.DataDictionary)1 DerivedField (org.dmg.pmml.DerivedField)1 Field (org.dmg.pmml.Field)1 Model (org.dmg.pmml.Model)1 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1