Search in sources :

Example 6 with OutputField

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);
}
Also used : MiningField(org.kie.pmml.api.models.MiningField) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) PMMLOASResult(org.kie.kogito.pmml.openapi.api.PMMLOASResult) OutputField(org.kie.pmml.api.models.OutputField) CommonTestUtility.getRandomOutputField(org.kie.kogito.pmml.CommonTestUtility.getRandomOutputField) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 7 with OutputField

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()));
    });
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OutputField(org.kie.pmml.api.models.OutputField) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 8 with OutputField

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());
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OutputField(org.kie.pmml.api.models.OutputField) CommonTestUtility.getRandomOutputField(org.kie.kogito.pmml.CommonTestUtility.getRandomOutputField) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode)

Example 9 with OutputField

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));
}
Also used : MiningField(org.kie.pmml.api.models.MiningField) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) PMMLOASResult(org.kie.kogito.pmml.openapi.api.PMMLOASResult) OutputField(org.kie.pmml.api.models.OutputField) CommonTestUtility.getRandomOutputField(org.kie.kogito.pmml.CommonTestUtility.getRandomOutputField) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test)

Example 10 with OutputField

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"));
}
Also used : Random(java.util.Random) RESULT_FEATURE(org.kie.pmml.api.enums.RESULT_FEATURE) OutputField(org.kie.pmml.api.models.OutputField) OP_TYPE(org.kie.pmml.api.enums.OP_TYPE) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE)

Aggregations

OutputField (org.kie.pmml.api.models.OutputField)10 MiningField (org.kie.pmml.api.models.MiningField)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)4 Expression (com.github.javaparser.ast.expr.Expression)4 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)4 NameExpr (com.github.javaparser.ast.expr.NameExpr)4 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)4 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)4 Random (java.util.Random)4 TargetField (org.kie.pmml.api.models.TargetField)4 CompilationUnit (com.github.javaparser.ast.CompilationUnit)3 NodeList (com.github.javaparser.ast.NodeList)3 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)3 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)3 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)3 ExplicitConstructorInvocationStmt (com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt)3 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)3 Statement (com.github.javaparser.ast.stmt.Statement)3