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;
}
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());
}
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);
}
Aggregations