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;
}
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));
}
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");
}
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");
}
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");
}
Aggregations