Search in sources :

Example 16 with KiePMMLMiningField

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

the class PreProcessTest method convertInputDataConvertibles.

@Test
public void convertInputDataConvertibles() {
    List<KiePMMLMiningField> miningFields = IntStream.range(0, 3).mapToObj(i -> {
        DATA_TYPE dataType = DATA_TYPE.values()[i];
        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", "123");
    pmmlRequestData.addRequestParam("FIELD-2", "1.23");
    Map<String, ParameterInfo> mappedRequestParams = pmmlRequestData.getMappedRequestParams();
    assertEquals(123, mappedRequestParams.get("FIELD-0").getValue());
    assertEquals("123", mappedRequestParams.get("FIELD-1").getValue());
    assertEquals("1.23", mappedRequestParams.get("FIELD-2").getValue());
    PreProcess.convertInputData(miningFields, pmmlRequestData);
    assertEquals("123", mappedRequestParams.get("FIELD-0").getValue());
    assertEquals(123, mappedRequestParams.get("FIELD-1").getValue());
    assertEquals(1.23f, mappedRequestParams.get("FIELD-2").getValue());
}
Also used : IntStream(java.util.stream.IntStream) CLOSURE(org.kie.pmml.api.enums.CLOSURE) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Arrays(java.util.Arrays) KiePMMLParameterField(org.kie.pmml.commons.transformations.KiePMMLParameterField) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) ArrayList(java.util.ArrayList) MiningField(org.kie.pmml.api.models.MiningField) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLTransformationDictionary(org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary) Map(java.util.Map) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) ParameterInfo(org.kie.api.pmml.ParameterInfo) KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) List(java.util.List) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) Assert.assertNull(org.junit.Assert.assertNull) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Optional(java.util.Optional) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Assert.assertEquals(org.junit.Assert.assertEquals) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) ParameterInfo(org.kie.api.pmml.ParameterInfo) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Test(org.junit.Test)

Example 17 with KiePMMLMiningField

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

the class PreProcessTest method manageMissingValuesReturnInvalid.

@Test(expected = KiePMMLException.class)
public void manageMissingValuesReturnInvalid() {
    KiePMMLMiningField miningField = KiePMMLMiningField.builder("FIELD", null).withDataType(DATA_TYPE.STRING).withMissingValueTreatmentMethod(MISSING_VALUE_TREATMENT_METHOD.RETURN_INVALID).build();
    PreProcess.manageMissingValues(miningField, new PMMLRequestData());
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) Test(org.junit.Test)

Example 18 with KiePMMLMiningField

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

the class PreProcessTest method verifyFixInvalidValuesInvalidAsValueWithReplacement.

@Test
public void verifyFixInvalidValuesInvalidAsValueWithReplacement() {
    KiePMMLMiningField miningField0 = KiePMMLMiningField.builder("FIELD-0", null).withDataType(DATA_TYPE.STRING).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_VALUE).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_VALUE).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_VALUE).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("123", mappedRequestParams.get("FIELD-0").getValue());
    assertEquals(1.23, mappedRequestParams.get("FIELD-1").getValue());
    assertEquals(12.3, 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)

Example 19 with KiePMMLMiningField

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

the class PreProcessTest method verifyAddMissingValuesMissingReturnInvalid.

@Test(expected = KiePMMLException.class)
public void verifyAddMissingValuesMissingReturnInvalid() {
    List<KiePMMLMiningField> miningFields = IntStream.range(0, 3).mapToObj(i -> {
        DATA_TYPE dataType = DATA_TYPE.values()[i];
        return KiePMMLMiningField.builder("FIELD-" + i, null).withDataType(dataType).withMissingValueTreatmentMethod(MISSING_VALUE_TREATMENT_METHOD.RETURN_INVALID).build();
    }).collect(Collectors.toList());
    PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName");
    PreProcess.verifyAddMissingValues(miningFields, pmmlRequestData);
}
Also used : IntStream(java.util.stream.IntStream) CLOSURE(org.kie.pmml.api.enums.CLOSURE) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Arrays(java.util.Arrays) KiePMMLParameterField(org.kie.pmml.commons.transformations.KiePMMLParameterField) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) KiePMMLInterval(org.kie.pmml.commons.model.expressions.KiePMMLInterval) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) ArrayList(java.util.ArrayList) MiningField(org.kie.pmml.api.models.MiningField) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLTransformationDictionary(org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary) Map(java.util.Map) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) MISSING_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD) INVALID_VALUE_TREATMENT_METHOD(org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) ParameterInfo(org.kie.api.pmml.ParameterInfo) KiePMMLDefineFunction(org.kie.pmml.commons.transformations.KiePMMLDefineFunction) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) List(java.util.List) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) Assert.assertNull(org.junit.Assert.assertNull) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Optional(java.util.Optional) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Assert.assertEquals(org.junit.Assert.assertEquals) KiePMMLDerivedField(org.kie.pmml.commons.transformations.KiePMMLDerivedField) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) Test(org.junit.Test)

Example 20 with KiePMMLMiningField

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

the class PreProcessTest method manageInvalidValuesNotReturnInvalid.

@Test
public void manageInvalidValuesNotReturnInvalid() {
    final ParameterInfo parameterInfo = new ParameterInfo();
    // AS_MISSING
    KiePMMLMiningField miningField = KiePMMLMiningField.builder("FIELD", null).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_MISSING).build();
    List<ParameterInfo> toRemove = new ArrayList<>();
    PreProcess.manageInvalidValues(miningField, parameterInfo, toRemove);
    assertEquals(1, toRemove.size());
    assertTrue(toRemove.contains(parameterInfo));
    // AS_IS
    miningField = KiePMMLMiningField.builder("FIELD", null).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_IS).build();
    toRemove = new ArrayList<>();
    PreProcess.manageInvalidValues(miningField, parameterInfo, toRemove);
    assertTrue(toRemove.isEmpty());
    // AS_VALUE with replacement
    String invalidValueReplacement = "REPLACEMENT";
    miningField = KiePMMLMiningField.builder("FIELD", null).withDataType(DATA_TYPE.STRING).withInvalidValueTreatmentMethod(INVALID_VALUE_TREATMENT_METHOD.AS_VALUE).withInvalidValueReplacement(invalidValueReplacement).build();
    toRemove = new ArrayList<>();
    assertNull(parameterInfo.getValue());
    assertNull(parameterInfo.getType());
    PreProcess.manageInvalidValues(miningField, parameterInfo, toRemove);
    assertTrue(toRemove.isEmpty());
    assertEquals(invalidValueReplacement, parameterInfo.getValue());
    assertEquals(String.class, parameterInfo.getType());
}
Also used : ArrayList(java.util.ArrayList) ParameterInfo(org.kie.api.pmml.ParameterInfo) KiePMMLMiningField(org.kie.pmml.commons.model.KiePMMLMiningField) Test(org.junit.Test)

Aggregations

KiePMMLMiningField (org.kie.pmml.commons.model.KiePMMLMiningField)20 Test (org.junit.Test)18 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)15 KiePMMLInterval (org.kie.pmml.commons.model.expressions.KiePMMLInterval)14 ParameterInfo (org.kie.api.pmml.ParameterInfo)12 ArrayList (java.util.ArrayList)9 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)7 INVALID_VALUE_TREATMENT_METHOD (org.kie.pmml.api.enums.INVALID_VALUE_TREATMENT_METHOD)7 MISSING_VALUE_TREATMENT_METHOD (org.kie.pmml.api.enums.MISSING_VALUE_TREATMENT_METHOD)7 OP_TYPE (org.kie.pmml.api.enums.OP_TYPE)7 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)7 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 List (java.util.List)6 Map (java.util.Map)6 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 IntStream (java.util.stream.IntStream)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Assert.assertNull (org.junit.Assert.assertNull)6