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());
}
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());
}
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);
}
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)));
}
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);
}
Aggregations