Search in sources :

Example 1 with KiePMMLInputDataException

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);
    }
}
Also used : KiePMMLInputDataException(org.kie.pmml.api.exceptions.KiePMMLInputDataException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD)

Example 2 with KiePMMLInputDataException

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);
    }
}
Also used : MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) KiePMMLInputDataException(org.kie.pmml.api.exceptions.KiePMMLInputDataException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Aggregations

KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)2 KiePMMLInputDataException (org.kie.pmml.api.exceptions.KiePMMLInputDataException)2 INVALID_VALUE_TREATMENT_METHOD (org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD)1 MISSING_VALUE_TREATMENT_METHOD (org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD)1