Search in sources :

Example 1 with PMMLContext

use of org.kie.pmml.api.runtime.PMMLContext in project drools by kiegroup.

the class DMNKiePMMLTrustyInvocationEvaluator method getPMML4Result.

@Override
protected PMML4Result getPMML4Result(DMNRuntimeEventManager eventManager, DMNResult dmnr) {
    PMMLContext pmmlContext = getPMMLPMMLContext(UUID.randomUUID().toString(), model, dmnr);
    PMMLRuntime pmmlRuntime = getPMMLRuntime(eventManager);
    return pmmlRuntime.evaluate(model, pmmlContext);
}
Also used : PMMLRuntime(org.kie.pmml.api.runtime.PMMLRuntime) PMMLContext(org.kie.pmml.api.runtime.PMMLContext)

Example 2 with PMMLContext

use of org.kie.pmml.api.runtime.PMMLContext in project drools by kiegroup.

the class PMMLListenerUtilsTest method getPMMLContext.

private PMMLContext getPMMLContext(int size, Map<Integer, PMMLStep> listenerFeedback) {
    PMMLContext toReturn = new PMMLContextImpl(new PMMLRequestData());
    IntStream.range(0, size).forEach(i -> toReturn.addPMMLListener(getPMMLListener(i, listenerFeedback)));
    return toReturn;
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMMLContextImpl(org.kie.pmml.evaluator.core.PMMLContextImpl) PMMLContext(org.kie.pmml.api.runtime.PMMLContext)

Example 3 with PMMLContext

use of org.kie.pmml.api.runtime.PMMLContext 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 4 with PMMLContext

use of org.kie.pmml.api.runtime.PMMLContext in project drools by kiegroup.

the class PMMLRuntimeInternalImplTest method evaluateWithPmmlRuntimeListeners.

@Test
public void evaluateWithPmmlRuntimeListeners() {
    final PMMLRequestData requestData = getPMMLRequestData();
    final List<PMMLStep> pmmlSteps = new ArrayList<>();
    final PMMLContext pmmlContext = new PMMLContextImpl(requestData);
    pmmlRuntime.addPMMLListener(getPMMLListener(pmmlSteps));
    pmmlRuntime.evaluate(modelMock, pmmlContext);
    Arrays.stream(PMML_STEP.values()).forEach(pmml_step -> {
        Optional<PMMLStep> retrieved = pmmlSteps.stream().filter(pmmlStep -> pmml_step.equals(((PMMLRuntimeStep) pmmlStep).getPmmlStep())).findFirst();
        assertTrue(retrieved.isPresent());
        commonValuateStep(retrieved.get(), pmml_step, modelMock, requestData);
    });
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OK(org.kie.pmml.api.enums.ResultCode.OK) Arrays(java.util.Arrays) PMML4Result(org.kie.api.pmml.PMML4Result) PMML_STEP(org.kie.pmml.api.enums.PMML_STEP) ArrayList(java.util.ArrayList) MiningField(org.kie.pmml.api.models.MiningField) PMML_MODEL(org.kie.pmml.api.enums.PMML_MODEL) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) Map(java.util.Map) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KieBase(org.kie.api.KieBase) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DATA_TYPE(org.kie.pmml.api.enums.DATA_TYPE) PMMLModelEvaluator(org.kie.pmml.evaluator.core.executor.PMMLModelEvaluator) Mockito.verify(org.mockito.Mockito.verify) PMMLContextImpl(org.kie.pmml.evaluator.core.PMMLContextImpl) PMMLContext(org.kie.pmml.api.runtime.PMMLContext) List(java.util.List) Mockito.never(org.mockito.Mockito.never) PMMLRuntimeStep(org.kie.pmml.evaluator.core.implementations.PMMLRuntimeStep) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMMLListener(org.kie.pmml.api.runtime.PMMLListener) PMMLModelEvaluatorFinderImpl(org.kie.pmml.evaluator.core.executor.PMMLModelEvaluatorFinderImpl) Optional(java.util.Optional) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) Mockito.reset(org.mockito.Mockito.reset) PMMLStep(org.kie.pmml.api.models.PMMLStep) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Mockito.mock(org.mockito.Mockito.mock) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMMLStep(org.kie.pmml.api.models.PMMLStep) PMMLContextImpl(org.kie.pmml.evaluator.core.PMMLContextImpl) ArrayList(java.util.ArrayList) PMMLContext(org.kie.pmml.api.runtime.PMMLContext) Test(org.junit.Test)

Example 5 with PMMLContext

use of org.kie.pmml.api.runtime.PMMLContext in project drools by kiegroup.

the class PMMLCommandExecutorImpl method evaluate.

private PMML4Result evaluate(final PMMLRequestData pmmlRequestData, final PMMLRuntime pmmlRuntime) {
    String modelName = pmmlRequestData.getModelName();
    final PMMLContext pmmlContext = new PMMLContextImpl(pmmlRequestData);
    return pmmlRuntime.evaluate(modelName, pmmlContext);
}
Also used : PMMLContextImpl(org.kie.pmml.evaluator.core.PMMLContextImpl) PMMLContext(org.kie.pmml.api.runtime.PMMLContext)

Aggregations

PMMLContext (org.kie.pmml.api.runtime.PMMLContext)10 PMMLContextImpl (org.kie.pmml.evaluator.core.PMMLContextImpl)7 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)6 Test (org.junit.Test)5 PMMLStep (org.kie.pmml.api.models.PMMLStep)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 PMML4Result (org.kie.api.pmml.PMML4Result)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 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)3