use of org.dmg.pmml.DataField in project drools by kiegroup.
the class ModelUtils method convertToKieOutputField.
/**
* Return a <code>org.kie.pmml.api.models.OutputField</code> out of a <code>org.dmg.pmml.OutputField</code> one
* @param toConvert
* @param field - this may be <code>null</code>
* @return
*/
public static org.kie.pmml.api.models.OutputField convertToKieOutputField(final OutputField toConvert, final Field<?> field) {
final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
final DATA_TYPE dataFieldDataType = field != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
final DATA_TYPE dataType = toConvert.getDataType() != null ? DATA_TYPE.byName(toConvert.getDataType().value()) : dataFieldDataType;
final String targetField = toConvert.getTargetField() != null ? toConvert.getTargetField().getValue() : null;
final RESULT_FEATURE resultFeature = toConvert.getResultFeature() != null ? RESULT_FEATURE.byName(toConvert.getResultFeature().value()) : null;
final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : null;
return new org.kie.pmml.api.models.OutputField(name, opType, dataType, targetField, resultFeature, allowedValues);
}
use of org.dmg.pmml.DataField in project drools by kiegroup.
the class ModelUtils method convertToKieMiningField.
/**
* Return a <code>org.kie.pmml.api.models.MiningField</code> out of a <code>org.dmg.pmml.MiningField</code> and
* relative <code>org.dmg.pmml.DataField</code> ones
* @param toConvert
* @param field
* @return
*/
public static org.kie.pmml.api.models.MiningField convertToKieMiningField(final MiningField toConvert, final Field<?> field) {
final String name = toConvert.getName() != null ? toConvert.getName().getValue() : null;
final FIELD_USAGE_TYPE fieldUsageType = toConvert.getUsageType() != null ? FIELD_USAGE_TYPE.byName(toConvert.getUsageType().value()) : null;
final OP_TYPE opType = toConvert.getOpType() != null ? OP_TYPE.byName(toConvert.getOpType().value()) : null;
final DATA_TYPE dataType = field.getDataType() != null ? DATA_TYPE.byName(field.getDataType().value()) : null;
final MISSING_VALUE_TREATMENT_METHOD missingValueTreatmentMethod = toConvert.getMissingValueTreatment() != null ? MISSING_VALUE_TREATMENT_METHOD.byName(toConvert.getMissingValueTreatment().value()) : null;
final INVALID_VALUE_TREATMENT_METHOD invalidValueTreatmentMethod = toConvert.getInvalidValueTreatment() != null ? INVALID_VALUE_TREATMENT_METHOD.byName(toConvert.getInvalidValueTreatment().value()) : null;
final String missingValueReplacement = toConvert.getMissingValueReplacement() != null ? toConvert.getMissingValueReplacement().toString() : null;
final String invalidValueReplacement = toConvert.getInvalidValueReplacement() != null ? toConvert.getInvalidValueReplacement().toString() : null;
final List<String> allowedValues = field instanceof DataField ? convertDataFieldValues(((DataField) field).getValues()) : Collections.emptyList();
final List<org.kie.pmml.api.models.Interval> intervals = field instanceof DataField ? convertDataFieldIntervals(((DataField) field).getIntervals()) : Collections.emptyList();
return new org.kie.pmml.api.models.MiningField(name, fieldUsageType, opType, dataType, missingValueTreatmentMethod, invalidValueTreatmentMethod, missingValueReplacement, invalidValueReplacement, allowedValues, intervals);
}
use of org.dmg.pmml.DataField in project drools by kiegroup.
the class PMMLModelTestUtils method getRandomDataField.
public static DataField getRandomDataField() {
DataField toReturn = new DataField();
toReturn.setName(FieldName.create(RandomStringUtils.random(6, true, false)));
toReturn.setDataType(getRandomDataType());
toReturn.setOpType(getRandomOpType());
IntStream.range(0, 3).forEach(i -> {
toReturn.addValues(getRandomValue(toReturn.getDataType()));
toReturn.addIntervals(getRandomInterval());
});
return toReturn;
}
use of org.dmg.pmml.DataField in project drools by kiegroup.
the class PMMLModelTestUtils method getDataField.
public static DataField getDataField(String fieldName, OpType opType, DataType dataType) {
DataField toReturn = getDataField(fieldName, opType);
toReturn.setDataType(dataType);
return toReturn;
}
use of org.dmg.pmml.DataField 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);
});
}
Aggregations