Search in sources :

Example 11 with PMMLExecutor

use of org.kie.pmml.pmml_4_2.PMMLExecutor in project drools by kiegroup.

the class ScorecardTest method testScorecardWithCompoundPredicate.

@Test
public void testScorecardWithCompoundPredicate() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(SOURCE_COMPOUND_PREDICATE_SCORECARD);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData requestData = new PMMLRequestData("123", "ScorecardCompoundPredicate");
    requestData.addRequestParam("param1", 41.0);
    requestData.addRequestParam("param2", 21.0);
    PMML4Result resultHolder = executor.run(requestData);
    double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(120.8);
    Map<String, Double> rankingMap = (Map<String, Double>) resultHolder.getResultValue("ScoreCard", "ranking");
    Assertions.assertThat(rankingMap.get("reasonCh1")).isEqualTo(50);
    Assertions.assertThat(rankingMap.get("reasonCh2")).isEqualTo(5);
    requestData = new PMMLRequestData("123", "ScorecardCompoundPredicate");
    requestData.addRequestParam("param1", 40.0);
    requestData.addRequestParam("param2", 25.0);
    resultHolder = executor.run(requestData);
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(120.8);
    requestData = new PMMLRequestData("123", "ScorecardCompoundPredicate");
    requestData.addRequestParam("param1", 40.0);
    requestData.addRequestParam("param2", 55.0);
    resultHolder = executor.run(requestData);
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(210.8);
    requestData = new PMMLRequestData("123", "ScorecardCompoundPredicate");
    requestData.addRequestParam("param1", 4.0);
    requestData.addRequestParam("param2", -25.0);
    resultHolder = executor.run(requestData);
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(30.8);
}
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) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Aggregations

Test (org.junit.Test)11 KieBase (org.kie.api.KieBase)11 PMML4Result (org.kie.api.pmml.PMML4Result)11 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)11 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)11 PMMLExecutor (org.kie.pmml.pmml_4_2.PMMLExecutor)11 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2