Search in sources :

Example 1 with KiePMMLInterval

use of org.kie.pmml.commons.model.expressions.KiePMMLInterval in project drools by kiegroup.

the class KiePMMLDiscretizeBinInstanceFactory method getKiePMMLDiscretizeBin.

static KiePMMLDiscretizeBin getKiePMMLDiscretizeBin(final DiscretizeBin discretizeBin) {
    KiePMMLInterval interval = KiePMMLIntervalInstanceFactory.getKiePMMLInterval(discretizeBin.getInterval());
    String binValue = discretizeBin.getBinValue() != null ? discretizeBin.getBinValue().toString() : null;
    return new KiePMMLDiscretizeBin(UUID.randomUUID().toString(), getKiePMMLExtensions(discretizeBin.getExtensions()), binValue, interval);
}
Also used : KiePMMLDiscretizeBin(org.kie.pmml.commons.model.expressions.KiePMMLDiscretizeBin) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval)

Example 2 with KiePMMLInterval

use of org.kie.pmml.commons.model.expressions.KiePMMLInterval 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();
}
Also used : MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) FIELD_USAGE_TYPE(org.kie.pmml.api.enums.FIELD_USAGE_TYPE) DataField(org.dmg.pmml.DataField) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD)

Example 3 with KiePMMLInterval

use of org.kie.pmml.commons.model.expressions.KiePMMLInterval 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);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) Test(org.junit.Test)

Example 4 with KiePMMLInterval

use of org.kie.pmml.commons.model.expressions.KiePMMLInterval in project drools by kiegroup.

the class PreProcessTest method verifyFixInvalidValuesInvalidReturnInvalid.

@Test(expected = KiePMMLException.class)
public void verifyFixInvalidValuesInvalidReturnInvalid() {
    KiePMMLMiningField miningField0 = KiePMMLMiningField.builder("FIELD-0", null).withDataType(DATA_TYPE.STRING).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.RETURN_INVALID).withAllowedValues(Arrays.asList("123", "124", "125")).build();
    KiePMMLMiningField miningField1 = KiePMMLMiningField.builder("FIELD-1", null).withDataType(DATA_TYPE.DOUBLE).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.RETURN_INVALID).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).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.RETURN_INVALID).withIntervals(intervals).build();
    List<KiePMMLMiningField> miningFields = Arrays.asList(miningField0, miningField1, miningField2);
    PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
    pmmlRequestData.addRequestParam("FIELD-0", "122");
    pmmlRequestData.addRequestParam("FIELD-1", 12.5);
    pmmlRequestData.addRequestParam("FIELD-2", 14.6);
    PreProcess.verifyFixInvalidValues(miningFields, pmmlRequestData);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) Test(org.junit.Test)

Example 5 with KiePMMLInterval

use of org.kie.pmml.commons.model.expressions.KiePMMLInterval in project drools by kiegroup.

the class PreProcessTest method verifyFixInvalidValuesInvalidAsIs.

@Test
public void verifyFixInvalidValuesInvalidAsIs() {
    KiePMMLMiningField miningField0 = KiePMMLMiningField.builder("FIELD-0", null).withDataType(DATA_TYPE.STRING).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_IS).withInvalidValueReplacement("123").withAllowedValues(Arrays.asList("123", "124", "125")).build();
    KiePMMLMiningField miningField1 = KiePMMLMiningField.builder("FIELD-1", null).withDataType(DATA_TYPE.DOUBLE).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_IS).withInvalidValueReplacement("1.23").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).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_IS).withInvalidValueReplacement("12.3").withIntervals(intervals).build();
    List<KiePMMLMiningField> miningFields = Arrays.asList(miningField0, miningField1, miningField2);
    PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
    pmmlRequestData.addRequestParam("FIELD-0", "122");
    pmmlRequestData.addRequestParam("FIELD-1", 12.5);
    pmmlRequestData.addRequestParam("FIELD-2", 14.6);
    PreProcess.verifyFixInvalidValues(miningFields, pmmlRequestData);
    Map<String, ParameterInfo> mappedRequestParams = pmmlRequestData.getMappedRequestParams();
    assertEquals("122", mappedRequestParams.get("FIELD-0").getValue());
    assertEquals(12.5, mappedRequestParams.get("FIELD-1").getValue());
    assertEquals(14.6, mappedRequestParams.get("FIELD-2").getValue());
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) ParameterInfo(org.kie.api.pmml.ParameterInfo) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) Test(org.junit.Test)

Aggregations

KiePMMLInterval (org.kie.pmml.commons.model.expressions.KiePMMLInterval)10 Test (org.junit.Test)8 KiePMMLMiningField (org.kie.pmml.commons.model.KiePMMLMiningField)8 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)7 ParameterInfo (org.kie.api.pmml.ParameterInfo)3 DataField (org.dmg.pmml.DataField)1 Interval (org.dmg.pmml.Interval)1 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)1 FIELD_USAGE_TYPE (org.kie.pmml.api.enums.FIELD_USAGE_TYPE)1 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 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)1 KiePMMLDiscretizeBin (org.kie.pmml.commons.model.expressions.KiePMMLDiscretizeBin)1 PMMLModelTestUtils.getRandomInterval (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomInterval)1 InstanceFactoriesTestCommon.commonVerifyKiePMMLInterval (org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLInterval)1