Search in sources :

Example 1 with KiePMMLPredicate

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;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLPredicate(org.kie.pmml.commons.model.predicates.KiePMMLPredicate) PMMLRuntime(org.kie.pmml.api.runtime.PMMLRuntime)

Example 2 with KiePMMLPredicate

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);
}
Also used : IntStream(java.util.stream.IntStream) PMMLModelTestUtils.getRandomSimplePredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimplePredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicate) PMMLModelTestUtils.getRandomCompoundPredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomCompoundPredicate) False(org.dmg.pmml.False) Test(org.junit.Test) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) Collectors(java.util.stream.Collectors) KiePMMLPredicate(org.kie.pmml.commons.model.predicates.KiePMMLPredicate) DataField(org.dmg.pmml.DataField) List(java.util.List) SimplePredicate(org.dmg.pmml.SimplePredicate) Field(org.dmg.pmml.Field) InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) PMMLModelTestUtils.getRandomSimpleSetPredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimpleSetPredicate) True(org.dmg.pmml.True) PMMLModelTestUtils.getRandomDataField(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField) DataField(org.dmg.pmml.DataField) Field(org.dmg.pmml.Field) KiePMMLPredicate(org.kie.pmml.commons.model.predicates.KiePMMLPredicate) InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate(org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate) True(org.dmg.pmml.True) CompoundPredicate(org.dmg.pmml.CompoundPredicate) PMMLModelTestUtils.getRandomCompoundPredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomCompoundPredicate) False(org.dmg.pmml.False) PMMLModelTestUtils.getRandomSimplePredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimplePredicate) SimplePredicate(org.dmg.pmml.SimplePredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicate) PMMLModelTestUtils.getRandomSimpleSetPredicate(org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimpleSetPredicate) Test(org.junit.Test)

Example 3 with KiePMMLPredicate

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();
}
Also used : KiePMMLPredicate(org.kie.pmml.commons.model.predicates.KiePMMLPredicate) BOOLEAN_OPERATOR(org.kie.pmml.api.enums.BOOLEAN_OPERATOR)

Aggregations

KiePMMLPredicate (org.kie.pmml.commons.model.predicates.KiePMMLPredicate)3 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 CompoundPredicate (org.dmg.pmml.CompoundPredicate)1 DataField (org.dmg.pmml.DataField)1 False (org.dmg.pmml.False)1 Field (org.dmg.pmml.Field)1 SimplePredicate (org.dmg.pmml.SimplePredicate)1 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicate)1 True (org.dmg.pmml.True)1 Test (org.junit.Test)1 PMML4Result (org.kie.api.pmml.PMML4Result)1 BOOLEAN_OPERATOR (org.kie.pmml.api.enums.BOOLEAN_OPERATOR)1 PMMLRuntime (org.kie.pmml.api.runtime.PMMLRuntime)1 PMMLModelTestUtils.getRandomCompoundPredicate (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomCompoundPredicate)1 PMMLModelTestUtils.getRandomDataField (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomDataField)1 PMMLModelTestUtils.getRandomSimplePredicate (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimplePredicate)1 PMMLModelTestUtils.getRandomSimpleSetPredicate (org.kie.pmml.compiler.api.testutils.PMMLModelTestUtils.getRandomSimpleSetPredicate)1 InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate (org.kie.pmml.compiler.commons.factories.InstanceFactoriesTestCommon.commonVerifyKiePMMLPredicate)1