Search in sources :

Example 6 with SegmentExecution

use of org.kie.pmml.pmml_4_2.model.mining.SegmentExecution in project drools by kiegroup.

the class MiningmodelTest method testSelectSecondSegmentFirst.

@Test
public void testSelectSecondSegmentFirst() {
    RuleUnitExecutor executor = createExecutor(source1);
    // KieRuntimeLogger console = ((InternalRuleUnitExecutor)executor).addConsoleLogger();
    PMMLRequestData request = new PMMLRequestData("1234", "SampleMine");
    request.addRequestParam(new ParameterInfo<>("1234", "fld1", Double.class, 45.0));
    request.addRequestParam(new ParameterInfo<>("1234", "fld2", Double.class, 60.0));
    request.addRequestParam(new ParameterInfo<>("1234", "fld6", String.class, "optA"));
    PMML4Result resultHolder = new PMML4Result();
    resultHolder.setCorrelationId(request.getCorrelationId());
    DataSource<PMMLRequestData> childModelRequest = executor.newDataSource("childModelRequest");
    DataSource<PMML4Result> childModelResults = executor.newDataSource("childModelResults");
    DataSource<SegmentExecution> childModelSegments = executor.newDataSource("childModelSegments");
    DataSource<? extends AbstractPMMLData> miningModelPojo = executor.newDataSource("miningModelPojo");
    List<String> possiblePackages = this.calculatePossiblePackageNames("SampleMine");
    Class<? extends RuleUnit> ruleUnitClass = this.getStartingRuleUnit("Start Mining - SampleMine", (InternalKnowledgeBase) kbase, possiblePackages);
    assertNotNull(ruleUnitClass);
    data.insert(request);
    resultData.insert(resultHolder);
    executor.run(ruleUnitClass);
    // console.close();
    resultData.forEach(rd -> {
        assertEquals(request.getCorrelationId(), rd.getCorrelationId());
        assertEquals("OK", rd.getResultCode());
        if (rd.getSegmentationId() == null) {
            assertNotNull(rd.getResultValue("Fld5", null));
            String value = rd.getResultValue("Fld5", "value", String.class).orElse(null);
            assertEquals("tgtZ", value);
            AbstractTreeToken token = rd.getResultValue("MissingTreeToken", null, AbstractTreeToken.class).orElse(null);
            assertNotNull(token);
            assertEquals(0.6, token.getConfidence().doubleValue(), 0.0);
            assertEquals("null", token.getCurrent());
        }
    });
    int segmentsExecuted = 0;
    for (Iterator<SegmentExecution> iter = childModelSegments.iterator(); iter.hasNext(); ) {
        SegmentExecution cms = iter.next();
        assertEquals(request.getCorrelationId(), cms.getCorrelationId());
        if (cms.getState() == SegmentExecutionState.COMPLETE)
            segmentsExecuted++;
    }
    assertEquals(1, segmentsExecuted);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) SegmentExecution(org.kie.pmml.pmml_4_2.model.mining.SegmentExecution) InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) RuleUnitExecutor(org.kie.api.runtime.rule.RuleUnitExecutor) AbstractTreeToken(org.kie.pmml.pmml_4_2.model.tree.AbstractTreeToken) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Aggregations

InternalRuleUnitExecutor (org.drools.core.impl.InternalRuleUnitExecutor)6 Test (org.junit.Test)6 PMML4Result (org.kie.api.pmml.PMML4Result)6 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)6 RuleUnitExecutor (org.kie.api.runtime.rule.RuleUnitExecutor)6 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)6 SegmentExecution (org.kie.pmml.pmml_4_2.model.mining.SegmentExecution)6 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ScoreCard (org.kie.pmml.pmml_4_2.model.ScoreCard)2 AbstractTreeToken (org.kie.pmml.pmml_4_2.model.tree.AbstractTreeToken)1