use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldTypeWithTargetField.
@Test
public void getTargetFieldTypeWithTargetField() {
final String fieldName = "fieldName";
MiningField.UsageType usageType = MiningField.UsageType.PREDICTED;
MiningField miningField = getMiningField(fieldName, usageType);
final DataField dataField = getDataField(fieldName, OpType.CATEGORICAL, DataType.STRING);
final DataDictionary dataDictionary = new DataDictionary();
dataDictionary.addDataFields(dataField);
final MiningSchema miningSchema = new MiningSchema();
miningSchema.addMiningFields(miningField);
final Model model = new RegressionModel();
model.setMiningSchema(miningSchema);
DATA_TYPE retrieved = ModelUtils.getTargetFieldType(getFieldsFromDataDictionary(dataDictionary), model);
assertNotNull(retrieved);
assertEquals(DATA_TYPE.STRING, retrieved);
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getDataTypeFromDataDictionary.
@Test
public void getDataTypeFromDataDictionary() {
final DataDictionary dataDictionary = new DataDictionary();
IntStream.range(0, 3).forEach(i -> {
final DataField dataField = getRandomDataField();
dataDictionary.addDataFields(dataField);
});
dataDictionary.getDataFields().forEach(dataField -> {
DATA_TYPE retrieved = ModelUtils.getDATA_TYPE(getFieldsFromDataDictionary(dataDictionary), dataField.getName().getValue());
assertNotNull(retrieved);
DATA_TYPE expected = DATA_TYPE.byName(dataField.getDataType().value());
assertEquals(expected, retrieved);
});
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class ModelUtilsTest method getTargetFieldsWithoutTargetFieldsWithTargets.
@Test
public void getTargetFieldsWithoutTargetFieldsWithTargets() {
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 = getMiningField(dataField.getName().getValue(), MiningField.UsageType.ACTIVE);
miningSchema.addMiningFields(miningField);
final Target targetField = getTarget(dataField.getName().getValue(), null);
targets.addTargets(targetField);
});
model.setMiningSchema(miningSchema);
model.setTargets(targets);
Map<String, DATA_TYPE> retrieved = ModelUtils.getTargetFieldsTypeMap(getFieldsFromDataDictionary(dataDictionary), model);
assertNotNull(retrieved);
assertTrue(retrieved.isEmpty());
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class CommonCodegenUtils method getExpressionForDataType.
public static Expression getExpressionForDataType(DataType dataTypeParam) {
final Expression toReturn;
if (dataTypeParam != null) {
final DATA_TYPE dataType = DATA_TYPE.byName(dataTypeParam.value());
toReturn = new NameExpr(DATA_TYPE.class.getName() + "." + dataType.name());
} else {
toReturn = new NullLiteralExpr();
}
return toReturn;
}
use of org.kie.pmml.api.enums.DATA_TYPE in project drools by kiegroup.
the class KiePMMLDiscretizeInstanceFactory method getKiePMMLDiscretize.
static KiePMMLDiscretize getKiePMMLDiscretize(final Discretize discretize) {
List<KiePMMLDiscretizeBin> discretizeBins = discretize.hasDiscretizeBins() ? getKiePMMLDiscretizeBins(discretize.getDiscretizeBins()) : Collections.emptyList();
String mapMissingTo = discretize.getMapMissingTo() != null ? discretize.getMapMissingTo().toString() : null;
String defaultValue = discretize.getDefaultValue() != null ? discretize.getDefaultValue().toString() : null;
DATA_TYPE dataType = discretize.getDataType() != null ? DATA_TYPE.byName(discretize.getDataType().value()) : null;
return new KiePMMLDiscretize(discretize.getField().getValue(), getKiePMMLExtensions(discretize.getExtensions()), discretizeBins, mapMissingTo, defaultValue, dataType);
}
Aggregations