use of org.kie.pmml.commons.model.predicates.KiePMMLPredicate 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.commons.model.predicates.KiePMMLPredicate in project drools by kiegroup.
the class KiePMMLPredicateInstanceFactoryTest method getKiePMMLPredicate.
@Test
public void getKiePMMLPredicate() {
List<Field<?>> fields = IntStream.range(0, 3).mapToObj(i -> getRandomDataField()).collect(Collectors.toList());
SimplePredicate simplePredicate1 = getRandomSimplePredicate((DataField) fields.get(0));
KiePMMLPredicate retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(simplePredicate1, fields);
commonVerifyKiePMMLPredicate(retrieved, simplePredicate1);
SimpleSetPredicate simpleSetPredicate = getRandomSimpleSetPredicate((DataField) fields.get(2));
retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(simpleSetPredicate, fields);
commonVerifyKiePMMLPredicate(retrieved, simpleSetPredicate);
final CompoundPredicate compoundPredicate = getRandomCompoundPredicate(fields);
retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(compoundPredicate, fields);
commonVerifyKiePMMLPredicate(retrieved, compoundPredicate);
False falsePredicate = new False();
retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(falsePredicate, fields);
commonVerifyKiePMMLPredicate(retrieved, falsePredicate);
True truePredicate = new True();
retrieved = KiePMMLPredicateInstanceFactory.getKiePMMLPredicate(truePredicate, fields);
commonVerifyKiePMMLPredicate(retrieved, truePredicate);
}
use of org.kie.pmml.commons.model.predicates.KiePMMLPredicate in project drools by kiegroup.
the class KiePMMLCompoundPredicateInstanceFactory method getKiePMMLCompoundPredicate.
static KiePMMLCompoundPredicate getKiePMMLCompoundPredicate(final CompoundPredicate compoundPredicate, final List<Field<?>> fields) {
final BOOLEAN_OPERATOR booleanOperator = BOOLEAN_OPERATOR.byName(compoundPredicate.getBooleanOperator().value());
final List<KiePMMLPredicate> kiePMMLPredicates = compoundPredicate.hasPredicates() ? getKiePMMLPredicates(compoundPredicate.getPredicates(), fields) : Collections.emptyList();
return KiePMMLCompoundPredicate.builder(getKiePMMLExtensions(compoundPredicate.getExtensions()), booleanOperator).withKiePMMLPredicates(kiePMMLPredicates).build();
}
Aggregations