use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue 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.tuples.KiePMMLNameValue 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.tuples.KiePMMLNameValue in project drools by kiegroup.
the class KiePMMLDerivedFieldTest method evaluateFromFieldRef.
@Test
public void evaluateFromFieldRef() {
// <DerivedField name="CUSTOM_FIELD" optype="continuous" dataType="double">
// <FieldRef field="PARAM_1"/>
// </DerivedField>
final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(PARAM_1, Collections.emptyList(), null);
final KiePMMLDerivedField derivedField = KiePMMLDerivedField.builder(CUSTOM_FIELD, Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLFieldRef).build();
ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList(), Arrays.asList(new KiePMMLNameValue(PARAM_1, value1)));
Object retrieved = derivedField.evaluate(processingDTO);
assertEquals(value1, retrieved);
}
use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.
the class KiePMMLComplexPartialScore method evaluate.
public Number evaluate(final List<KiePMMLDefineFunction> defineFunctions, final List<KiePMMLDerivedField> derivedFields, final List<KiePMMLOutputField> outputFields, final Map<String, Object> inputData) {
final List<KiePMMLNameValue> kiePMMLNameValues = getKiePMMLNameValuesFromInputDataMap(inputData);
ProcessingDTO processingDTO = new ProcessingDTO(defineFunctions, derivedFields, outputFields, Collections.emptyList(), kiePMMLNameValues, Collections.emptyList(), Collections.emptyList());
Object toReturn = expression.evaluate(processingDTO);
return toReturn != null ? (Number) toReturn : null;
}
Aggregations