use of org.kie.pmml.api.models.OutputField in project kogito-runtimes by kiegroup.
the class PMMLOASResultFactoryTest method getPMMLOASResultMiningFieldsOutputFields.
@Test
void getPMMLOASResultMiningFieldsOutputFields() {
final List<MiningField> miningFields = getRandomMiningFields();
final List<MiningField> predictedFields = miningFields.stream().filter(PMMLOASUtils::isPredicted).collect(Collectors.toList());
final List<OutputField> outputFields = getRandomOutputFields();
outputFields.add(getRandomOutputField(miningFields.get(miningFields.size() - 1).getName()));
final KiePMMLModel kiePMMLModel = getKiePMMLModelInternal(miningFields, outputFields);
final PMMLOASResult retrieved = PMMLOASResultFactory.getPMMLOASResult(kiePMMLModel);
assertNotNull(retrieved);
final ObjectNode jsonNodes = retrieved.jsonSchemaNode();
assertNotNull(jsonNodes);
assertFalse(jsonNodes.isEmpty());
assertNotNull(jsonNodes.get(DEFINITIONS));
final JsonNode definitionsNode = jsonNodes.get(DEFINITIONS);
assertFalse(definitionsNode.isEmpty());
commonValidateInputSet(definitionsNode.get(INPUT_SET), miningFields);
commonValidateResultSet(definitionsNode.get(RESULT_SET), predictedFields);
assertNotNull(definitionsNode.get(OUTPUT_SET));
assertNotNull(definitionsNode.get(OUTPUT_SET).get(PROPERTIES));
assertNotNull(definitionsNode.get(OUTPUT_SET).get(PROPERTIES).get(RESULT_VARIABLES));
commonValidateOutputSet(definitionsNode.get(OUTPUT_SET).get(PROPERTIES).get(RESULT_VARIABLES), outputFields);
}
use of org.kie.pmml.api.models.OutputField in project kogito-runtimes by kiegroup.
the class PMMLOASResultImplTest method addOutputFields.
@Test
void addOutputFields() {
PMMLOASResultImpl pmmlOAResult = (PMMLOASResultImpl) new PMMLOASResultImpl.Builder().build();
ObjectNode jsonNodes = pmmlOAResult.jsonNodes;
ObjectNode definitionsNode = (ObjectNode) jsonNodes.get(DEFINITIONS);
ObjectNode outputSetNode = (ObjectNode) definitionsNode.get(OUTPUT_SET);
ObjectNode outputSetPropertiesNode = (ObjectNode) outputSetNode.get(PROPERTIES);
assertNull(outputSetPropertiesNode.get(RESULT_VARIABLES));
List<OutputField> toAdd = getRandomOutputFields();
pmmlOAResult.addOutputFields(toAdd);
assertNotNull(outputSetPropertiesNode.get(RESULT_VARIABLES));
ObjectNode resultVariablesNode = (ObjectNode) outputSetPropertiesNode.get(RESULT_VARIABLES);
assertNotNull(resultVariablesNode.get(PROPERTIES));
ObjectNode resultVariablesPropertiesNode = (ObjectNode) resultVariablesNode.get(PROPERTIES);
assertEquals(toAdd.size(), resultVariablesPropertiesNode.size());
List<JsonNode> nodeList = StreamSupport.stream(resultVariablesPropertiesNode.spliterator(), false).collect(Collectors.toList());
nodeList.forEach(resultNode -> assertTrue(resultNode instanceof ObjectNode));
toAdd.forEach(outputField -> {
assertNotNull(resultVariablesPropertiesNode.get(outputField.getName()));
});
}
use of org.kie.pmml.api.models.OutputField in project kogito-runtimes by kiegroup.
the class PMMLOASResultFactoryTest method commonValidateOutputSet.
private void commonValidateOutputSet(final JsonNode toValidate, final List<OutputField> outputFields) {
assertNotNull(toValidate);
assertEquals(OBJECT, toValidate.get(TYPE).asText());
assertNotNull(toValidate.get(PROPERTIES));
final ObjectNode propertiesNode = (ObjectNode) toValidate.get(PROPERTIES);
for (OutputField outputField : outputFields) {
JsonNode property = propertiesNode.get(outputField.getName());
assertNotNull(property);
final ObjectNode typeFieldNode = (ObjectNode) property;
assertNotNull(typeFieldNode.get(TYPE));
final TextNode typeNode = (TextNode) typeFieldNode.get(TYPE);
String mappedType = PMMLOASUtils.getMappedType(outputField.getDataType());
assertEquals(mappedType, typeNode.asText());
}
}
use of org.kie.pmml.api.models.OutputField in project kogito-runtimes by kiegroup.
the class PMMLOASResultFactoryTest method getPMMLOASResultMiningFieldsNoOutputFields.
@Test
void getPMMLOASResultMiningFieldsNoOutputFields() {
final List<MiningField> miningFields = getRandomMiningFields();
final List<MiningField> predictedFields = miningFields.stream().filter(PMMLOASUtils::isPredicted).collect(Collectors.toList());
final List<OutputField> outputFields = Collections.emptyList();
final KiePMMLModel kiePMMLModel = getKiePMMLModelInternal(miningFields, outputFields);
final PMMLOASResult retrieved = PMMLOASResultFactory.getPMMLOASResult(kiePMMLModel);
assertNotNull(retrieved);
final ObjectNode jsonNodes = retrieved.jsonSchemaNode();
assertNotNull(jsonNodes);
assertFalse(jsonNodes.isEmpty());
assertNotNull(jsonNodes.get(DEFINITIONS));
final JsonNode definitionsNode = jsonNodes.get(DEFINITIONS);
assertFalse(definitionsNode.isEmpty());
commonValidateInputSet(definitionsNode.get(INPUT_SET), miningFields);
commonValidateResultSet(definitionsNode.get(RESULT_SET), predictedFields);
assertNotNull(definitionsNode.get(OUTPUT_SET));
assertNotNull(definitionsNode.get(OUTPUT_SET).get(PROPERTIES));
assertNotNull(definitionsNode.get(OUTPUT_SET).get(PROPERTIES).get(RESULT_VARIABLES));
}
use of org.kie.pmml.api.models.OutputField in project kogito-runtimes by kiegroup.
the class CommonTestUtility method getRandomOutputField.
public static OutputField getRandomOutputField(String targetField) {
Random random = new Random();
String fieldName = RandomStringUtils.random(6, true, false);
OP_TYPE opType = OP_TYPE.values()[random.nextInt(OP_TYPE.values().length)];
DATA_TYPE dataType = DATA_TYPE.values()[random.nextInt(DATA_TYPE.values().length)];
RESULT_FEATURE resultFeature = RESULT_FEATURE.values()[random.nextInt(RESULT_FEATURE.values().length)];
return new OutputField(fieldName, opType, dataType, targetField, resultFeature, Arrays.asList("A", "B", "C"));
}
Aggregations