use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class SegmentPropagationTest method createContext.
public BuildContext createContext() {
RuleBaseConfiguration conf = new RuleBaseConfiguration();
KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf);
BuildContext buildContext = new BuildContext(rbase);
RuleImpl rule = new RuleImpl("rule1").setPackage("org.pkg1");
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.pkg1");
pkg.getDialectRuntimeRegistry().setDialectData("mvel", new MVELDialectRuntimeData());
pkg.addRule(rule);
buildContext.setRule(rule);
return buildContext;
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class ReteooBuilderPerformanceTest method getReteBuilders.
private static ReteooBuilder[] getReteBuilders(int count) {
System.out.println("Creating " + count + " ReteBuilder's");
ReteooBuilder[] reteBuilders = new ReteooBuilder[count];
RuleBaseConfiguration conf = new RuleBaseConfiguration();
for (int i = 0; i < reteBuilders.length; i++) {
reteBuilders[i] = new ReteooBuilder(new KnowledgeBaseImpl("id1", conf));
}
return reteBuilders;
}
use of org.drools.core.impl.KnowledgeBaseImpl 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.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class Misc2Test method testFromEPDontRequireLeftInput.
@Test
public void testFromEPDontRequireLeftInput() {
// DROOLS-1014
String drl = "rule R when\n" + " $s1 : String() from entry-point \"xxx\"\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper().addContent(drl, ResourceType.DRL).build();
Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
LeftInputAdapterNode liaNode = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
Class<?> otnType = ((ClassObjectType) otn.getObjectType()).getClassType();
if (String.class == otnType) {
assertEquals(1, otn.getObjectSinkPropagator().size());
} else if (InitialFact.class.isAssignableFrom(otnType)) {
assertEquals(0, otn.getObjectSinkPropagator().size());
} else {
fail("There shouldn't be other OTNs");
}
}
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class NodePositionInPathTest method test.
@Test
public void test() {
String drl = "rule R1 when\n" + " Integer()\n" + " exists( Integer() and Integer() )\n" + " String()\n" + "then\n" + "end\n" + "rule R2 when\n" + " Integer()\n" + " exists( Integer() and String() )\n" + "then\n" + "end\n";
KieBase kbase = new KieHelper().addContent(drl, ResourceType.DRL).build();
ReteDumper.dumpRete(((InternalKnowledgeBase) kbase));
Rete rete = ((KnowledgeBaseImpl) kbase).getRete();
LeftInputAdapterNode liaNode = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
Class<?> otnType = ((ClassObjectType) otn.getObjectType()).getClassType();
if (Integer.class == otnType) {
liaNode = (LeftInputAdapterNode) otn.getObjectSinkPropagator().getSinks()[0];
}
}
assertEquals(0, liaNode.getPositionInPath());
LeftTupleSink[] liaSinks = liaNode.getSinkPropagator().getSinks();
BetaNode join1 = (BetaNode) liaSinks[0];
assertEquals(1, join1.getPositionInPath());
ExistsNode ex1 = (ExistsNode) liaSinks[1];
assertEquals(1, ex1.getPositionInPath());
BetaNode join2 = (BetaNode) ex1.getSinkPropagator().getSinks()[0];
assertEquals(2, join2.getPositionInPath());
RuleTerminalNode rtn1 = (RuleTerminalNode) join2.getSinkPropagator().getSinks()[0];
assertEquals(3, rtn1.getPositionInPath());
ExistsNode ex2 = (ExistsNode) liaSinks[2];
assertEquals(1, ex2.getPositionInPath());
RuleTerminalNode rtn2 = (RuleTerminalNode) ex2.getSinkPropagator().getSinks()[0];
assertEquals(2, rtn2.getPositionInPath());
BetaNode join3 = (BetaNode) join1.getSinkPropagator().getSinks()[0];
assertEquals(2, join3.getPositionInPath());
RightInputAdapterNode ria1 = (RightInputAdapterNode) join3.getSinkPropagator().getSinks()[0];
assertEquals(3, ria1.getPositionInPath());
BetaNode join4 = (BetaNode) join1.getSinkPropagator().getSinks()[1];
assertEquals(2, join4.getPositionInPath());
RightInputAdapterNode ria2 = (RightInputAdapterNode) join4.getSinkPropagator().getSinks()[0];
assertEquals(3, ria2.getPositionInPath());
LeftTupleNode[] rtn1PathNodes = rtn1.getPathNodes();
assertEquals(4, rtn1PathNodes.length);
checkNodePosition(rtn1PathNodes, liaNode);
checkNodePosition(rtn1PathNodes, ex1);
checkNodePosition(rtn1PathNodes, join2);
checkNodePosition(rtn1PathNodes, rtn1);
LeftTupleNode[] rtn2PathNodes = rtn2.getPathNodes();
assertEquals(3, rtn2PathNodes.length);
checkNodePosition(rtn2PathNodes, liaNode);
checkNodePosition(rtn2PathNodes, ex2);
checkNodePosition(rtn2PathNodes, rtn2);
LeftTupleNode[] ria1PathNodes = ria1.getPathNodes();
assertEquals(4, ria1PathNodes.length);
checkNodePosition(ria1PathNodes, liaNode);
checkNodePosition(ria1PathNodes, join1);
checkNodePosition(ria1PathNodes, join3);
checkNodePosition(ria1PathNodes, ria1);
LeftTupleNode[] ria2PathNodes = ria2.getPathNodes();
assertEquals(4, ria2PathNodes.length);
checkNodePosition(ria2PathNodes, liaNode);
checkNodePosition(ria2PathNodes, join1);
checkNodePosition(ria2PathNodes, join4);
checkNodePosition(ria2PathNodes, ria2);
}
Aggregations