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));
}
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);
}
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));
}
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");
}
}
Aggregations