Search in sources :

Example 1 with PMMLStep

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)));
}
Also used : PMMLStep(org.kie.pmml.api.models.PMMLStep) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) PMMLContext(org.kie.pmml.api.runtime.PMMLContext) Test(org.junit.Test)

Example 2 with PMMLStep

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;
}
Also used : PMMLStep(org.kie.pmml.api.models.PMMLStep)

Example 3 with PMMLStep

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"));
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) PMMLStep(org.kie.pmml.api.models.PMMLStep) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KiePMMLSegment(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment) ResultCode(org.kie.pmml.api.enums.ResultCode) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Example 4 with PMMLStep

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);
    });
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMMLStep(org.kie.pmml.api.models.PMMLStep) Test(org.junit.Test)

Example 5 with PMMLStep

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));
    }
}
Also used : PMMLStep(org.kie.pmml.api.models.PMMLStep)

Aggregations

PMMLStep (org.kie.pmml.api.models.PMMLStep)9 Test (org.junit.Test)6 PMML4Result (org.kie.api.pmml.PMML4Result)4 PMMLContext (org.kie.pmml.api.runtime.PMMLContext)4 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 IntStream (java.util.stream.IntStream)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Before (org.junit.Before)3 KieBase (org.kie.api.KieBase)3 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)3 PMML_MODEL (org.kie.pmml.api.enums.PMML_MODEL)3 OK (org.kie.pmml.api.enums.ResultCode.OK)3 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)3 PMMLListener (org.kie.pmml.api.runtime.PMMLListener)3 PMMLRuntimeStep (org.kie.pmml.evaluator.core.implementations.PMMLRuntimeStep)3