use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.
the class ScorecardTest method testScorecardWithSimpleSetPredicate.
@Test
public void testScorecardWithSimpleSetPredicate() {
KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(SOURCE_SIMPLE_SET_SCORECARD);
PMMLExecutor executor = new PMMLExecutor(kieBase);
PMMLRequestData requestData = new PMMLRequestData("123", "SimpleSetScorecard");
requestData.addRequestParam("param1", 4);
requestData.addRequestParam("param2", "optA");
PMML4Result resultHolder = executor.run(requestData);
Assertions.assertThat(resultHolder).isNotNull();
double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(113);
requestData = new PMMLRequestData("123", "SimpleSetScorecard");
requestData.addRequestParam("param1", 5);
requestData.addRequestParam("param2", "optA");
resultHolder = executor.run(requestData);
Assertions.assertThat(resultHolder).isNotNull();
score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(33);
requestData = new PMMLRequestData("123", "SimpleSetScorecard");
requestData.addRequestParam("param1", -5);
requestData.addRequestParam("param2", "optC");
resultHolder = executor.run(requestData);
Assertions.assertThat(resultHolder).isNotNull();
score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(123);
requestData = new PMMLRequestData("123", "SimpleSetScorecard");
requestData.addRequestParam("param1", -5);
requestData.addRequestParam("param2", "optA");
resultHolder = executor.run(requestData);
Assertions.assertThat(resultHolder).isNotNull();
score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(113);
}
use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.
the class ScorecardTest method testScorecardWithComplexPartialScore.
@Test
public void testScorecardWithComplexPartialScore() {
KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(SOURCE_COMPLEX_PARTIAL_SCORE_SCORECARD);
PMMLExecutor executor = new PMMLExecutor(kieBase);
PMMLRequestData requestData = new PMMLRequestData("123", "ComplexPartialScoreScorecard");
requestData.addRequestParam("param", 5.0);
PMML4Result resultHolder = executor.run(requestData);
Assertions.assertThat(resultHolder).isNotNull();
double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(20);
requestData = new PMMLRequestData("123", "ComplexPartialScoreScorecard");
requestData.addRequestParam("param", 40.0);
resultHolder = executor.run(requestData);
Assertions.assertThat(resultHolder).isNotNull();
score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(150);
requestData = new PMMLRequestData("123", "ComplexPartialScoreScorecard");
requestData.addRequestParam("param", 100.0);
resultHolder = executor.run(requestData);
Assertions.assertThat(resultHolder).isNotNull();
score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(205);
}
use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.
the class UserDefinedFunctionsTest method testFunctions0.
@Test
public void testFunctions0() throws Exception {
setKSession(getModelSession(source0, VERBOSE));
setKbase(getKSession().getKieBase());
FactType userAge1 = getKbase().getFactType(packageName, "UserAge");
PMMLRequestData request = new PMMLRequestData("TestSimple");
request.addRequestParam("Age", 2.2);
getKSession().insert(request);
// getKSession().getEntryPoint( "in_Age" ).insert( 2.2 );
getKSession().fireAllRules();
System.out.println(reportWMObjects(getKSession()));
checkFirstDataFieldOfTypeStatus(userAge1, true, false, null, 22.0);
checkGeneratedRules();
}
use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.
the class SimpleRegressionTest method testClassification.
@Test
public void testClassification() throws Exception {
RuleUnitExecutor executor = createExecutor(source2);
PMMLRequestData request = new PMMLRequestData("123", "LinReg");
request.addRequestParam("fld1", 1.0);
request.addRequestParam("fld2", 1.0);
request.addRequestParam("fld3", "x");
PMML4Result resultHolder = new PMML4Result();
List<String> possiblePackages = calculatePossiblePackageNames("LinReg");
Class<? extends RuleUnit> unitClass = getStartingRuleUnit("RuleUnitIndicator", (InternalKnowledgeBase) kbase, possiblePackages);
assertNotNull(unitClass);
int x = executor.run(unitClass);
data.insert(request);
resultData.insert(resultHolder);
executor.run(unitClass);
assertNotNull(resultHolder.getResultValue("RegOut", null));
assertNotNull(resultHolder.getResultValue("RegProb", null));
assertNotNull(resultHolder.getResultValue("RegProbA", null));
String regOut = resultHolder.getResultValue("RegOut", "value", String.class).orElse(null);
Double regProb = resultHolder.getResultValue("RegProb", "value", Double.class).orElse(null);
Double regProbA = resultHolder.getResultValue("RegProbA", "value", Double.class).orElse(null);
assertEquals("catC", regOut);
assertEquals(0.709228, regProb, 1e-6);
assertEquals(0.010635, regProbA, 1e-6);
}
use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.
the class PMMLExecutor method run.
private PMML4Result run(PMMLRequestData requestData, Optional<PMML4Data> data) {
KieRuntimeLogger logger = null;
RuleUnitExecutor ruleUnitExecutor = RuleUnitExecutor.create().bind(kieBase);
if (runWithLogging) {
if (loggingFileName != null) {
logger = ((InternalRuleUnitExecutor) ruleUnitExecutor).addFileLogger(loggingFileName);
} else {
logger = ((InternalRuleUnitExecutor) ruleUnitExecutor).addConsoleLogger();
}
}
DataSource<PMMLRequestData> requestDataSource = ruleUnitExecutor.newDataSource("request");
;
DataSource<PMML4Result> resultDataSource = ruleUnitExecutor.newDataSource("results");
DataSource<PMML4Data> pmmlDataSource = ruleUnitExecutor.newDataSource("pmmlData");
requestDataSource.insert(requestData);
PMML4Result resultHandler = new PMML4Result();
resultDataSource.insert(resultHandler);
if (data.isPresent()) {
pmmlDataSource.insert(data.get());
}
try {
ruleUnitExecutor.run(startingRuleUnit("RuleUnitIndicator", requestData.getModelName(), "org.drools.scorecards.example"));
} finally {
if (logger != null) {
logger.close();
}
}
return resultHandler;
}
Aggregations