[Drools] Order of sequence of execution of Conditions and Actions
by Yv RamaRao
Hi all,
I has a problem in executing the drool code. I have
2 rules with a condition and an action.
The order of execution is
executeCondition1
executeCondition2
executeAction2()
executeAction1()
but to fullfill my requirements i need the sequence to be executed as
executeCondition1
executeAction1()
executeCondition2
executeAction2()
Is there any to get way to execute the sequence as above. Kindly suggest
Here is Drool Code and Implementation Java Code
Sample.drl
========
package com.sample
import com.sample.DroolsTest.MyDeligate;
rule "Rule1"
salience 2
when
delegate: MyDeligate()
eval(delegate.executeCondition1());
then
delegate.executeAction1();
end
rule "Rule2"
salience 1
when
delegate: MyDeligate()
eval(delegate.executeCondition2());
then
delegate.executeAction2();
end
DroolTest.java
===========
package com.sample;
import java.io.InputStreamReader;
import java.io.Reader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
public class DroolsTest {
public static final void main(String[] args) {
try {
RuleBase ruleBase = readRule();
WorkingMemory workingMemory = ruleBase.newWorkingMemory();
MyDeligate delegate = new MyDeligate();
workingMemory.assertObject(delegate);
workingMemory.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static RuleBase readRule() throws Exception
{
Reader source = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source );
Package pkg = builder.getPackage();
RuleBase ruleBase =
RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
public static class MyDeligate
{
public boolean executeCondition1()
{
System.out.println("Executed Condition1");
return true;
}
public boolean executeCondition2()
{
System.out.println("Executed Condition2");
return true;
}
public boolean executeCondition3()
{
System.out.println("Executed Condition3");
return true;
}
public boolean executeAction1()
{
System.out.println("Executed Action1");
return true;
}
public boolean executeAction2()
{
System.out.println("Executed Action2");
return true;
}
public boolean executeAction3()
{
System.out.println("Executed Action3");
return true;
}
}
}
Regards
Ramarao
Why delete messages? Unlimited storage is just a click away. Go to http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html
18 years, 5 months
How to dump the class/src generated by .drl file?
by Yang Song
Greetings everyone,
Does anyone know how to dump the class generated from .drl file to disk? Or
even better if the generated Java source file can be dumped?
Looking for some hints here, I got a NPE when firing the rules. However, it
is really hard to find out why the NEP was thrown... If I can have the
dumped class file, then I can be disassemble it back to Java code.
To debug this rule in Eclipse is a bit difficult here, because the
project is a little "big" and we usually use logging to do debugging...
java.lang.NullPointerException
at monitor.Rule_ftp_other_host_alarm_0.consequence
(Rule_ftp_other_host_alarm_0.java:23)
at monitor.Rule_ftp_other_host_alarm_0ConsequenceInvoker.evaluate
(Rule_ftp_other_host_alarm_0ConsequenceInvoker.java:26)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java
:545)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java
:509)
at org.drools.common.AbstractWorkingMemory.fireAllRules(
AbstractWorkingMemory.java:430)
at org.drools.common.AbstractWorkingMemory.fireAllRules(
AbstractWorkingMemory.java:392)
at com.monitor.ruleengine.InferenceMachine.fireAllRules(
InferenceMachine.java:400)
at com.monitor.ruleengine.InferenceMachine.run(InferenceMachine.java
:314)
at java.lang.Thread.run(Thread.java:595)
Thanks very much,
Yang
18 years, 5 months
problems with Otherwise()
by Matt Geis
I've got the following three rules in my DRL, but I'm seeing odd results.
rule "matchfound"
when
s : String()
then
System.out.println("got a match, string found in working memory");
end
rule "intmatchfound"
when
i : Integer()
then
System.out.println("got a match, Integer found in working memory");
end
rule "no matching rule"
when
Otherwise()
then
System.out.println("no rule applied, using otherwise rule");
end
If I assert a String, then the 'matchfound' rule fires. If I assert an Integer, 'intmatchfound' fires. If I assert an object of a different type or do not assert anything, the rule I would expect to fire ('no matching rule') never fires. The only way I can get it to fire is if I explicitly assert an instance of Otherwise.
I was under the impression that Drools would automatically assert it when it sees that no other rule has fired.
Am I doing something wrong here? Did usage of Otherwise change?
____________________________________________________________________________________
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more.
http://mobile.yahoo.com/go?refer=1GNXIC
18 years, 5 months
Guided editor (BRL) rules in the drools-examples-brms dont work
by Edgardo
Hi list, I post my problem in the rules-dev list. The problem is execute
the "Driver is Crazy", "Driver is too old" and "Driver special age
Approved" rules. I have the problem of the next section:
> Edgardo wrote:
>> Yes, I did it, in the package configuration. I use the
>> drools-4.0.0-brms version. The problem is at the moment to evaluate the
>> next generate code of the rule:
>>
>> then
>> Rejection fact0 = new Rejection();
>> fact0.setReason( "Driver too old" );
>> insert( fact0 );
>>
>> If I use the Technical rule text editor, i dont have any problem.
>>
>> Greetings from Chile :)
>>
>> En Fri, 03 Aug 2007 19:06:05 -0400, Mark Proctor
>> <mproctor(a)codehaus.org> escribió:
>>
>>> did you upload your model and import it?
>>>
>>> Mark
>>> Edgardo wrote:
>>>> Hi rules-dev list, (my english is very poor, sorry) I am interested
>>>> in using the
>>>> BRMS of JBoss Rules, but when I use the guided editor, this rules dont
>>>> work, and in drools-examples-brms example, this dont work too, the
>>>> error message (in the
>>>> "Driver is Crazy" rule)is:
>>>>
>>>> RuleAgent(insuranceconfig) INFO (Fri Aug 03 16:05:58 CLT 2007): Adding
>>>> package called org.acme.insurance
>>>> org.mvel.CompileException: class or class reference not found:
>>>> Rejection()
>>>> at
>>>> org.mvel.optimizers.impl.asm.ASMAccessorOptimizer.optimizeObjectCreation(ASMAccessorOptimizer.java:1771)
>>>> at
>>>> org.mvel.ast.NewObjectNode.getReducedValueAccelerated(NewObjectNode.java:49)
>>>> at org.mvel.MVELRuntime.execute(MVELRuntime.java:87)
>>>> at
>>>> org.mvel.CompiledExpression.getValue(CompiledExpression.java:98)
>>>> at
>>>> org.mvel.CompiledExpression.getValue(CompiledExpression.java:93)
>>>> at
>>>> org.mvel.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:36)
>>>> at org.mvel.MVELRuntime.execute(MVELRuntime.java:87)
>>>> at
>>>> org.mvel.CompiledExpression.getValue(CompiledExpression.java:98)
>>>> at org.mvel.MVEL.executeExpression(MVEL.java:202)
>>>> at
>>>> org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:32)
>>>> at
>>>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:545)
>>>> at
>>>> org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:509)
>>>> at
>>>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:430)
>>>> at
>>>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:392)
>>>> at
>>>> org.acme.insurance.launcher.InsuranceBusiness.testDriverCrazy(InsuranceBusiness.java:93)
>>>> at
>>>> org.acme.insurance.launcher.InsuranceBusiness.executeExample(InsuranceBusiness.java:19)
>>>> at org.acme.insurance.launcher.MainClass.main(MainClass.java:13)
>>>> org.drools.spi.ConsequenceException: org.mvel.CompileException: class
>>>> or
>>>> class reference not found: Rejection()
>>>> at
>>>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:549)
>>>> at
>>>> org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:509)
>>>> at
>>>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:430)
>>>> at
>>>> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:392)
>>>> at
>>>> org.acme.insurance.launcher.InsuranceBusiness.testDriverCrazy(InsuranceBusiness.java:93)
>>>> at
>>>> org.acme.insurance.launcher.InsuranceBusiness.executeExample(InsuranceBusiness.java:19)
>>>> at org.acme.insurance.launcher.MainClass.main(MainClass.java:13)
>>>> Caused by: org.mvel.CompileException: class or class reference not
>>>> found:
>>>> Rejection()
>>>> at
>>>> org.mvel.optimizers.impl.asm.ASMAccessorOptimizer.optimizeObjectCreation(ASMAccessorOptimizer.java:1771)
>>>> at
>>>> org.mvel.ast.NewObjectNode.getReducedValueAccelerated(NewObjectNode.java:49)
>>>> at org.mvel.MVELRuntime.execute(MVELRuntime.java:87)
>>>> at
>>>> org.mvel.CompiledExpression.getValue(CompiledExpression.java:98)
>>>> at
>>>> org.mvel.CompiledExpression.getValue(CompiledExpression.java:93)
>>>> at
>>>> org.mvel.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:36)
>>>> at org.mvel.MVELRuntime.execute(MVELRuntime.java:87)
>>>> at
>>>> org.mvel.CompiledExpression.getValue(CompiledExpression.java:98)
>>>> at org.mvel.MVEL.executeExpression(MVEL.java:202)
>>>> at
>>>> org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:32)
>>>> at
>>>> org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:545)
>>>> ... 6 more
>>>>
>>>> Thanks :), I am waiting for you response...
>>>>
>>>
>>> _______________________________________________
>>> rules-dev mailing list
>>> rules-dev(a)lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-dev
>>
>>
>>
>
> _______________________________________________
> rules-dev mailing list
> rules-dev(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
--
Edgardo Ibañez O.
18 years, 5 months
finding matching entries in parallel arrays
by Aaron Dixon
My problem boils down to finding matching entries in parallel arrays.
Here is a rule that succesfully does just that:
rule "Find matching entry in parallel arrays"
when
$first : ArrayList( )
$second : ArrayList( this != $first )
$i : Integer( this < $first.size )
eval( $first.get($i) == $second.get($i) )
then
System.out.println ( "Found match at index " + $i + "!" );
end
To execute this rule, I must insert (assert) the two ArrayList facts as well
as at least as many Integer facts as there are items in the ArrayLists.
What I don't like about this rule is that
(1) I have to assert the Integers
(2) I can't support arbitrarily-sized lists in my rules (without
asserting that many Integer facts)
So -- Is there a better way?
What if a future version of Drools supported implicit Number facts that
allowed for these kinds of indexing rules?
Aaron
18 years, 5 months
problems using the from
by hypnosat7
Hi,
This is my rule :
#declare any global variables here
global MockServiceRepository service
rule "Your First Rule"
when
Variable($list : values ) from service.findVariableByName("njdn","dedkm")
r : Rum(diagnostic memberOf (value in $list))
then
System.out.println("test From ok");
end
And this is the errors
testFromPackage/Rule_Your_First_Rule_0.java (12:581) : value cannot be
resolved
testFromPackage/Rule_Your_First_Rule_0.java (12:587) : Syntax error on
token "in", instanceof expected
testFromPackage/Rule_Your_First_Rule_0.java (12:590) : $list cannot be
resolved to a type
I have a class Variable with a values property :
private Set<VariableValue> values = new LinkedHashSet<VariableValue>();
And a class VariableValue with those properties :
private String id;
protected String value;
private Variable variable;
--
View this message in context: http://www.nabble.com/problems-using-the-from-tf4229482.html#a12032198
Sent from the drools - user mailing list archive at Nabble.com.
18 years, 5 months
WG: Second Rule does not recognize changes from first rule?
by Martin Book
Hello,
i am a newbie at JBoss Rules and have a problem with a ruleset. Here are my
rules:
rule "1.CallsPerDay" --> Modifies the "CallsPerDayOfWeek" objects.
salience 35
when
$dayObj: CallsPerDay( $day: dayOfWeekS != null, $calls:calls > 0
)
$dayInWeek: CallsPerDayOfWeek( day == $day )
then
$dayInWeek.addCalls($calls); --> Changes call variable.
System.out.println("Drools: "+$dayObj.getInfo()+" /
"+$dayInWeek.getCalls());
End
//Output: Drools: On Mo 02/19/2007 12:00:00 AM 97 calls came in. / 104
rule "2.ProcessAgents" -> Should only process on changed "CallsPerDayOfWeek"
objects (calls must be 104 but seem to be still 0)
salience 35
when
$dayInWeek:CallsPerDayOfWeek ($callsTMP: calls==0, sum == 0)
then
System.out.println("Sum = "+$dayInWeek.getSum()+" for
"+$dayInWeek.getDay()+" CallTMP: "+$callsTMP+" /CallReally:
"+$dayInWeek.getCalls());
end
//Output= Sum = 2 for Mo CallTMP: 0 /CallReally: 104
Why is the "calls" variable still 0 at the beginning of rule
"2.ProcessAgents", although it was modified by the rule "1.CallsPerDay"?
with kind regards
Martin
18 years, 5 months