Search in sources :

Example 6 with PMMLRuntime

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

the class PMMLMiningModelEvaluator method evaluateSegment.

/**
 * Evaluate the model contained in the <code>KiePMMLSegment</code>, indirectly invoking
 * the model-specific evaluator (through <code>PMMLRuntime</code> container)
 * @param toEvaluate
 * @param pmmlContext
 * @param knowledgeBase
 * @param containerModelName
 * @return
 */
private Optional<PMML4Result> evaluateSegment(final KiePMMLSegment toEvaluate, final PMMLContext pmmlContext, final KieBase knowledgeBase, final String containerModelName) {
    logger.trace("evaluateSegment {}", toEvaluate.getId());
    final KiePMMLPredicate kiePMMLPredicate = toEvaluate.getKiePMMLPredicate();
    Optional<PMML4Result> toReturn = Optional.empty();
    Map<String, Object> values = getUnwrappedParametersMap(pmmlContext.getRequestData().getMappedRequestParams());
    String modelName = toEvaluate.getModel().getName();
    if (kiePMMLPredicate.evaluate(values)) {
        final PMMLRuntime pmmlRuntime = getPMMLRuntime(toEvaluate.getModel().getKModulePackageName(), knowledgeBase, containerModelName);
        logger.trace("{}: matching predicate, evaluating... ", toEvaluate.getId());
        toReturn = Optional.ofNullable(pmmlRuntime.evaluate(modelName, pmmlContext));
    }
    return toReturn;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLPredicate(org.kie.pmml.commons.model.predicates.KiePMMLPredicate) PMMLRuntime(org.kie.pmml.api.runtime.PMMLRuntime)

Example 7 with PMMLRuntime

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

the class PMMLMiningModelEvaluatorTest method getPMMLRuntime.

@Test
public void getPMMLRuntime() {
    final KieServices kieServices = KieServices.Factory.get();
    final KieContainer kieContainer = kieServices.newKieClasspathContainer();
    final KieBase kieBase = kieContainer.getKieBase();
    String kModulePackageName = "kModulePackageNameA";
    String containerModelName = "containerModelNameA";
    PMMLRuntime firstRetrieved = evaluator.getPMMLRuntime(kModulePackageName, kieBase, containerModelName);
    assertNotNull(firstRetrieved);
    assertTrue(firstRetrieved instanceof PMMLRuntimeInternal);
    PMMLRuntimeInternal firstPMMLRuntimeInternal = (PMMLRuntimeInternal) firstRetrieved;
    PMMLRuntime secondRetrieved = evaluator.getPMMLRuntime(kModulePackageName, kieBase, containerModelName);
    assertTrue(secondRetrieved instanceof PMMLRuntimeInternal);
    PMMLRuntimeInternal secondPMMLRuntimeInternal = (PMMLRuntimeInternal) secondRetrieved;
    assertEquals(firstPMMLRuntimeInternal.getKnowledgeBase(), secondPMMLRuntimeInternal.getKnowledgeBase());
    kModulePackageName = "kModulePackageNameB";
    containerModelName = "containerModelNameB";
    PMMLRuntime thirdRetrieved = evaluator.getPMMLRuntime(kModulePackageName, kieBase, containerModelName);
    assertNotNull(thirdRetrieved);
    assertTrue(thirdRetrieved instanceof PMMLRuntimeInternal);
    PMMLRuntimeInternal thirdPMMLRuntimeInternal = (PMMLRuntimeInternal) thirdRetrieved;
    assertNotEquals(firstPMMLRuntimeInternal.getKnowledgeBase(), thirdPMMLRuntimeInternal.getKnowledgeBase());
}
Also used : KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) PMMLRuntime(org.kie.pmml.api.runtime.PMMLRuntime) PMMLRuntimeInternal(org.kie.pmml.evaluator.api.executor.PMMLRuntimeInternal) KieContainer(org.kie.api.runtime.KieContainer) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Example 8 with PMMLRuntime

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

the class PMMLCommandExecutorImpl method execute.

/**
 * Evaluate the given <code>PMMLRequestData<code>
 * @param pmmlRequestData : it must contain the pmml file name (in the <i>source</i> property)
 * @param context and the model name
 * @return
 */
@Override
public PMML4Result execute(final PMMLRequestData pmmlRequestData, final Context context) {
    final PMMLRequestData cleanedRequestData = getCleanedRequestData(pmmlRequestData);
    validate(cleanedRequestData);
    final String pmmlFileName = cleanedRequestData.getSource();
    final String pmmlModelName = cleanedRequestData.getModelName();
    final PMMLRuntime pmmlRuntime = getPMMLRuntime(pmmlFileName, pmmlModelName, ((RegistryContext) context).lookup(KieBase.class));
    return evaluate(cleanedRequestData, pmmlRuntime);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) KieBase(org.kie.api.KieBase) PMMLRuntime(org.kie.pmml.api.runtime.PMMLRuntime)

Aggregations

PMMLRuntime (org.kie.pmml.api.runtime.PMMLRuntime)8 File (java.io.File)4 Test (org.junit.Test)4 FileUtils.getFile (org.kie.test.util.filesystem.FileUtils.getFile)3 KieBase (org.kie.api.KieBase)2 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 KieServices (org.kie.api.KieServices)1 ReleaseId (org.kie.api.builder.ReleaseId)1 PMML4Result (org.kie.api.pmml.PMML4Result)1 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)1 KieContainer (org.kie.api.runtime.KieContainer)1 PMMLContext (org.kie.pmml.api.runtime.PMMLContext)1 KiePMMLPredicate (org.kie.pmml.commons.model.predicates.KiePMMLPredicate)1 PMMLContextTest (org.kie.pmml.commons.testingutility.PMMLContextTest)1 PMMLRuntimeInternal (org.kie.pmml.evaluator.api.executor.PMMLRuntimeInternal)1 ReleaseIdImpl (org.kie.util.maven.support.ReleaseIdImpl)1