use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class KieBuilderSetImpl method registerInitialErrors.
private void registerInitialErrors(KieBuilderImpl kieBuilder) {
previousErrors = new HashMap<String, Collection<KnowledgeBuilderError>>();
InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModuleIgnoringErrors();
for (KieBaseModel kBaseModel : kieModule.getKieModuleModel().getKieBaseModels().values()) {
KnowledgeBuilder kBuilder = kieModule.getKnowledgeBuilderForKieBase(kBaseModel.getName());
if (kBuilder != null) {
previousErrors.put(kBaseModel.getName(), kBuilder.getErrors());
resourcesWithErrors.put(kBaseModel.getName(), findResourcesWithErrors(kBuilder));
}
}
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class BayesBeliefSystemTest method getSession.
protected KieSession getSession(String ruleFile) {
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(ResourceFactory.newClassPathResource(ruleFile), ResourceType.DRL);
if (kBuilder.hasErrors()) {
System.err.println(kBuilder.getErrors());
fail();
}
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addPackages(kBuilder.getKnowledgePackages());
KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
((SessionConfiguration) ksConf).setBeliefSystemType(BeliefSystemType.DEFEASIBLE);
KieSession kSession = kBase.newKieSession(ksConf, null);
return kSession;
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class JavaDialectBinaryEqualityTest method getKnowledgePackage1.
public KiePackage getKnowledgePackage1() {
String str = "";
str += "package org.drools.compiler.test\n";
str += "import " + Person.class.getName() + ";\n";
str += "global java.util.List list\n";
str += "rule rule1 dialect\"java\" \n";
str += "when\n";
str += " $p : Person( age : age == ( 17 + 17 ), eval( age == 34 ))\n";
str += " eval( $p.getAge() == 34 )\n";
str += "then\n";
str += " list.add( $p );\n";
str += "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
List<Person> list = new ArrayList<Person>();
KieSession ksession = kbase.newKieSession();
ksession.setGlobal("list", list);
ksession.insert(new Person("darth", 34));
ksession.fireAllRules();
assertEquals(new Person("darth", 34), list.get(0));
return kbase.getPackage("org.drools.compiler.test");
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class JavaDialectTest method testEvalDetectionInBetaNode.
@Test
public void testEvalDetectionInBetaNode() {
// Tests evals are generated and executed with Java dialect
String drl = "";
drl += "package org.drools.compiler.test\n";
drl += "import org.drools.compiler.Person\n";
drl += "global java.util.List list\n";
drl += "rule test1\n";
drl += "when\n";
drl += " $s : String()\n";
drl += " $p1 : Person( eval( name \n != $s ), name == ( new String($s+\"xxx\") ) )\n";
drl += "then\n";
drl += "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
assertFalse(kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
List<ObjectTypeNode> nodes = ((KnowledgeBaseImpl) kbase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for (ObjectTypeNode n : nodes) {
if (((ClassObjectType) n.getObjectType()).getClassType() == Person.class) {
node = n;
break;
}
}
BetaNode betaanode = (BetaNode) node.getObjectSinkPropagator().getSinks()[0];
BetaNodeFieldConstraint[] constraint = betaanode.getConstraints();
PredicateConstraint c = (PredicateConstraint) constraint[0];
assertTrue(c.getPredicateExpression() instanceof PredicateExpression);
assertTrue(c.getPredicateExpression() instanceof CompiledInvoker);
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class SessionInspectorTest method testGetSessionInfoWithCustomTemplate.
@Test
public void testGetSessionInfoWithCustomTemplate() {
if (System.getProperty("java.vendor").toUpperCase().contains("IBM")) {
// Does not work in the IBM JDK due to a bug in MVEL
return;
}
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_SubNetworks.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_AccumulateWithFromChaining.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_CollectResultsBetaConstraint.drl"), ResourceType.DRL);
kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_QueryMemoryLeak.drl"), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createKnowledgeSession(kbase);
ksession.setGlobal("results", new ArrayList<Object>());
ksession.insert(new Dimension(100, 50));
ksession.insert(new Dimension(130, 80));
ksession.insert(new Dimension(50, 40));
ksession.insert(new Dimension(50, 40));
Cheesery cheesery = new Cheesery();
cheesery.addCheese(new Cheese("brie", 10));
cheesery.addCheese(new Cheese("brie", 10));
cheesery.addCheese(new Cheese("brie", 10));
cheesery.addCheese(new Cheese("brie", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("muzzarella", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("stilton", 10));
ksession.insert(cheesery);
ksession.insert(new Person("Bob", "muzzarella"));
ksession.insert(new Person("Mark", "brie"));
ksession.insert(new Cheese("brie", 10));
ksession.insert(new Cheese("brie", 10));
ksession.insert(new Cheese("brie", 10));
ksession.insert(new Cheese("brie", 10));
ksession.insert(new Cheese("muzzarella", 10));
ksession.insert(new Cheese("muzzarella", 10));
ksession.insert(new Cheese("muzzarella", 10));
ksession.insert(new Cheese("muzzarella", 10));
ksession.insert(new Cheese("Stilton", 10));
ksession.insert(new Cheese("Stilton", 10));
ksession.insert(new Cheese("Stilton", 10));
ksession.insert(new Double(10));
ksession.insert(new Double(11));
ksession.insert(new Double(12));
ksession.insert(new Double(13));
ksession.insert(new Double(14));
ksession.insert(new Integer(15));
ksession.insert(new Integer(16));
ksession.insert(new Integer(17));
ksession.insert(new Integer(18));
FactHandle handle = ksession.insert(new Worker());
ksession.retract(handle);
SessionInspector inspector = new SessionInspector(ksession);
StatefulKnowledgeSessionInfo info = inspector.getSessionInfo();
SessionReporter.addNamedTemplate("topten", getClass().getResourceAsStream("customreports.mvel"));
String report = SessionReporter.generateReport("topten", info, null);
assertNotNull(report);
}
Aggregations