KiePMMLScorecardModel extends KiePMMLDroolsModel { protected void populateWithOutputFields(PMML4Result toPopulate) { if (outputFields != null) { final Map<String, Double> sortedByValue = outputFieldsMap.entrySet() .stream() .filter(entry -> entry.getValue() instanceof Double && (Double) entry.getValue() > 0) .map((Function<Map.Entry<String, Object>, Map.Entry<String, Double>>) entry -> new AbstractMap.SimpleEntry<>(entry.getKey(), (Double) entry.getValue())) .sorted(Map.Entry.<String, Double>comparingByValue().reversed()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); final List<String> orderedReasonCodes = new ArrayList<>(sortedByValue.keySet()); for (KiePMMLOutputField outputField : outputFields) { switch (outputField.getResultFeature()) { case REASON_CODE: if (outputField.getRank() != null) { int index = outputField.getRank() - 1; String resultCode = null; String resultVariableName = outputField.getName(); if (index < orderedReasonCodes.size()) { resultCode = orderedReasonCodes.get(index); } toPopulate.updateResultVariable(resultVariableName, resultCode); } break; default: } } } } protected  KiePMMLScorecardModel(String modelName, List<KiePMMLExtension> extensions); static Builder builder(String name, List<KiePMMLExtension> extensions, MINING_FUNCTION miningFunction); static PMML_MODEL getPmmlModelType(); @Override Object evaluate(final Object knowledgeBase, Map<String, Object> requestData); static final PMML_MODEL PMML_MODEL_TYPE; }
@Test public void populateWithOutputFields() { model = KiePMMLScorecardModel.builder(MODEL_NAME, Collections.emptyList(), MINING_FUNCTION.REGRESSION) .withOutputFields(outputFields) .withOutputFieldsMap(outputFieldsMap) .build(); PMML4Result toPopulate = new PMML4Result(); model.populateWithOutputFields(toPopulate); assertFalse(toPopulate.getResultVariables().isEmpty()); for (int i = outputFields.size() -1; i == 0; i --) { KiePMMLOutputField outputField = outputFields.get(i); assertTrue(toPopulate.getResultVariables().containsKey(outputField.getName())); assertEquals("REASON_CODE_" + i, toPopulate.getResultVariables().get(outputField.getName())); } }