use of org.kie.pmml.commons.model.ProcessingDTO in project drools by kiegroup.
the class KiePMMLFieldRefTest method evaluateNull.
@Test
public void evaluateNull() {
final KiePMMLConstant kiePMMLConstant = new KiePMMLConstant("NAME", Collections.emptyList(), "WRONG-CONSTANT", null);
final KiePMMLDerivedField kiePMMLDerivedField = KiePMMLDerivedField.builder("ANOTHER_FIELD", Collections.emptyList(), DATA_TYPE.DOUBLE, OP_TYPE.CONTINUOUS, kiePMMLConstant).build();
final List<KiePMMLDerivedField> derivedFields = Collections.singletonList(kiePMMLDerivedField);
final List<KiePMMLNameValue> kiePMMLNameValues = Collections.singletonList(new KiePMMLNameValue("UNKNOWN", "WRONG"));
final KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(FIELD_NAME, Collections.emptyList(), null);
ProcessingDTO processingDTO = getProcessingDTO(derivedFields, kiePMMLNameValues);
final Object retrieved = kiePMMLFieldRef.evaluate(processingDTO);
assertNull(retrieved);
}
use of org.kie.pmml.commons.model.ProcessingDTO in project drools by kiegroup.
the class KiePMMLTextIndexTest method evaluateTextIndex1Normalizations.
@Test
public void evaluateTextIndex1Normalizations() {
// <TextIndexNormalization inField="string" outField="stem" regexField="regex">
// <InlineTable>
// <row>
// <string>interfaces?</string>
// <stem>interface</stem>
// <regex>true</regex>
// </row>
// <row>
// <string>is|are|seem(ed|s?)|were</string>
// <stem>be</stem>
// <regex>true</regex>
// </row>
// <row>
// <string>user friendl(y|iness)</string>
// <stem>user_friendly</stem>
// <regex>true</regex>
// </row>
// </InlineTable>
// </TextIndexNormalization>
Map<String, Object> columnValues = new HashMap<>();
columnValues.put("string", "interfaces?");
columnValues.put("stem", "interface");
columnValues.put("regex", "true");
KiePMMLRow row0_0 = new KiePMMLRow(columnValues);
columnValues = new HashMap<>();
columnValues.put("string", "is|are|seem(ed|s?)|were");
columnValues.put("stem", "be");
columnValues.put("regex", "true");
KiePMMLRow row0_1 = new KiePMMLRow(columnValues);
columnValues = new HashMap<>();
columnValues.put("string", "user friendl(y|iness)");
columnValues.put("stem", "user_friendly");
columnValues.put("regex", "true");
KiePMMLRow row0_2 = new KiePMMLRow(columnValues);
KiePMMLInlineTable inlineTable0 = new KiePMMLInlineTable("inlineTable0", Collections.emptyList(), Arrays.asList(row0_0, row0_1, row0_2));
KiePMMLTextIndexNormalization indexNormalization0 = KiePMMLTextIndexNormalization.builder("indexNormalization0", Collections.emptyList()).withInField("string").withOutField("stem").withRegexField("regex").withKiePMMLInlineTable(inlineTable0).build();
// <TextIndexNormalization inField="re" outField="feature" regexField="regex">
// <InlineTable>
// <row>
// <re>interface be (user_friendly|well designed|excellent)</re>
// <feature>ui_good</feature>
// <regex>true</regex>
// </row>
// </InlineTable>
// </TextIndexNormalization>
columnValues = new HashMap<>();
columnValues.put("re", "interface be (user_friendly|well designed|excellent)");
columnValues.put("feature", "ui_good");
columnValues.put("regex", "true");
KiePMMLRow row1_0 = new KiePMMLRow(columnValues);
KiePMMLInlineTable inlineTable1 = new KiePMMLInlineTable("inlineTable1", Collections.emptyList(), Collections.singletonList(row1_0));
KiePMMLTextIndexNormalization indexNormalization1 = KiePMMLTextIndexNormalization.builder("indexNormalization1", Collections.emptyList()).withInField("re").withOutField("feature").withRegexField("regex").withKiePMMLInlineTable(inlineTable1).build();
// <FieldRef field="term"/>
KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef("term", Collections.emptyList(), null);
KiePMMLTextIndex kiePMMLTextIndex = KiePMMLTextIndex.builder("reviewText", Collections.emptyList(), kiePMMLFieldRef).withMaxLevenshteinDistance(2).withLocalTermWeights(BINARY).withIsCaseSensitive(false).withTextIndexNormalizations(Arrays.asList(indexNormalization0, indexNormalization1)).build();
List<KiePMMLNameValue> kiePMMLNameValues = Arrays.asList(new KiePMMLNameValue("term", TERM_1), new KiePMMLNameValue("reviewText", NOT_NORMALIZED_TEXT_1));
ProcessingDTO processingDTO = getProcessingDTO(kiePMMLNameValues);
assertEquals(1.0, kiePMMLTextIndex.evaluate(processingDTO));
}
use of org.kie.pmml.commons.model.ProcessingDTO in project drools by kiegroup.
the class KiePMMLNormDiscreteTest method evaluateDifferentValue.
@Test
public void evaluateDifferentValue() {
String fieldName = "fieldName";
String fieldValue = "fieldValue";
Number mapMissingTo = null;
KiePMMLNormDiscrete kiePMMLNormContinuous = getKiePMMLNormDiscrete(fieldName, fieldValue, mapMissingTo);
ProcessingDTO processingDTO = getProcessingDTO(Collections.singletonList(new KiePMMLNameValue(fieldName, "anotherValue")));
Object retrieved = kiePMMLNormContinuous.evaluate(processingDTO);
assertNotNull(retrieved);
assertEquals(0.0, retrieved);
}
use of org.kie.pmml.commons.model.ProcessingDTO in project drools by kiegroup.
the class KiePMMLNormDiscreteTest method evaluateSameValue.
@Test
public void evaluateSameValue() {
String fieldName = "fieldName";
String fieldValue = "fieldValue";
Number mapMissingTo = null;
KiePMMLNormDiscrete kiePMMLNormContinuous = getKiePMMLNormDiscrete(fieldName, fieldValue, mapMissingTo);
ProcessingDTO processingDTO = getProcessingDTO(Collections.singletonList(new KiePMMLNameValue(fieldName, fieldValue)));
Object retrieved = kiePMMLNormContinuous.evaluate(processingDTO);
assertNotNull(retrieved);
assertEquals(1.0, retrieved);
}
use of org.kie.pmml.commons.model.ProcessingDTO in project drools by kiegroup.
the class KiePMMLDefineFunctionTest method evaluateNoParamValues.
@Test(expected = IllegalArgumentException.class)
public void evaluateNoParamValues() {
final KiePMMLParameterField parameterField1 = KiePMMLParameterField.builder(PARAM_1, Collections.emptyList()).build();
final KiePMMLParameterField parameterField2 = KiePMMLParameterField.builder(PARAM_2, Collections.emptyList()).build();
final KiePMMLDefineFunction defineFunction = new KiePMMLDefineFunction(CUSTOM_FUNCTION, Collections.emptyList(), null, OP_TYPE.CONTINUOUS, Arrays.asList(parameterField1, parameterField2), null);
ProcessingDTO processingDTO = getProcessingDTO(Collections.emptyList());
defineFunction.evaluate(processingDTO, null);
}
Aggregations