use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue 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.tuples.KiePMMLNameValue 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.tuples.KiePMMLNameValue 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.tuples.KiePMMLNameValue 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.tuples.KiePMMLNameValue in project drools by kiegroup.
the class PostProcessTest method populateTransformedOutputFieldWithFieldRef.
@Test
public void populateTransformedOutputFieldWithFieldRef() {
final String mapMissingTo = "mapMissingTo";
final String variableName = "variableName";
final Object variableValue = 543.65434;
KiePMMLFieldRef kiePMMLFieldRef = new KiePMMLFieldRef(variableName, Collections.emptyList(), mapMissingTo);
KiePMMLOutputField outputField = KiePMMLOutputField.builder(OUTPUT_NAME, Collections.emptyList()).withResultFeature(RESULT_FEATURE.TRANSFORMED_VALUE).withKiePMMLExpression(kiePMMLFieldRef).build();
KiePMMLTestingModel kiePMMLModel = testingModelBuilder(outputField).build();
ProcessingDTO processingDTO = buildProcessingDTOWithNameValues(kiePMMLModel, new KiePMMLNameValue(variableName, variableValue));
PMML4Result toUpdate = new PMML4Result();
PostProcess.populateOutputFields(toUpdate, processingDTO);
assertFalse(toUpdate.getResultVariables().isEmpty());
assertTrue(toUpdate.getResultVariables().containsKey(OUTPUT_NAME));
assertEquals(variableValue, toUpdate.getResultVariables().get(OUTPUT_NAME));
}
Aggregations