Search in sources :

Example 41 with ProcessingDTO

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

the class KiePMMLNormContinuousTest method evaluate.

@Test
public void evaluate() {
    String fieldName = "fieldName";
    Number input = 24;
    KiePMMLNormContinuous kiePMMLNormContinuous = getKiePMMLNormContinuous(fieldName, null, null);
    ProcessingDTO processingDTO = new ProcessingDTO(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.singletonList(new KiePMMLNameValue(fieldName, input)), Collections.emptyList(), Collections.emptyList());
    Number retrieved = (Number) kiePMMLNormContinuous.evaluate(processingDTO);
    Number expected = kiePMMLNormContinuous.linearNorms.get(0).getNorm() + ((input.doubleValue() - kiePMMLNormContinuous.linearNorms.get(0).getOrig()) / (kiePMMLNormContinuous.linearNorms.get(1).getOrig() - kiePMMLNormContinuous.linearNorms.get(0).getOrig())) * (kiePMMLNormContinuous.linearNorms.get(1).getNorm() - kiePMMLNormContinuous.linearNorms.get(0).getNorm());
    assertEquals(expected, retrieved);
}
Also used : ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) Test(org.junit.Test)

Example 42 with ProcessingDTO

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

the class KiePMMLTextIndexTest method evaluateTextIndex0Normalizations.

@Test
public void evaluateTextIndex0Normalizations() {
    // <Constant>brown fox</Constant>
    final KiePMMLConstant kiePMMLConstant = new KiePMMLConstant("NAME-1", Collections.emptyList(), TERM_0, null);
    List<KiePMMLNameValue> kiePMMLNameValues = Collections.singletonList(new KiePMMLNameValue(FIELD_NAME, NOT_NORMALIZED_TEXT_0));
    ProcessingDTO processingDTO = getProcessingDTO(kiePMMLNameValues);
    double frequency = 3.0;
    double logarithmic = Math.log10(1 + frequency);
    int maxFrequency = 2;
    // cast
    double augmentedNormalizedTermFrequency = 0.5 * (1 + (frequency / (double) maxFrequency));
    // for java:S2184
    Map<LOCAL_TERM_WEIGHTS, Double> expectedResults = new HashMap<>();
    expectedResults.put(TERM_FREQUENCY, frequency);
    expectedResults.put(BINARY, 1.0);
    expectedResults.put(LOGARITHMIC, logarithmic);
    expectedResults.put(AUGMENTED_NORMALIZED_TERM_FREQUENCY, augmentedNormalizedTermFrequency);
    expectedResults.forEach((localTermWeights, expected) -> {
        KiePMMLTextIndex kiePMMLTextIndex = KiePMMLTextIndex.builder(FIELD_NAME, Collections.emptyList(), kiePMMLConstant).withMaxLevenshteinDistance(2).withLocalTermWeights(localTermWeights).withIsCaseSensitive(true).withTextIndexNormalizations(getKiePMMLTextIndexNormalizations()).build();
        assertEquals(expected, kiePMMLTextIndex.evaluate(processingDTO));
    });
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) HashMap(java.util.HashMap) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LOCAL_TERM_WEIGHTS(org.kie.pmml.api.enums.LOCAL_TERM_WEIGHTS) Test(org.junit.Test)

Example 43 with ProcessingDTO

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

the class KiePMMLTextIndexTest method evaluateNoTextIndex0Normalizations.

@Test
public void evaluateNoTextIndex0Normalizations() {
    // <Constant>brown fox</Constant>
    final KiePMMLConstant kiePMMLConstant = new KiePMMLConstant("NAME-1", Collections.emptyList(), TERM_0, null);
    List<KiePMMLNameValue> kiePMMLNameValues = Collections.singletonList(new KiePMMLNameValue(FIELD_NAME, TEXT_0));
    ProcessingDTO processingDTO = getProcessingDTO(kiePMMLNameValues);
    double frequency = 3.0;
    double logarithmic = Math.log10(1 + frequency);
    int maxFrequency = 2;
    // cast
    double augmentedNormalizedTermFrequency = 0.5 * (1 + (frequency / (double) maxFrequency));
    // for java:S2184
    Map<LOCAL_TERM_WEIGHTS, Double> expectedResults = new HashMap<>();
    expectedResults.put(TERM_FREQUENCY, frequency);
    expectedResults.put(BINARY, 1.0);
    expectedResults.put(LOGARITHMIC, logarithmic);
    expectedResults.put(AUGMENTED_NORMALIZED_TERM_FREQUENCY, augmentedNormalizedTermFrequency);
    expectedResults.forEach((localTermWeights, expected) -> {
        KiePMMLTextIndex kiePMMLTextIndex = KiePMMLTextIndex.builder(FIELD_NAME, Collections.emptyList(), kiePMMLConstant).withMaxLevenshteinDistance(2).withLocalTermWeights(localTermWeights).withIsCaseSensitive(true).withWordSeparatorCharacterRE("\\s+").build();
        assertEquals(expected, kiePMMLTextIndex.evaluate(processingDTO));
    });
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) HashMap(java.util.HashMap) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LOCAL_TERM_WEIGHTS(org.kie.pmml.api.enums.LOCAL_TERM_WEIGHTS) Test(org.junit.Test)

Example 44 with ProcessingDTO

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

the class KiePMMLNormDiscreteTest method evaluateMissingValue.

@Test
public void evaluateMissingValue() {
    String fieldName = "fieldName";
    String fieldValue = "fieldValue";
    Number mapMissingTo = 1.0;
    KiePMMLNormDiscrete kiePMMLNormContinuous = getKiePMMLNormDiscrete(fieldName, fieldValue, mapMissingTo);
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList());
    Object retrieved = kiePMMLNormContinuous.evaluate(processingDTO);
    assertNotNull(retrieved);
    assertEquals(mapMissingTo, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) Test(org.junit.Test)

Example 45 with ProcessingDTO

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

the class KiePMMLDerivedFieldTest method evaluateFromApplyWithKiePMMLNameValues.

@Test
public void evaluateFromApplyWithKiePMMLNameValues() {
    // <DerivedField name="CUSTOM_FIELD" optype="continuous" dataType="double">
    // <Apply function="/">
    // <FieldRef>PARAM_1</FieldRef>
    // <FieldRef>PARAM_2</FieldRef>
    // </Apply>
    // </DerivedField>
    final KiePMMLFieldRef kiePMMLFieldRef1 = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
    final KiePMMLFieldRef kiePMMLFieldRef2 = new KiePMMLFieldRef(PARAM_2, Collections.emptyList(), null);
    final KiePMMLApply kiePMMLApply = KiePMMLApply.builder("NAME", Collections.emptyList(), "/").withKiePMMLExpressions(Arrays.asList(kiePMMLFieldRef1, kiePMMLFieldRef2)).build();
    final KiePMMLDerivedField derivedField = KiePMMLDerivedField.builder(CUSTOM_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLApply).build();
    ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList(), getKiePMMLNameValues());
    Object retrieved = derivedField.evaluate(processingDTO);
    Object expected = value1 / value2;
    assertEquals(expected, retrieved);
}
Also used : CommonTestingUtility.getProcessingDTO(org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO) ProcessingDTO(org.kie.pmml.commons.model.ProcessingDTO) KiePMMLApply(org.kie.pmml.commons.model.expressions.KiePMMLApply) KiePMMLFieldRef(org.kie.pmml.commons.model.expressions.KiePMMLFieldRef) Test(org.junit.Test)

Aggregations

ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)48 Test (org.junit.Test)44 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)41 KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)19 PMML4Result (org.kie.api.pmml.PMML4Result)15 KiePMMLTestingModel (org.kie.pmml.commons.testingutility.KiePMMLTestingModel)15 KiePMMLOutputField (org.kie.pmml.commons.model.KiePMMLOutputField)13 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)13 KiePMMLConstant (org.kie.pmml.commons.model.expressions.KiePMMLConstant)12 KiePMMLApply (org.kie.pmml.commons.model.expressions.KiePMMLApply)11 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)9 KiePMMLTransformationDictionary (org.kie.pmml.commons.transformations.KiePMMLTransformationDictionary)7 KiePMMLDefineFunction (org.kie.pmml.commons.transformations.KiePMMLDefineFunction)6 Collections (java.util.Collections)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3