Search in sources :

Example 6 with PMMLContext

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

the class PMMLListenerUtilsTest method stepNotExecuted.

@Test
public void stepNotExecuted() {
    PMMLContext pmmlContext = new PMMLContextImpl(new PMMLRequestData());
    AtomicBoolean invoked = new AtomicBoolean(false);
    PMMLListenerUtils.stepExecuted(() -> new PMMLStepTest(invoked), pmmlContext);
    assertFalse(invoked.get());
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PMMLContextImpl(org.kie.pmml.evaluator.core.PMMLContextImpl) PMMLContext(org.kie.pmml.api.runtime.PMMLContext) Test(org.junit.Test)

Example 7 with PMMLContext

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

the class PMMLRuntimeInternalImplTest method evaluateWithPMMLContextListeners.

@Test
public void evaluateWithPMMLContextListeners() {
    final PMMLRequestData requestData = getPMMLRequestData();
    final List<PMMLStep> pmmlSteps = new ArrayList<>();
    final PMMLContext pmmlContext = new PMMLContextImpl(requestData, Collections.singleton(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 8 with PMMLContext

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

the class PMMLScorecardModelEvaluatorTest method commonEvaluate.

private void commonEvaluate(Map<String, Object> inputData) {
    final PMMLRequestData pmmlRequestData = getPMMLRequestData(modelName, inputData);
    PMMLContext pmmlContext = new PMMLContextImpl(pmmlRequestData);
    commonEvaluate(pmmlContext);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMMLContextImpl(org.kie.pmml.evaluator.core.PMMLContextImpl) PMMLContext(org.kie.pmml.api.runtime.PMMLContext)

Example 9 with PMMLContext

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

the class PMMLTreeModelEvaluatorTest method commonEvaluate.

private void commonEvaluate(String modelName, Map<String, Object> inputData, String expectedScore) {
    final PMMLRequestData pmmlRequestData = getPMMLRequestData(modelName, inputData);
    PMMLContext pmmlContext = new PMMLContextImpl(pmmlRequestData);
    commonEvaluate(pmmlContext, expectedScore);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMMLContextImpl(org.kie.pmml.evaluator.core.PMMLContextImpl) PMMLContext(org.kie.pmml.api.runtime.PMMLContext)

Example 10 with PMMLContext

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

the class PMMLMiningModelEvaluatorTest method addStep.

@Test
public void addStep() {
    PMMLStep step = mock(PMMLStep.class);
    Set<PMMLListener> pmmlListenersMock = IntStream.range(0, 3).mapToObj(i -> mock(PMMLListener.class)).collect(Collectors.toSet());
    PMMLContext pmmlContextMock = mock(PMMLContext.class);
    when(pmmlContextMock.getPMMLListeners()).thenReturn(pmmlListenersMock);
    evaluator.addStep(() -> step, pmmlContextMock);
    pmmlListenersMock.forEach(pmmlListenerMock -> verify(pmmlListenerMock).stepExecuted(step));
}
Also used : MAX(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MAX) Arrays(java.util.Arrays) WEIGHTED_AVERAGE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_AVERAGE) SELECT_ALL(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SELECT_ALL) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) PMML_MODEL(org.kie.pmml.api.enums.PMML_MODEL) WEIGHTED_MAJORITY_VOTE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_MAJORITY_VOTE) PMMLRuntimeInternal(org.kie.pmml.evaluator.api.executor.PMMLRuntimeInternal) Map(java.util.Map) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Assert.fail(org.junit.Assert.fail) MINING_FUNCTION(org.kie.pmml.api.enums.MINING_FUNCTION) KiePMMLValueWeight(org.kie.pmml.commons.model.tuples.KiePMMLValueWeight) ResultCode(org.kie.pmml.api.enums.ResultCode) MAJORITY_VOTE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MAJORITY_VOTE) Set(java.util.Set) Collectors(java.util.stream.Collectors) AVERAGE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.AVERAGE) PMMLContext(org.kie.pmml.api.runtime.PMMLContext) List(java.util.List) KiePMMLTestingModel(org.kie.pmml.commons.testingutility.KiePMMLTestingModel) Assert.assertFalse(org.junit.Assert.assertFalse) WEIGHTED_MEDIAN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_MEDIAN) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) OK(org.kie.pmml.api.enums.ResultCode.OK) PMMLRuntime(org.kie.pmml.api.runtime.PMMLRuntime) PMML4Result(org.kie.api.pmml.PMML4Result) MULTIPLE_MODEL_METHOD(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) MEDIAN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MEDIAN) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) KieServices(org.kie.api.KieServices) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KieBase(org.kie.api.KieBase) Before(org.junit.Before) KiePMMLSegment(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment) WEIGHTED_SUM(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_SUM) FAIL(org.kie.pmml.api.enums.ResultCode.FAIL) Assert.assertNotNull(org.junit.Assert.assertNotNull) SUM(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SUM) KieContainer(org.kie.api.runtime.KieContainer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) SELECT_FIRST(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SELECT_FIRST) Mockito.verify(org.mockito.Mockito.verify) MODEL_CHAIN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MODEL_CHAIN) Assert.assertNull(org.junit.Assert.assertNull) PMMLListener(org.kie.pmml.api.runtime.PMMLListener) KiePMMLModelException(org.kie.pmml.evaluator.api.exceptions.KiePMMLModelException) KiePMMLSegmentation(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation) Collections(java.util.Collections) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) PMMLStep(org.kie.pmml.api.models.PMMLStep) Assert.assertEquals(org.junit.Assert.assertEquals) PMMLStep(org.kie.pmml.api.models.PMMLStep) PMMLListener(org.kie.pmml.api.runtime.PMMLListener) PMMLContext(org.kie.pmml.api.runtime.PMMLContext) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

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