Packages using, drools-ant vs. brms?
by Małecki
Hi
How to correct load packages generated by drools-ant?
I got no problem with importing packages from brms.
I try method below. Rules are loaded but not all are executed as in
classic java test.
File pkgFile = new File("c:/(...)/drools_test.rules.pkg");
ObjectInputStream in = new
DroolsObjectInputStream(newFileInputStream(pkgFile));
RuleBase p1_ = (RuleBase) in.readObject();
Second test (below) give me error
"org.drools.compiler.PackageBuilder$MissingPackageNameException:
Missing package name for rule package."
ObjectInputStream is = new DroolsObjectInputStream(new
FileInputStream(pkgFile));
RuleBaseLoader loader = RuleBaseLoader.getInstance();
RuleBase ruleBase = loader.loadFromReader(new InputStreamReader(is));
Any solution?
----------------------------------------------------
Mucha zaręczyła się z Wojewódzkim?
http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Fzareczyny.html...
16 years, 10 months
modifying individual facts in rule drl file
by Mehak
Hi
I am using drool to put my application business logic
In my java service class, I am adding into an ArrayList objects: task1,task2
and task3.
list.add(task1);
list.add(task2);
list.add(task3);
new RuleRunner().runRules(new String[] { "ruleTraverseFacts.drl" }, list);
Code in the RuleRunner class is :
public void runRules(String[] rules, ArrayList facts) throws Exception {
// RuleBase contains the rules to be applied to facts
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
PackageBuilder builder = new PackageBuilder();
for (int i = 0; i < rules.length; i++) {
String ruleFile = rules[i];
System.out.println("Loading file: " + ruleFile);
builder.addPackageFromDrl(new
InputStreamReader(RuleRunner.class
.getResourceAsStream("/BusinessRules/" + ruleFile)));
}
Package pkg = builder.getPackage();
ruleBase.addPackage(pkg);
//Facts are inserted in the working Memory of the ruleBase
WorkingMemory workingMemory = ruleBase.newStatefulSession();
Collection factList=new ArrayList();
for (int i = 0; i < facts.size(); i++) {
Object fact = facts.get(i);
System.out.println("Inserting fact: " +
fact.toString());
factList.add(workingMemory.insert(fact));
}
In my .drl class I have defined rules:
package BusinessRules
import model.*
import java.util.*
rule "traverse Collection"
when
$o1 : Task($child : childTasks , childTasks != null)
then
$o1.setWorkHours((getRollUp($child)) + $o1.getWorkHours());
update($o1);
System.out.println("estimated hours" + $o1.getWorkHours());
retract($o1);
end
function int getRollUp(ArrayList child) {
//some code
}
What I would want to do is identify and manipulate individual objects in the
working memory.
like task1.getId();.
All the rules in the drl file are applied to all the facts in working
memory. How can I access individual objects without specifying any
condition?
--
View this message in context: http://www.nabble.com/modifying-individual-facts-in-rule-drl-file-tp15605...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 10 months
Question about managing working memory facts
by Zoltan Farkas
I am looking to implement a system that has as facts "events" that happen randomly.
How is the best way to implement a "garbage collection" mechanism that if the number of "events" in the working memory reaches a limit value will retract the oldest event/s.
Thanks
--zoly
16 years, 10 months
OR condition in decision tables
by Mahesh Gadgil
Hi ALL, This is my first project on drools. I am using JBOSS rules 4.0.4 and wouldlike your help. I want to create a spreadsheet that will compile into drl file. I can notfigure out how I could create an OR condition in the spreadsheet. The drlcode I am looking to get finally will look like this. The documentation on JBOSS site does not provide any examples of OR condition in a spreadsheet. WHEN applicant : Applicant(applicantType == "authenticated" ||applicantType == "existing")............THEN applicant.setfundingType(internal") END. Thanking you in advanceMahesh
_________________________________________________________________
Post ads for free - to sell, rent or even buy.www.yello.in
http://ss1.richmedia.in/recurl.asp?pid=186
16 years, 10 months
drools parser loops infinitely.
by Godmar Back
Hi,
here's a simple test for which Drools 4.0.4 w/ MVEL 1.4 loops infinitely:
----
package tests;
import java.util.Map;
import java.io.File;
dialect "mvel"
rule "Rule #1"
when
p : Map (this["path"] matches File.separator);
then
System.out.println("cgi path " + p.path);
end
----
It appears to be related to the use of static String variable on the
rhs of the match clause.
- Godmar
16 years, 10 months
drools fails to parse Array literals correctly when using MVEL
by Godmar Back
Consider this test:
---
package tests;
import java.lang.reflect.Method;
dialect "mvel"
rule "Rule #1"
when
then
Class clazz = Class.forName("java.lang.Class");
System.out.println("clazz = " + clazz);
Method m = clazz.getDeclaredMethod("forName", new Class [] {
java.lang.String.class });
System.out.println("m = " + m);
end
--
(which runs correctly when dialect "java" is given), fails in Drools
4.0.4/MVEL 1.4 with:
org.mvel.CompileException: could not create constructor:
java.lang.Class.<init>()
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeObjectCreation(ReflectiveAccessorOptimizer.java:688)
at org.mvel.ast.NewObjectNode.getReducedValueAccelerated(NewObjectNode.java:191)
at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:106)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:521)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:260)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:109)
at org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated(VariableDeepPropertyNode.java:29)
at org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:77)
at org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:26)
at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)
at org.mvel.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:43)
at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
at org.mvel.MVEL.executeExpression(MVEL.java:235)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:47)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:471)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
at org.libx.autodetect.DroolsDriver$Host.fireAllRules(DroolsDriver.java:63)
at org.libx.autodetect.DroolsDriver.main(DroolsDriver.java:136)
It appears to be looking for a constructor for "new java.lang.Class()"
rather than constructing an array.)
Similarly, "o.method(new String [] { ... })" fails because it looks
for a method taking a String, rather than String[].
- Godmar
16 years, 10 months
"unable to resolve token" in simple mvel RHS
by Godmar Back
Hi,
with Drools 4.0.4 and MVEL 1.4, simple RHS like this one fail for me:
---
package test;
dialect "mvel"
rule "Rule #1"
when
then
System.out.println("now computing 1+1...");
Integer two = new Integer(2);
System.out.println(two);
end
---
now computing 1+1...
org.mvel.CompileException: unable to resolve property: two
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:288)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:109)
at org.mvel.ast.ContextDeepPropertyNode.getReducedValueAccelerated(ContextDeepPropertyNode.java:26)
at org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:123)
at org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:26)
at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:521)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:260)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:109)
at org.mvel.ast.LiteralDeepPropertyNode.getReducedValueAccelerated(LiteralDeepPropertyNode.java:28)
at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
at org.mvel.MVEL.executeExpression(MVEL.java:235)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:47)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:471)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
at org.libx.autodetect.DroolsDriver$Host.fireAllRules(DroolsDriver.java:63)
at org.libx.autodetect.DroolsDriver.main(DroolsDriver.java:136)
Caused by: org.mvel.PropertyAccessException: unable to resolve property: two
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:382)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:257)
... 19 more
org.mvel.CompileException: unable to resolve token: two
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:297)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:109)
at org.mvel.ast.LiteralDeepPropertyNode.getReducedValueAccelerated(LiteralDeepPropertyNode.java:28)
at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:111)
at org.mvel.MVEL.executeExpression(MVEL.java:235)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:47)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:471)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
at org.libx.autodetect.DroolsDriver$Host.fireAllRules(DroolsDriver.java:63)
at org.libx.autodetect.DroolsDriver.main(DroolsDriver.java:136)
Caused by: org.mvel.UnresolveablePropertyException: unable to resolve token: two
at org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:127)
at org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:26)
at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:521)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:260)
... 12 more
Caused by: org.mvel.CompileException: unable to resolve property: two
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:288)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:109)
at org.mvel.ast.ContextDeepPropertyNode.getReducedValueAccelerated(ContextDeepPropertyNode.java:26)
at org.mvel.ast.PropertyASTNode.initializePropertyNode(PropertyASTNode.java:123)
... 16 more
Caused by: org.mvel.PropertyAccessException: unable to resolve property: two
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:382)
at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:257)
... 19 more
etc.
It appears to be related to the use of MVEL - the same rule with
'dialect "java"' executes correctly.
- Godmar
16 years, 10 months
Pattern matching
by Jai Vasanth
Hi,
What is the difference between the following 2 statements
stmt1 : FactA( attrib1 == "X" || attrib1 =="Y")
stmt2: FactA( attrib1 =="X") or FactA(attrib1 =="Y")
Thanks
Jai
16 years, 10 months
RuleFlows and Working Memory..
by mmquelo massi
Hi there,
I have got a couple of questions about ruleflows and woking memory.
What does happen each time I modify a fact within a ruleflow node without
calling update(fact)?
What does happen between the node where I
apllied the modifications and the next activation node?
I guess that between one ruleflow node and the next one, all the modified
facts (in the previous node) are automatically updated (without explicitly
call "update()")
so that once the next node has been activated,
the corresponding shadow facts result synchronized with the actual facts.
Am I wrong?
Should I call "update()" instead?
My scenario...
I have got one node where I modify a fact, but I do not
want to call the update() because otherwise I would generate
a "ping-pong" loop between two decision tables that are
placed in the same rule flow node. I think I could use
the "no-active" attribute but I can't.... cause I can't specify
it in a Decision table.
Another workaround could be the "clearAgenda()" method
but It is not accesible from the "drools" (the helper) object...
How can I call it from the decision table or within an "action" ruleflow
node?
Maybe there is a third solution.... I should "update()" all the
fact from an action node ...but in this case I would need
to call an "update()" method that allowed me to update
"all the facts of a given Class", Is That Possible in drools?
I took a look on the API docs but some methods are not explained.
Looking forward to hearing from you!
Thank You again!
Massi
16 years, 10 months