Plz reply : Descending order rule
by barath gunasagaran
Hi,
Can u explain me the rule flow for the below rule ?.
This will help me to get some clear idea about rules.
rule "Descending order"
when
$a : Order( $value : value )
not Order( value > $value)
then
System.out.println("value :"+$value);
retract($a);
end
I am having the following ,
1. Order value=1
2. Order value=2
3. Order value=3
4. Order value=4
5. Order value=5
Can u explain the flow(when part) for this 5 object ?
Note my understanding(in when) : 1st line take one order object
2nd line check for
any other object with grater 'value'
But i dont know
sequence in which the objects are taken.
Plz do reply......
Thanks in advance,
Barath.
18 years
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...
18 years
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.
18 years
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
18 years
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
18 years
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
18 years
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
18 years
"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
18 years
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
18 years