Search in sources :

Example 1 with PMML4Result

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

the class ApplyPmmlModelCommand method execute.

@Override
public PMML4Result execute(Context context) {
    PMML4Result resultHolder = new PMML4Result(requestData.getCorrelationId());
    RequestContextImpl ctx = (RequestContextImpl) context;
    KieBase kbase = ((RegistryContext) context).lookup(KieBase.class);
    if (kbase == null) {
        System.out.println("KieBase not found in context!");
        return null;
    } else {
        KieContainer kcont = ((KnowledgeBaseImpl) kbase).getKieContainer();
        kcont.getKieBaseNames().forEach(n -> {
            System.out.println(n);
        });
        kbase.getKiePackages().forEach(kp -> {
            System.out.println("Package: " + kp.getName());
        });
    }
    return null;
// RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
// DataSource<PMMLRequestData> data = executor.newDataSource("request", this.requestData);
// DataSource<PMML4Result> resultData = executor.newDataSource("results", resultHolder);
// System.out.println("Setting result: "+resultHolder);
// ctx.lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, resultHolder);
// return resultHolder;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) RequestContextImpl(org.drools.core.command.RequestContextImpl) RegistryContext(org.drools.core.command.impl.RegistryContext) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) KieContainer(org.kie.api.runtime.KieContainer)

Example 2 with PMML4Result

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

the class MiningSegmentTransferTest method setup.

@Before
public void setup() {
    simpleResult = new PMML4Result();
    simpleResult.setCorrelationId("1234");
    simpleResult.setResultCode("OK");
    simpleResult.setSegmentationId("Segmentation_1");
    simpleResult.setSegmentId("SEGMENT_1");
    simpleResult.addResultVariable("var1", new Integer(100));
    simpleResult.addResultVariable("var2", "Just some string");
    complexResult = new PMML4Result();
    complexResult.setCorrelationId("7890");
    complexResult.setResultCode("OK");
    complexResult.setSegmentationId("Segmentation_1");
    complexResult.setSegmentId("SEGMENT_1");
    complexResult.addResultVariable("firstObject", "Just a string");
    complexResult.addResultVariable("myComplex", new MyResult("a test string", 101));
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) Before(org.junit.Before)

Example 3 with PMML4Result

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

the class DecisionTreeTest method testWeightedConfidenceMissingValueStrategy.

@Test
public // @Ignore
void testWeightedConfidenceMissingValueStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_WEIGHTED_CONFIDENCE_MISSING_STRATEGY);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 30.0);
    PMML4Result resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    Assertions.assertThat(resultHolder.getResultValue("Fld3", "value", String.class).get()).isEqualTo("tgtY");
    executor.setRunWithLogging(true);
    request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 50.0);
    resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    Assertions.assertThat(resultHolder.getResultValue("Fld3", "value", String.class).get()).isEqualTo("tgtX");
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) PMMLExecutor(org.kie.pmml.pmml_4_2.PMMLExecutor) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 4 with PMML4Result

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

the class DecisionTreeTest method testReturnLastNoTrueChildPredictionStrategy.

@Test
public void testReturnLastNoTrueChildPredictionStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_RETURN_LAST_NOTRUE_CHILD_STRATEGY);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 30.0);
    PMML4Result resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    String targetValue = resultHolder.getResultValue("Fld2", "value", String.class).orElse(null);
    Assertions.assertThat(targetValue).isEqualTo("tgtY");
    request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 50.0);
    resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    targetValue = resultHolder.getResultValue("Fld2", "value", String.class).orElse(null);
    Assertions.assertThat(targetValue).isEqualTo("tgtX");
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) PMMLExecutor(org.kie.pmml.pmml_4_2.PMMLExecutor) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 5 with PMML4Result

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

the class DecisionTreeTest method testDefaultChildMissingValueStrategy.

@Test
public void testDefaultChildMissingValueStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_DEFAULT_CHILD_MISSING_STRATEGY);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 30.0);
    PMML4Result resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    Assertions.assertThat(resultHolder.getResultValue("Fld3", "value", String.class).get()).isEqualTo("tgtY");
    request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 100.0);
    resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    Assertions.assertThat(resultHolder.getResultValue("Fld3", "value", String.class).get()).isEqualTo("tgtZ");
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) PMMLExecutor(org.kie.pmml.pmml_4_2.PMMLExecutor) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Aggregations

PMML4Result (org.kie.api.pmml.PMML4Result)30 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)28 Test (org.junit.Test)27 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)27 InternalRuleUnitExecutor (org.drools.core.impl.InternalRuleUnitExecutor)17 RuleUnitExecutor (org.kie.api.runtime.rule.RuleUnitExecutor)17 KieBase (org.kie.api.KieBase)14 PMMLExecutor (org.kie.pmml.pmml_4_2.PMMLExecutor)11 LinkedHashMap (java.util.LinkedHashMap)6 SegmentExecution (org.kie.pmml.pmml_4_2.model.mining.SegmentExecution)6 Map (java.util.Map)4 AbstractTreeToken (org.kie.pmml.pmml_4_2.model.tree.AbstractTreeToken)4 Iterator (java.util.Iterator)3 Resource (org.kie.api.io.Resource)3 KieRuntimeLogger (org.kie.api.logger.KieRuntimeLogger)3 PMML4Data (org.kie.api.pmml.PMML4Data)3 KieHelper (org.kie.internal.utils.KieHelper)3 ScoreCard (org.kie.pmml.pmml_4_2.model.ScoreCard)2 RequestContextImpl (org.drools.core.command.RequestContextImpl)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1