Search in sources :

Example 16 with KiePMMLNameValue

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

the class KiePMMLDiscretizeTest method evaluateDefaultValue.

@Test
public void evaluateDefaultValue() {
    KiePMMLDiscretize kiePMMLDiscretize = getKiePMMLDiscretize(null, null);
    ProcessingDTO processingDTO = getProcessingDTO(Arrays.asList(new KiePMMLNameValue(NAME, 20)));
    Object retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNull(retrieved);
    kiePMMLDiscretize = getKiePMMLDiscretize(MAP_MISSING_TO, DEFAULTVALUE);
    processingDTO = getProcessingDTO(Arrays.asList(new KiePMMLNameValue(NAME, 20)));
    retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(DEFAULTVALUE, retrieved);
    processingDTO = getProcessingDTO(Arrays.asList(new KiePMMLNameValue(NAME, 21)));
    retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(DEFAULTVALUE, retrieved);
    processingDTO = getProcessingDTO(Arrays.asList(new KiePMMLNameValue(NAME, 40)));
    retrieved = kiePMMLDiscretize.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(DEFAULTVALUE, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Example 17 with KiePMMLNameValue

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

the class KiePMMLMapValuesTest method evaluateKeyFoundMatching.

@Test
public void evaluateKeyFoundMatching() {
    KiePMMLMapValues kiePMMLMapValues = getKiePMMLMapValues();
    List<KiePMMLNameValue> kiePMMLNameValues = IntStream.range(0, 2).mapToObj(i -> new KiePMMLNameValue("FIELD-" + i, "VALUE-1-" + i)).collect(Collectors.toList());
    ProcessingDTO processingDTO = getProcessingDTO(kiePMMLNameValues);
    Object retrieved = kiePMMLMapValues.evaluate(processingDTO);
    assertNotNull(retrieved);
}
Also used : IntStream(java.util.stream.IntStream) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) List(java.util.List) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Assert.assertNotNull(org.junit.Assert.assertNotNull) Map(java.util.Map) Test(org.junit.Test) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Example 18 with KiePMMLNameValue

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

the class KiePMMLMapValuesTest method evaluateKeyFoundNotMatching.

@Test
public void evaluateKeyFoundNotMatching() {
    KiePMMLMapValues kiePMMLMapValues = getKiePMMLMapValues();
    List<KiePMMLNameValue> kiePMMLNameValues = IntStream.range(0, 2).mapToObj(i -> new KiePMMLNameValue("FIELD-" + i, "NOT-VALUE-1-" + i)).collect(Collectors.toList());
    ProcessingDTO processingDTO = getProcessingDTO(kiePMMLNameValues);
    assertEquals(DEFAULTVALUE, kiePMMLMapValues.evaluate(processingDTO));
}
Also used : IntStream(java.util.stream.IntStream) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) List(java.util.List) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Assert.assertNotNull(org.junit.Assert.assertNotNull) Map(java.util.Map) Test(org.junit.Test) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Example 19 with KiePMMLNameValue

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

the class KiePMMLOutputFieldTest method evaluatePredictedValue.

@Test
public void evaluatePredictedValue() {
    final String variableName = "variableName";
    KiePMMLOutputField kiePMMLOutputField = KiePMMLOutputField.builder("outputfield", Collections.emptyList()).withResultFeature(RESULT_FEATURE.PREDICTED_VALUE).withTargetField(variableName).build();
    final List<KiePMMLNameValue> kiePMMLNameValues = IntStream.range(0, 3).mapToObj(i -> new KiePMMLNameValue("val-" + i, i)).collect(Collectors.toList());
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList(), kiePMMLNameValues, Collections.emptyList());
    assertNull(kiePMMLOutputField.evaluate(processingDTO));
    final Object variableValue = 243.94;
    kiePMMLNameValues.add(new KiePMMLNameValue(variableName, variableValue));
    processingDTO = getProcessingDTO(Collections.emptyList(), kiePMMLNameValues, Collections.emptyList());
    Object retrieved = kiePMMLOutputField.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(variableValue, retrieved);
}
Also used : IntStream(java.util.stream.IntStream) RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Arrays(java.util.Arrays) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Optional(java.util.Optional) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Example 20 with KiePMMLNameValue

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

the class KiePMMLOutputFieldTest method getValueFromKiePMMLNameValuesByVariableName.

@Test
public void getValueFromKiePMMLNameValuesByVariableName() {
    final String variableName = "variableName";
    final List<KiePMMLNameValue> kiePMMLNameValues = IntStream.range(0, 3).mapToObj(i -> new KiePMMLNameValue("val-" + i, i)).collect(Collectors.toList());
    Optional<Object> retrieved = KiePMMLOutputField.getValueFromKiePMMLNameValuesByVariableName(variableName, kiePMMLNameValues);
    assertFalse(retrieved.isPresent());
    final Object variableValue = 243.94;
    kiePMMLNameValues.add(new KiePMMLNameValue(variableName, variableValue));
    retrieved = KiePMMLOutputField.getValueFromKiePMMLNameValuesByVariableName(variableName, kiePMMLNameValues);
    assertTrue(retrieved.isPresent());
    assertEquals(variableValue, retrieved.get());
}
Also used : IntStream(java.util.stream.IntStream) RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) KiePMMLConstant(org.kie.pmml.commons.model.expressions.KiePMMLConstant) Arrays(java.util.Arrays) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Optional(java.util.Optional) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Aggregations

KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)44 Test (org.junit.Test)37 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)19 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)19 LinkedHashMap (java.util.LinkedHashMap)16 ArrayList (java.util.ArrayList)8 List (java.util.List)8 HashMap (java.util.HashMap)7 PMML4Result (org.kie.api.pmml.PMML4Result)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 IntStream (java.util.stream.IntStream)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)6 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)6 Collections (java.util.Collections)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 Arrays (java.util.Arrays)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 PMMLContextTest (org.kie.pmml.commons.testingutility.PMMLContextTest)4