use of org.kie.pmml.api.enums.LOCAL_TERM_WEIGHTS 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));
});
}
Aggregations