Search in sources :

Example 6 with KiePMMLDroolsType

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

the class KiePMMLDataDictionaryASTFactory method declareType.

/**
 * Create a <code>KiePMMLDroolsType</code> out of original <code>DataField</code>,
 * and <b>populate</b> the <b>fieldNameTypeNameMap</b> with mapping between original field' name and <b>original
 * type/generated type</b> tupla
 * @param field
 */
public KiePMMLDroolsType declareType(Field field) {
    String generatedType = getGeneratedClassName(field.getName().getValue());
    String fieldName = field.getName().getValue();
    String fieldType = field.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 7 with KiePMMLDroolsType

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

the class KiePMMLScorecardModelASTFactoryTest method getKiePMMLDroolsSampleAST.

@Test
public void getKiePMMLDroolsSampleAST() {
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(samplePmml.getDataDictionary(), samplePmml.getTransformationDictionary(), scorecardModel.getLocalTransformations());
    List<KiePMMLDroolsType> types = Collections.emptyList();
    KiePMMLDroolsAST retrieved = KiePMMLScorecardModelASTFactory.getKiePMMLDroolsAST(getFieldsFromDataDictionary(samplePmml.getDataDictionary()), scorecardModel, 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 8 with KiePMMLDroolsType

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

the class DroolsModelProvider method getKiePMMLDroolsASTCommon.

/**
 * @param fields Should contain all fields retrieved from model, i.e. DataFields from DataDictionary,
 * DerivedFields from Transformations/LocalTransformations, OutputFields
 * @param model
 * @param fieldTypeMap
 * @return
 */
protected KiePMMLDroolsAST getKiePMMLDroolsASTCommon(final List<Field<?>> fields, final T model, final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap) {
    List<KiePMMLDroolsType> types = fieldTypeMap.values().stream().map(kiePMMLOriginalTypeGeneratedType -> {
        String type = DATA_TYPE.byName(kiePMMLOriginalTypeGeneratedType.getOriginalType()).getMappedClass().getSimpleName();
        return new KiePMMLDroolsType(kiePMMLOriginalTypeGeneratedType.getGeneratedType(), type);
    }).collect(Collectors.toList());
    types.addAll(KiePMMLDataDictionaryASTFactory.factory(fieldTypeMap).declareTypes(fields));
    return getKiePMMLDroolsAST(fields, model, fieldTypeMap, types);
}
Also used : KiePMMLDroolsModel(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModel) DescrResource(org.drools.core.io.impl.DescrResource) EXPECTING_HAS_KNOWLEDGEBUILDER_TEMPLATE(org.kie.pmml.commons.Constants.EXPECTING_HAS_KNOWLEDGEBUILDER_TEMPLATE) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Model(org.dmg.pmml.Model) CompositeKnowledgeBuilder(org.kie.internal.builder.CompositeKnowledgeBuilder) DroolsCompilationDTO(org.kie.pmml.models.drools.dto.DroolsCompilationDTO) KiePMMLDescrFactory.getBaseDescr(org.kie.pmml.models.drools.commons.factories.KiePMMLDescrFactory.getBaseDescr) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) LoggerFactory(org.slf4j.LoggerFactory) StringUtils.getPkgUUID(org.drools.core.util.StringUtils.getPkgUUID) HashMap(java.util.HashMap) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) ModelImplementationProvider(org.kie.pmml.compiler.api.provider.ModelImplementationProvider) ResourceType(org.kie.api.io.ResourceType) ArrayList(java.util.ArrayList) Field(org.dmg.pmml.Field) Map(java.util.Map) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) KiePMMLModelWithSources(org.kie.pmml.commons.model.KiePMMLModelWithSources) ModelBuilderImpl(org.drools.modelcompiler.builder.ModelBuilderImpl) CompilationDTO(org.kie.pmml.compiler.api.dto.CompilationDTO) PackageSources(org.drools.modelcompiler.builder.PackageSources) Logger(org.slf4j.Logger) PackageDescr(org.drools.drl.ast.descr.PackageDescr) IOException(java.io.IOException) HasKnowledgeBuilder(org.kie.pmml.kie.dependencies.HasKnowledgeBuilder) Collectors(java.util.stream.Collectors) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) GeneratedFile(org.drools.modelcompiler.builder.GeneratedFile) KiePMMLDataDictionaryASTFactory(org.kie.pmml.models.drools.ast.factories.KiePMMLDataDictionaryASTFactory) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ReleaseIdImpl(org.kie.util.maven.support.ReleaseIdImpl) DroolsError(org.drools.drl.parser.DroolsError) KiePMMLDroolsAST(org.kie.pmml.models.drools.ast.KiePMMLDroolsAST) KiePMMLDroolsModelWithSources(org.kie.pmml.models.drools.commons.model.KiePMMLDroolsModelWithSources) CompositePackageDescr(org.drools.compiler.lang.descr.CompositePackageDescr) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType)

Example 9 with KiePMMLDroolsType

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

the class KiePMMLDataDictionaryASTFactoryTest method declareTypes.

@Test
public void declareTypes() {
    List<DataField> dataFields = Arrays.asList(getTypeDataField(), getDottedTypeDataField(), getTypeDataField(), getDottedTypeDataField());
    DataDictionary dataDictionary = new DataDictionary(dataFields);
    final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = new HashMap<>();
    List<KiePMMLDroolsType> retrieved = KiePMMLDataDictionaryASTFactory.factory(fieldTypeMap).declareTypes(getFieldsFromDataDictionary(dataDictionary));
    assertNotNull(retrieved);
    assertEquals(dataFields.size(), retrieved.size());
    IntStream.range(0, dataFields.size()).forEach(i -> commonVerifyTypeDeclarationDescr(dataFields.get(i), fieldTypeMap, retrieved.get(i)));
}
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) DataDictionary(org.dmg.pmml.DataDictionary) CommonTestingUtils.getFieldsFromDataDictionary(org.kie.pmml.compiler.api.CommonTestingUtils.getFieldsFromDataDictionary) KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) KiePMMLOriginalTypeGeneratedType(org.kie.pmml.models.drools.tuples.KiePMMLOriginalTypeGeneratedType) Test(org.junit.Test)

Example 10 with KiePMMLDroolsType

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

the class KiePMMLDerivedFieldASTFactoryTest method declareType.

@Test
public void declareType() {
    DerivedField derivedField = getDerivedField("FieldName");
    KiePMMLDroolsType retrieved = fieldASTFactory.declareType(derivedField);
    commonValidateKiePMMLDroolsType(retrieved, derivedField);
}
Also used : KiePMMLDroolsType(org.kie.pmml.models.drools.ast.KiePMMLDroolsType) DerivedField(org.dmg.pmml.DerivedField) 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