use of org.kie.pmml.api.models.PMMLStep in project drools by kiegroup.
the class PMMLListenerUtilsTest method stepExecuted.
@Test
public void stepExecuted() {
final Map<Integer, PMMLStep> listenerFeedback = new HashMap<>();
int size = 3;
PMMLContext pmmlContext = getPMMLContext(size, listenerFeedback);
AtomicBoolean invoked = new AtomicBoolean(false);
PMMLListenerUtils.stepExecuted(() -> new PMMLStepTest(invoked), pmmlContext);
assertTrue(invoked.get());
assertEquals(size, listenerFeedback.size());
final PMMLStep retrieved = listenerFeedback.get(0);
IntStream.range(1, size).forEach(i -> assertEquals(retrieved, listenerFeedback.get(i)));
}
use of org.kie.pmml.api.models.PMMLStep in project drools by kiegroup.
the class PMMLMiningModelEvaluator method getStep.
/**
* Return a <code>PMMLStep</code> out of the given <code>KiePMMLSegment</code> and
* <code>PMML4Result</code>
* @param segment
* @param pmml4Result
* @return
*/
PMMLStep getStep(final KiePMMLSegment segment, final PMML4Result pmml4Result) {
PMMLStep toReturn = new PMMLMiningModelStep();
toReturn.addInfo("SEGMENT", segment.getName());
toReturn.addInfo("MODEL", segment.getModel().getName());
toReturn.addInfo("RESULT CODE", pmml4Result.getResultCode());
if (ResultCode.OK.getName().equals(pmml4Result.getResultCode())) {
toReturn.addInfo("RESULT", pmml4Result.getResultVariables().get(pmml4Result.getResultObjectName()));
}
return toReturn;
}
use of org.kie.pmml.api.models.PMMLStep in project drools by kiegroup.
the class PMMLMiningModelEvaluatorTest method getStep.
@Test
public void getStep() {
final String modelName = "MODEL_NAME";
KiePMMLModel modelMock = mock(KiePMMLModel.class);
when(modelMock.getName()).thenReturn(modelName);
final String segmentName = "SEGMENT_NAME";
KiePMMLSegment segmentMock = mock(KiePMMLSegment.class);
when(segmentMock.getName()).thenReturn(segmentName);
when(segmentMock.getModel()).thenReturn(modelMock);
final String resultObjectName = "RESULT_OBJECT_NAME";
final String resultObjectValue = "RESULT_OBJECT_VALUE";
ResultCode resultCode = OK;
PMML4Result pmml4Result = new PMML4Result();
pmml4Result.setResultCode(resultCode.getName());
pmml4Result.setResultObjectName(resultObjectName);
pmml4Result.getResultVariables().put(resultObjectName, resultObjectValue);
PMMLStep retrieved = evaluator.getStep(segmentMock, pmml4Result);
assertNotNull(retrieved);
assertTrue(retrieved instanceof PMMLMiningModelStep);
Map<String, Object> retrievedInfo = retrieved.getInfo();
assertNotNull(retrievedInfo);
assertEquals(segmentName, retrievedInfo.get("SEGMENT"));
assertEquals(modelName, retrievedInfo.get("MODEL"));
assertEquals(resultCode.getName(), retrievedInfo.get("RESULT CODE"));
assertEquals(resultObjectValue, retrievedInfo.get("RESULT"));
resultCode = FAIL;
pmml4Result = new PMML4Result();
pmml4Result.setResultCode(resultCode.getName());
retrieved = evaluator.getStep(segmentMock, pmml4Result);
assertNotNull(retrieved);
assertTrue(retrieved instanceof PMMLMiningModelStep);
retrievedInfo = retrieved.getInfo();
assertNotNull(retrievedInfo);
assertEquals(segmentName, retrievedInfo.get("SEGMENT"));
assertEquals(modelName, retrievedInfo.get("MODEL"));
assertEquals(resultCode.getName(), retrievedInfo.get("RESULT CODE"));
assertFalse(retrievedInfo.containsKey("RESULT"));
}
use of org.kie.pmml.api.models.PMMLStep in project drools by kiegroup.
the class PMMLRuntimeInternalImplTest method getStep.
@Test
public void getStep() {
final PMMLRequestData requestData = getPMMLRequestData();
Arrays.stream(PMML_STEP.values()).forEach(pmml_step -> {
PMMLStep retrieved = pmmlRuntime.getStep(pmml_step, modelMock, requestData);
commonValuateStep(retrieved, pmml_step, modelMock, requestData);
});
}
use of org.kie.pmml.api.models.PMMLStep in project drools by kiegroup.
the class PMMLListenerUtils method stepExecuted.
/**
* Send the <code>PMMLStep</code> to all registered <code>PMMLListener</code>s
* @param stepSupplier
* @param context
*/
public static void stepExecuted(final Supplier<PMMLStep> stepSupplier, final PMMLContext context) {
if (!context.getPMMLListeners().isEmpty()) {
final PMMLStep step = stepSupplier.get();
context.getPMMLListeners().forEach(listener -> listener.stepExecuted(step));
}
}
Aggregations