use of org.dmg.pmml.DataField in project drools by kiegroup.
the class KiePMMLUtil method populateMissingMiningTargetField.
/**
* Method to populate <code>MiningSchema</code> with a n ad-hoc created target <code>MiningField</code>.
* It also populate the given <code>List<DataField></code> with the relative <code>DataField</code>.
* This method has to be called <b>after</b> the model name has been set
* @param model
* @param dataFields
*/
static void populateMissingMiningTargetField(final Model model, final List<DataField> dataFields) {
List<MiningField> miningTargetFields = getMiningTargetFields(model.getMiningSchema().getMiningFields());
if (miningTargetFields.isEmpty()) {
Optional<DataField> targetDataField = getTargetDataField(model);
targetDataField.ifPresent(dataField -> {
dataFields.add(dataField);
MiningField targetMiningField = getTargetMiningField(dataField);
model.getMiningSchema().addMiningFields(targetMiningField);
correctTargetFields(targetMiningField, model.getTargets());
});
}
}
use of org.dmg.pmml.DataField in project drools by kiegroup.
the class KiePMMLUtil method getTargetDataField.
/**
* Returns a model-specific <b>target</b> <code>DataField</code>
* @param model
* @return
*/
static Optional<DataField> getTargetDataField(final Model model) {
DataType targetDataType = getTargetDataType(model.getMiningFunction(), model.getMathContext());
OpType targetOpType = getTargetOpType(model.getMiningFunction());
if (targetDataType == null || targetOpType == null) {
return Optional.empty();
}
String cleanedName = model.getModelName().replaceAll("[^A-Za-z0-9]", "");
String fieldName = String.format(TARGETFIELD_TEMPLATE, cleanedName);
DataField toReturn = new DataField();
toReturn.setName(FieldName.create(fieldName));
toReturn.setOpType(targetOpType);
toReturn.setDataType(targetDataType);
return Optional.of(toReturn);
}
use of org.dmg.pmml.DataField in project drools by kiegroup.
the class KiePMMLSimplePredicateInstanceFactoryTest method getKiePMMLSimplePredicate.
@Test
public void getKiePMMLSimplePredicate() {
List<Field<?>> fields = IntStream.range(0, 3).mapToObj(i -> getRandomDataField()).collect(Collectors.toList());
final SimplePredicate toConvert = getRandomSimplePredicate((DataField) fields.get(0));
final KiePMMLSimplePredicate retrieved = KiePMMLSimplePredicateInstanceFactory.getKiePMMLSimplePredicate(toConvert, fields);
commonVerifyKiePMMLSimplePredicate(retrieved, toConvert, (DataField) fields.get(0));
}
use of org.dmg.pmml.DataField 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);
}
use of org.dmg.pmml.DataField in project drools by kiegroup.
the class DroolsModelProviderTest method getKiePMMLModelWithKnowledgeBuilder.
@Test
public void getKiePMMLModelWithKnowledgeBuilder() {
KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecard, new HasKnowledgeBuilderMock(knowledgeBuilder));
KiePMMLDroolsModel retrieved = droolsModelProvider.getKiePMMLModel(compilationDTO);
assertNotNull(retrieved);
assertTrue(retrieved instanceof KiePMMLDroolsModelTest);
KiePMMLDroolsModelTest retrievedTest = (KiePMMLDroolsModelTest) retrieved;
final List<DataField> originalDataFields = pmml.getDataDictionary().getDataFields();
final List<DataField> retrievedDataFields = retrievedTest.dataDictionary.getDataFields();
assertEquals(originalDataFields.size(), retrievedTest.dataDictionary.getDataFields().size());
originalDataFields.forEach(dataField -> {
Optional<DataField> optRet = retrievedDataFields.stream().filter(retrievedDataField -> dataField.getName().equals(retrievedDataField.getName())).findFirst();
assertTrue(optRet.isPresent());
assertEquals(dataField.getDataType(), optRet.get().getDataType());
});
assertEquals(pmml.getTransformationDictionary(), retrievedTest.transformationDictionary);
assertEquals(scorecard, retrievedTest.model);
String expectedPackageName = getSanitizedPackageName(PACKAGE_NAME);
assertEquals(expectedPackageName, retrievedTest.getKModulePackageName());
assertEquals(PACKAGE_NAME, retrievedTest.getName());
PackageDescr packageDescr = knowledgeBuilder.getPackageDescrs("packagename").get(0);
assertTrue(packageDescr instanceof CompositePackageDescr);
}
Aggregations