PMMLMiningModelEvaluator implements PMMLModelEvaluator<KiePMMLMiningModel> { Object getEventuallyWeightedResult(Object rawObject, MULTIPLE_MODEL_METHOD multipleModelMethod, double weight) { switch (multipleModelMethod) { case MAJORITY_VOTE: case SELECT_ALL: case SELECT_FIRST: return rawObject; case MAX: case SUM: case MEDIAN: case AVERAGE: case WEIGHTED_SUM: case WEIGHTED_MEDIAN: case WEIGHTED_AVERAGE: if (!(rawObject instanceof Number)) { throw new KiePMMLException("Expected a number, retrieved " + rawObject.getClass().getName()); } return new KiePMMLValueWeight(((Number) rawObject).doubleValue(), weight); case MODEL_CHAIN: case WEIGHTED_MAJORITY_VOTE: throw new KiePMMLException(multipleModelMethod + " not implemented, yet"); default: throw new KiePMMLException("Unrecognized MULTIPLE_MODEL_METHOD " + multipleModelMethod); } }  @Override PMML_MODEL getPMMLModelType(); @Override PMML4Result evaluate(final KieBase knowledgeBase,
                                final KiePMMLMiningModel model,
                                final PMMLContext pmmlContext);  }
@Test public void getEventuallyWeightedResultRawObject() { final Object rawObject = "OBJ"; RAW_OBJECT_METHODS.forEach(multipleModelMethod -> { Object retrieved = evaluator.getEventuallyWeightedResult(rawObject, multipleModelMethod, 34.2); assertNotNull(retrieved); assertEquals(rawObject, retrieved); }); }
@Test public void getEventuallyWeightedResultValueWeightNumber() { final Integer rawObject = 24; final double weight = 2.23; VALUE_WEIGHT_METHODS.forEach(multipleModelMethod -> { Object retrieved = evaluator.getEventuallyWeightedResult(rawObject, multipleModelMethod, weight); assertNotNull(retrieved); assertTrue(retrieved instanceof KiePMMLValueWeight); KiePMMLValueWeight kiePMMLValueWeight = (KiePMMLValueWeight) retrieved; assertEquals(rawObject.doubleValue(), kiePMMLValueWeight.getValue(), 0.0); assertEquals(weight, kiePMMLValueWeight.getWeight(), 0.0); }); }
@Test public void getEventuallyWeightedResultValueWeightNoNumber() { VALUE_WEIGHT_METHODS.forEach(multipleModelMethod -> { try { evaluator.getEventuallyWeightedResult("OBJ", multipleModelMethod, 34.2); fail(multipleModelMethod + " is supposed to throw exception because raw object is not a number"); } catch (KiePMMLException e) { } }); }
@Test public void getEventuallyWeightedResultNotImplemented() { NOT_IMPLEMENTED_METHODS.forEach(multipleModelMethod -> { try { evaluator.getEventuallyWeightedResult("OBJ", multipleModelMethod, 34.2); fail(multipleModelMethod + " is supposed to throw exception because not implemented"); } catch (KiePMMLException e) { } }); }