PMMLRuntimeImpl implements PMMLRuntime { protected void addMissingValuesReplacements(final KiePMMLModel model, final PMMLContext context) { logger.debug("addMissingValuesReplacements {} {}", model, context); final PMMLRequestData requestData = context.getRequestData(); final Map<String, ParameterInfo> mappedRequestParams = requestData.getMappedRequestParams(); final Map<String, Object> missingValueReplacementMap = model.getMissingValueReplacementMap(); missingValueReplacementMap.forEach((fieldName, missingValueReplacement) -> { if (!mappedRequestParams.containsKey(fieldName)) { logger.debug("missingValueReplacement {} {}", fieldName, missingValueReplacement); requestData.addRequestParam(fieldName, missingValueReplacement); context.addMissingValueReplaced(fieldName, missingValueReplacement); } }); } PMMLRuntimeImpl(final KieBase knowledgeBase, final PMMLModelEvaluatorFinderImpl pmmlModelExecutorFinder); @Override KieBase getKnowledgeBase(); @Override List<KiePMMLModel> getModels(); @Override Optional<KiePMMLModel> getModel(final String modelName); @Override PMML4Result evaluate(final String modelName, final PMMLContext context);  }
@Test public void addMissingValuesReplacements() { Map<String, Object> missingValueReplacementMap = new HashMap<>(); missingValueReplacementMap.put("fieldA", "one"); missingValueReplacementMap.put("fieldB", 2); KiePMMLTestingModel model = KiePMMLTestingModel.builder("TESTINGMODEL", Collections.emptyList(), MINING_FUNCTION.REGRESSION) .withMissingValueReplacementMap(missingValueReplacementMap) .build(); PMMLRequestData pmmlRequestData = new PMMLRequestData("123", "modelName"); pmmlRequestData.addRequestParam("age", 123); pmmlRequestData.addRequestParam("work", "work"); PMMLContext pmmlContext = new PMMLContextImpl(pmmlRequestData); missingValueReplacementMap.keySet().forEach(key -> { assertFalse(pmmlContext.getRequestData().getMappedRequestParams().containsKey(key)); assertFalse(pmmlContext.getMissingValueReplacedMap().containsKey(key)); }); pmmlRuntime.addMissingValuesReplacements(model, pmmlContext); missingValueReplacementMap.forEach((key, value) -> { assertTrue(pmmlContext.getRequestData().getMappedRequestParams().containsKey(key)); final ParameterInfo<?> parameterInfo = pmmlContext.getRequestData().getMappedRequestParams().get(key); assertEquals(key, parameterInfo.getName()); assertEquals(value.getClass(), parameterInfo.getType()); assertEquals(value, parameterInfo.getValue()); assertTrue(pmmlContext.getMissingValueReplacedMap().containsKey(key)); assertEquals(value, pmmlContext.getMissingValueReplacedMap().get(key)); }); }