use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldsWithTargetFieldsWithTargetsWithOptType.
@Test
public void getTargetFieldsWithTargetFieldsWithTargetsWithOptType() {
final Model model = new RegressionModel();
final DataDictionary dataDictionary = new DataDictionary();
final MiningSchema miningSchema = new MiningSchema();
final Targets targets = new Targets();
IntStream.range(0, 3).forEach(i -> {
final String fieldName = "fieldName-" + i;
final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
dataDictionary.addDataFields(dataField);
final MiningField miningField = getMiningField(fieldName, MiningField.UsageType.PREDICTED);
miningField.setOpType(OpType.CONTINUOUS);
miningSchema.addMiningFields(miningField);
final Target targetField = getTarget(fieldName, OpType.CATEGORICAL);
targets.addTargets(targetField);
});
model.setMiningSchema(miningSchema);
model.setTargets(targets);
List<KiePMMLNameOpType> retrieved = ModelUtils.getTargetFields(getFieldsFromDataDictionary(dataDictionary), model);
assertNotNull(retrieved);
assertEquals(miningSchema.getMiningFields().size(), retrieved.size());
retrieved.forEach(kiePMMLNameOpType -> {
Optional<Target> optionalTarget = targets.getTargets().stream().filter(fld -> kiePMMLNameOpType.getName().equals(fld.getField().getValue())).findFirst();
assertTrue(optionalTarget.isPresent());
Target target = optionalTarget.get();
OP_TYPE expected = OP_TYPE.byName(target.getOpType().value());
assertEquals(expected, kiePMMLNameOpType.getOpType());
});
}
use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class ModelUtilsTest method getOpTypeByTargets.
@Test
public void getOpTypeByTargets() {
final Model model = new RegressionModel();
final DataDictionary dataDictionary = new DataDictionary();
final MiningSchema miningSchema = new MiningSchema();
final Targets targets = new Targets();
IntStream.range(0, 3).forEach(i -> {
final DataField dataField = getRandomDataField();
dataDictionary.addDataFields(dataField);
final MiningField miningField = getRandomMiningField();
miningField.setName(dataField.getName());
miningSchema.addMiningFields(miningField);
final Target targetField = getRandomTarget();
targetField.setField(dataField.getName());
targets.addTargets(targetField);
});
model.setMiningSchema(miningSchema);
model.setTargets(targets);
getFieldsFromDataDictionary(dataDictionary);
targets.getTargets().forEach(target -> {
OP_TYPE retrieved = ModelUtils.getOpType(getFieldsFromDataDictionary(dataDictionary), model, target.getField().getValue());
assertNotNull(retrieved);
OP_TYPE expected = OP_TYPE.byName(target.getOpType().value());
assertEquals(expected, retrieved);
});
}
use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class KiePMMLScorecardModelFactoryTest method getKiePMMLDroolsAST.
@Test
public void getKiePMMLDroolsAST() {
final DataDictionary dataDictionary = pmml.getDataDictionary();
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(dataDictionary, pmml.getTransformationDictionary(), scorecardModel.getLocalTransformations());
KiePMMLDroolsAST retrieved = KiePMMLScorecardModelFactory.getKiePMMLDroolsAST(getFieldsFromDataDictionary(dataDictionary), scorecardModel, fieldTypeMap, Collections.emptyList());
assertNotNull(retrieved);
}
use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class KiePMMLScorecardModelFactoryTest method getKiePMMLScorecardModelSourcesMap.
@Test
public void getKiePMMLScorecardModelSourcesMap() {
final DataDictionary dataDictionary = pmml.getDataDictionary();
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(dataDictionary, pmml.getTransformationDictionary(), scorecardModel.getLocalTransformations());
KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecardModel, new HasKnowledgeBuilderMock(knowledgeBuilder));
final DroolsCompilationDTO<Scorecard> droolsCompilationDTO = DroolsCompilationDTO.fromCompilationDTO(compilationDTO, fieldTypeMap);
Map<String, String> retrieved = KiePMMLScorecardModelFactory.getKiePMMLScorecardModelSourcesMap(droolsCompilationDTO);
assertNotNull(retrieved);
assertEquals(1, retrieved.size());
}
use of org.dmg.pmml.DataDictionary in project drools by kiegroup.
the class KiePMMLScorecardModelFactoryTest method getKiePMMLScorecardModel.
@Test
public void getKiePMMLScorecardModel() throws Exception {
final DataDictionary dataDictionary = pmml.getDataDictionary();
final Map<String, KiePMMLOriginalTypeGeneratedType> fieldTypeMap = getFieldTypeMap(dataDictionary, pmml.getTransformationDictionary(), scorecardModel.getLocalTransformations());
KnowledgeBuilderImpl knowledgeBuilder = new KnowledgeBuilderImpl();
final CommonCompilationDTO<Scorecard> compilationDTO = CommonCompilationDTO.fromGeneratedPackageNameAndFields(PACKAGE_NAME, pmml, scorecardModel, new HasKnowledgeBuilderMock(knowledgeBuilder));
final DroolsCompilationDTO<Scorecard> droolsCompilationDTO = DroolsCompilationDTO.fromCompilationDTO(compilationDTO, fieldTypeMap);
KiePMMLScorecardModel retrieved = KiePMMLScorecardModelFactory.getKiePMMLScorecardModel(droolsCompilationDTO);
assertNotNull(retrieved);
assertEquals(scorecardModel.getModelName(), retrieved.getName());
assertEquals(TARGET_FIELD, retrieved.getTargetField());
}
Aggregations