Search in sources :

Example 1 with PMMLOASResult

use of org.kie.kogito.pmml.openapi.api.PMMLOASResult in project kogito-runtimes by kiegroup.

the class PMMLOASResultFactoryTest method getPMMLOASResultNoMiningFieldsNoOutputFields.

@Test
void getPMMLOASResultNoMiningFieldsNoOutputFields() {
    final List<MiningField> miningFields = Collections.emptyList();
    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);
    assertNull(definitionsNode.get(RESULT_SET));
    assertNotNull(definitionsNode.get(OUTPUT_SET));
    assertNull(definitionsNode.get(OUTPUT_SET).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 2 with PMMLOASResult

use of org.kie.kogito.pmml.openapi.api.PMMLOASResult 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 3 with PMMLOASResult

use of org.kie.kogito.pmml.openapi.api.PMMLOASResult 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 4 with PMMLOASResult

use of org.kie.kogito.pmml.openapi.api.PMMLOASResult in project kogito-runtimes by kiegroup.

the class PredictionCodegen method generateModelRESTFiles.

private void generateModelRESTFiles(List<GeneratedFile> files, KiePMMLModel model) {
    if (!context().hasRESTForGenerator(this) || (model instanceof KiePMMLFactoryModel)) {
        return;
    }
    PMMLRestResourceGenerator resourceGenerator = new PMMLRestResourceGenerator(context(), model, applicationCanonicalName());
    files.add(new GeneratedFile(REST_TYPE, resourceGenerator.generatedFilePath(), resourceGenerator.generate()));
    PMMLOASResult oasResult = PMMLOASResultFactory.getPMMLOASResult(model);
    try {
        String jsonContent = new ObjectMapper().writeValueAsString(oasResult.jsonSchemaNode());
        String jsonFile = String.format("%s.json", getSanitizedClassName(model.getName()));
        files.add(new GeneratedFile(GeneratedFileType.STATIC_HTTP_RESOURCE, jsonFile, jsonContent));
    } catch (Exception e) {
        LOGGER.warn("Failed to write OAS schema");
    }
}
Also used : PMMLOASResult(org.kie.kogito.pmml.openapi.api.PMMLOASResult) GeneratedFile(org.kie.kogito.codegen.api.GeneratedFile) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KiePMMLFactoryModel(org.kie.pmml.commons.model.KiePMMLFactoryModel)

Aggregations

PMMLOASResult (org.kie.kogito.pmml.openapi.api.PMMLOASResult)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Test (org.junit.jupiter.api.Test)3 CommonTestUtility.getRandomOutputField (org.kie.kogito.pmml.CommonTestUtility.getRandomOutputField)3 MiningField (org.kie.pmml.api.models.MiningField)3 OutputField (org.kie.pmml.api.models.OutputField)3 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GeneratedFile (org.kie.kogito.codegen.api.GeneratedFile)1 KiePMMLFactoryModel (org.kie.pmml.commons.model.KiePMMLFactoryModel)1