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);
}
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));
});
}
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));
});
}
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);
}
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);
}
Aggregations