use of org.kie.pmml.api.exceptions.KiePMMLInputDataException in project drools by kiegroup.
the class PreProcess method manageInvalidValues.
/**
* Manage the <b>invalid value</b> of the given <code>ParameterInfo</code> depending on the
* <code>INVALID_VALUE_TREATMENT_METHOD</code>
* of the given <code>MiningField</code>, <b>eventually adding the ParameterInfo to the list of the ones to be
* removed from input data</b>
* @param miningField
* @param parameterInfo
* @param toRemove
*/
static void manageInvalidValues(final KiePMMLMiningField miningField, final ParameterInfo parameterInfo, final List<ParameterInfo> toRemove) {
INVALID_VALUE_TREATMENT_METHOD invalidValueTreatmentMethod = miningField.getInvalidValueTreatmentMethod() != null ? miningField.getInvalidValueTreatmentMethod() : INVALID_VALUE_TREATMENT_METHOD.RETURN_INVALID;
Object originalValue = parameterInfo.getValue();
switch(invalidValueTreatmentMethod) {
case RETURN_INVALID:
throw new KiePMMLInputDataException("Invalid value " + originalValue + " for " + miningField.getName());
case AS_MISSING:
toRemove.add(parameterInfo);
break;
case AS_IS:
break;
case AS_VALUE:
String invalidValueReplacement = miningField.getInvalidValueReplacement();
if (invalidValueReplacement == null) {
throw new KiePMMLInputDataException("Missing required invalidValueReplacement for " + miningField.getName());
} else {
Object requiredValue = miningField.getDataType().getActualValue(invalidValueReplacement);
parameterInfo.setType(miningField.getDataType().getMappedClass());
parameterInfo.setValue(requiredValue);
}
break;
default:
throw new KiePMMLException("Unmanaged INVALID_VALUE_TREATMENT_METHOD " + invalidValueTreatmentMethod);
}
}
use of org.kie.pmml.api.exceptions.KiePMMLInputDataException in project drools by kiegroup.
the class PreProcess method manageMissingValues.
/**
* Manage the <b>missing value</b> depending on the <code>INVALID_VALUE_TREATMENT_METHOD</code>
* of the given <code>MiningField</code>, <b>eventually adding default ont to input data</b>
* @param miningField
* @param requestData
*/
static void manageMissingValues(final KiePMMLMiningField miningField, final PMMLRequestData requestData) {
MISSING_VALUE_TREATMENT_METHOD missingValueTreatmentMethod = miningField.getMissingValueTreatmentMethod() != null ? miningField.getMissingValueTreatmentMethod() : MISSING_VALUE_TREATMENT_METHOD.RETURN_INVALID;
switch(missingValueTreatmentMethod) {
case RETURN_INVALID:
throw new KiePMMLInputDataException("Missing required value for " + miningField.getName());
case AS_IS:
case AS_MEAN:
case AS_MODE:
case AS_MEDIAN:
case AS_VALUE:
String missingValueReplacement = miningField.getMissingValueReplacement();
if (missingValueReplacement != null) {
Object requiredValue = miningField.getDataType().getActualValue(missingValueReplacement);
requestData.addRequestParam(miningField.getName(), requiredValue);
}
break;
default:
throw new KiePMMLException("Unmanaged INVALID_VALUE_TREATMENT_METHOD " + missingValueTreatmentMethod);
}
}
Aggregations