Query on loading facts dynamically
by jobin wilson
Hello List,
I have a very basic question about inserting facts into the working memory
dynamically.For firing the rules,we should be having all our facts in the
working memory.In that case,How will we deal with the situation where the
facts that we need for evaluation of a particular rule is dependent on the
rule itself (needs to be brought it dynamically)?
Say for example say i want to use rule engine to reward all students with
average scores for all subjects > 75 for the past 3 exams.
The facts that i have are the Student objects & their Subject wise
scores(one to many relation;one student to many exams & each exams having
many subjects).
I want the "when" condition to be satisfied for all students whose average
scores for all subjects for the past 3 exams to be greater than 75
and the consequence to be to just print out the name of the student.
In this case,should i be loading all the student objects & each of their
past exam scores in the whole system to find student objects satisfying this
critera?
Since i already know that the rule just need the average scores for just the
past 3 exams for each student,wouldn't loading the whole facts be
inefficient?
Is there a way in which i can specify somehow how much of the facts needs to
be loaded before firing the rule based on the rule itself?
i mean a rule which is aware of the quantity of the facts on which it needs
to work on(considering loading 3 facts versus 100 facts)?
Thanks a lot in advance for all your inputs and suggestions on this.
Thanks & Regards
Jobin Wilson
16 years
Rule Compilation Problems
by Jean-Philippe Steinmetz
Hello everyone,
I'm fairly new to Drools, having only worked with a basic setup for a
little while now. I've successfully gotten a Drools 5.0.1 runtime
working with an app running under JBoss 5 but now I need Drools to run
under a standalone application. I've more or less copied all of the set
up that I used in the JBoss app but am experiencing weird compilation
problems.
My application code looks like the following...
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("MyAgenda");
kagent.applyChangeSet(ResourceFactory.newClassPathResource("my_rules.xml
"));
KnowledgeBase kbase = kagent.getKnowledgeBase();
final StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());
KnowledgeRuntimeLogger krlogger =
KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
ksession.insert(myObject);
ksession.fireAllRules();
krlogger.close();
ksession.dispose();
and my rules file looks like...
package mypackage
rule "test"
when
Object()
then
System.out.println("Hello World!");
end
Finally this is the output I am seeing from my application...
[2010:06:180 18:06:144:info] ResourceChangeNotification created
[2010:06:180 18:06:147:info] ResourceChangeScanner created with default
interval=60
[2010:06:180 18:06:147:debug] ResourceChangeNotification monitor added
monitor=org.drools.io.impl.ResourceChangeScannerImpl@7d0b8078
[2010:06:180 18:06:149:info] KnowledgAgent created, with configuration:
monitorChangeSetEvents=true scanResources=true scanDirectories=true
[2010:06:180 18:06:149:info] KnowledegAgent has started listening for
ChangeSet notifications
(null: 3, 78): SchemaLocation: schemaLocation value =
'http://drools.org/drools-5.0/change-set.xsd' must have even number of
URI's.
(null: 3, 78): cvc-elt.1: Cannot find the declaration of element
'change-set'.
[2010:06:180 18:06:181:info] KnowledgAgent applying ChangeSet
[2010:06:180 18:06:182:debug] KnowledgeAgent subscribing to
resource=[ClassPathResource path='TestRules.drl']
[2010:06:180 18:06:182:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@61176350 to
resource=[ClassPath
Resource path='TestRules.drl']
[2010:06:180 18:06:185:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl@46794afc to
resource=[ClassPathR
esource path='TestRules.drl']
[2010:06:180 18:06:187:debug] KnowledgeAgent ChangeSet requires
KnowledgeBuilder
[2010:06:180 18:06:187:debug] KnowledgeAgent rebuilding KnowledgeBase
using ChangeSet
[2010:06:180 18:06:315:debug] KnowledgeAgent building
resource=[ClassPathResource path='TestRules.drl']
java.lang.NoSuchMethodError:
org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/e
clipse/jdt/core/compiler/CategorizedProblem;
at
org.drools.commons.jci.compilers.EclipseJavaCompiler$3.acceptResult(Ecli
pseJavaCompiler.java:321)
at
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:335)
at
org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJava
Compiler.java:351)
at
org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJa
vaCompiler.java:51)
at
org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.
java:389)
at
org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompile
timeRegistry.java:56)
at
org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:74)
at
org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:690)
at
org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:653)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java
:290)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.j
ava:488)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.ja
va:25)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgent
Impl.java:386)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentIm
pl.java:120)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentIm
pl.java:109)
Now I've checked all of the maven dependencies to make sure the they are
all there and I can doubly confirm everything is fine. In fact, I even
went so far to make sure the jars included in my app contained the
org.eclipse.jdt.core.compiler.CategorizedProblem.class file. The only
difference I've been able to think of so far is that my standalone
application uses the Java service wrapper where JBoss does not.
Any help is greatly appreciated.
Cheers,
Jean-Philippe Steinmetz
16 years