use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class KiePMMLMiningFieldInstanceFactory method getKiePMMLMiningField.
public static KiePMMLMiningField getKiePMMLMiningField(final MiningField toConvert, final Field<?> field) {
String name = toConvert.getName() != null ? toConvert.getName().getValue() : "" + toConvert.hashCode();
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<KiePMMLInterval> intervals = field instanceof DataField ? getKiePMMLIntervals(((DataField) field).getIntervals()) : Collections.emptyList();
final KiePMMLMiningField.Builder builder = KiePMMLMiningField.builder(name, Collections.emptyList()).withFieldUsageType(fieldUsageType).withOpType(opType).withDataType(dataType).withMissingValueTreatmentMethod(missingValueTreatmentMethod).withInvalidValueTreatmentMethod(invalidValueTreatmentMethod).withMissingValueReplacement(missingValueReplacement).withInvalidValueReplacement(invalidValueReplacement).withAllowedValues(allowedValues).withIntervals(intervals);
return builder.build();
}
use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class KiePMMLMiningFieldInstanceFactoryTest method getKiePMMLMiningField.
@Test
public void getKiePMMLMiningField() {
DataField dataField = getRandomDataField();
MiningField toConvert = getRandomMiningField(dataField);
KiePMMLMiningField toVerify = KiePMMLMiningFieldInstanceFactory.getKiePMMLMiningField(toConvert, dataField);
commonVerifyKiePMMLMiningField(toVerify, toConvert, dataField);
}
use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class PreProcessTest method manageInvalidValuesAsValueNoReplacement.
@Test(expected = KiePMMLException.class)
public void manageInvalidValuesAsValueNoReplacement() {
final ParameterInfo parameterInfo = new ParameterInfo();
// AS_VALUE without replacement
KiePMMLMiningField miningField = KiePMMLMiningField.builder("FIELD", null).withDataType(DATA_TYPE.STRING).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_VALUE).build();
List<ParameterInfo> toRemove = new ArrayList<>();
assertNull(parameterInfo.getValue());
assertNull(parameterInfo.getType());
PreProcess.manageInvalidValues(miningField, parameterInfo, toRemove);
}
use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class PreProcessTest method verifyFixInvalidValuesNotInvalid.
@Test
public void verifyFixInvalidValuesNotInvalid() {
KiePMMLMiningField miningField0 = KiePMMLMiningField.builder("FIELD-0", null).withDataType(DATA_TYPE.STRING).withAllowedValues(Arrays.asList("123", "124", "125")).build();
KiePMMLMiningField miningField1 = KiePMMLMiningField.builder("FIELD-1", null).withDataType(DATA_TYPE.DOUBLE).withAllowedValues(Arrays.asList("1.23", "12.4", "1.25")).build();
List<KiePMMLInterval> intervals = Arrays.asList(new KiePMMLInterval(0.0, 12.4, CLOSURE.CLOSED_CLOSED), new KiePMMLInterval(12.6, 14.5, CLOSURE.OPEN_CLOSED));
KiePMMLMiningField miningField2 = KiePMMLMiningField.builder("FIELD-2", null).withDataType(DATA_TYPE.DOUBLE).withIntervals(intervals).build();
List<KiePMMLMiningField> miningFields = Arrays.asList(miningField0, miningField1, miningField2);
PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
pmmlRequestData.addRequestParam("FIELD-0", "123");
pmmlRequestData.addRequestParam("FIELD-1", 12.4);
pmmlRequestData.addRequestParam("FIELD-2", 9.3);
PreProcess.verifyFixInvalidValues(miningFields, pmmlRequestData);
pmmlRequestData = new PMMLRequestData("123", "modelName");
pmmlRequestData.addRequestParam("FIELD-0", "125");
pmmlRequestData.addRequestParam("FIELD-1", 1.25);
pmmlRequestData.addRequestParam("FIELD-2", 13.9);
PreProcess.verifyFixInvalidValues(miningFields, pmmlRequestData);
}
use of org.kie.pmml.commons.model.KiePMMLMiningField in project drools by kiegroup.
the class PreProcessTest method convertInputDataNotConvertibles.
@Test(expected = KiePMMLException.class)
public void convertInputDataNotConvertibles() {
List<KiePMMLMiningField> miningFields = IntStream.range(0, 3).mapToObj(i -> {
DATA_TYPE dataType = DATA_TYPE.values()[i];
new MiningField("FIELD-" + i, null, null, dataType, null, null, null, null, null, null);
return KiePMMLMiningField.builder("FIELD-" + i, null).withDataType(dataType).build();
}).collect(Collectors.toList());
PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
pmmlRequestData.addRequestParam("FIELD-0", 123);
pmmlRequestData.addRequestParam("FIELD-1", true);
pmmlRequestData.addRequestParam("FIELD-2", "123");
PreProcess.convertInputData(miningFields, pmmlRequestData);
}
Aggregations