Re: variable 'or' constraints with a DSL
by Matt Geis
Hi Reid,
There is a way to do this, but it doesn't involve the "-" (AND) hyphen shortcut. You would write a regular DSL, and the RHS of your rule would be one line.
It's important to remember that DSL entry order is very important in your file. The domain-specific code you write can (either intentionally or unintentionally) be expanded many times before it arrives at the DRL language that is fed into the rules engine. In your case, the RHS of your rule will be tested once for a match against every "condition" entry in your DSL file.
What this means is that you want to first write your rule in standard drools syntax, then work backward to see how expansion of DSL entries slowly moves your DSL rule closer to, and ultimately into, a DRL rule.
You should be able to write something close to
There is a person with {color} hair or with {color} eyes or that is {height} inches tall or that is {age} years old
You *might* have to use the variable typing feature new to Drools 5.0, but you may not.
A couple approaches that may help you out are...
1. Write a unit test, and pass your DSL code through the DSLExpander and see what DRL code it generates (which may or may not be valid, but at least you'll see what the DSL engine is doing to your DSL rule).
2. Download the source and use a step-through debugger with a breakpoint so you can examine the consequences of every match attempted against the RHS of the rule, and the consequent results of the replacement if a match is found.
3. If you don't want to run a debugger, you could write some AOP code to emit the results of the RHS with each step of the expansion, but this approach would be more work than just running a debugger.
If you'd like to write a self-contained unit test with your DRL rule (the one that looks like the one I provided above, but verified to work), I can take a look at it and see what I'd do DSL-wise.
Matt
16 years, 6 months
Drools in multithreaded env
by Jin
Env setup:
1. There is only one instance of working memory.
2. There are at lease two threads constantly insert/update/delete facts from the
same workings memory based on some incoming messages.
3. I use temporal rules (duration clause) as well. When it is fired, it will be
on the third thread.
Question:
I can synchronize the first two threads by acquiring lock on the working memory.
But how do I synchronize the temporal rules thread especially on the left hand
side of the rules?
Thanks,
Jin
16 years, 6 months
variable 'or' constraints with a DSL
by Reid Kaufmann
I really like how you can specify a DSL like this (for example):
[condition]There is a person=$p : Person()
[condition]- with {color} hair=hairColor matches {color}
[condition]- with {color} eyes=eyeColor matches {color}
[condition]- that is {height} inches tall =height == {height}
[condition]- that is {age} years old=yearsOld == {age}
If I'm reading the documentation correctly, the rules can then be
specified with any subset of the constraints (lines beginning with
"-"). These constraints are then essentially ANDed together since they
are comma separated when converted to DRL. Since they are called
constraints, this makes sense. My question is this: Is there a similar
way to allow a variable number of "constraints" that are all ORed ("||")
together?
I've been reading the documentation and searching mail archives and so
far haven't found anything helpful. Let me know if there is a way to do
this or any clever workarounds, since I don't want to delineate every
possible combination of attributes when OR is needed.
reid
16 years, 6 months
Function call in LHS
by BINET JEAN-BAPTISTE
Hello,
I am new to Drools. I have downloaded and installed Drools 4.0.7.
After having read the documentation, I saw that it is possible to create
function in the .drl file.
I succeed in creating a function, calling it in the LHS with eval()
instruction or in the RHS.
But, is it possible to call a function in the LHS out of an eval() ? For
example, I would like to use
a pattern such as :
$tmp : MyClass( name == MyFunction() )
Thanks in advance.
Regards.
JB
16 years, 6 months
RE: [rules-dev] Multi threading usage best practice
by Anstis, Michael (M.)
Cross posted for information.
Ths subject is more for the user list than the dev' one.
Cheers,
________________________________
From: rules-dev-bounces(a)lists.jboss.org
[mailto:rules-dev-bounces@lists.jboss.org] On Behalf Of 9Lives 9Lives
Sent: 14 July 2008 14:33
To: Rules Dev List
Subject: RE: [rules-dev] Multi threading usage best practice
TnX Mike 4 the quick response.
I'm afraid that u r right regarding the through-put ;-(
Using the "synchronized" method will probably solve my problem
but will damage the solution.
If u have any other thoughts on the matter i would love 2 hear
them.
Regards
Dotan
________________________________
Subject: RE: [rules-dev] Multi threading usage best practice
Date: Mon, 14 Jul 2008 14:24:02 +0100
From: manstis1(a)ford.com
To: rules-dev(a)lists.jboss.org
Hi,
Would synchronising on working memory effectively serialise the
effects of fireAllRules()?
...
synchronised(wm) {
wm.fireAllRules();
}
...
I don't know whether this would kill your through-put either.
Cheers,
Mike
________________________________
From: rules-dev-bounces(a)lists.jboss.org
[mailto:rules-dev-bounces@lists.jboss.org] On Behalf Of 9Lives 9Lives
Sent: 14 July 2008 13:41
To: rules-dev(a)lists.jboss.org
Subject: [rules-dev] Multi threading usage best practice
Hello
I'm using Drools 4.0.7 inside a mail relay application 2
determine the operations that need 2 b executed on each passing message.
To do this i'm using the following scenario:
1.
I have a ruleBase.newStatefulSession().
2.
I have a fixed set of facts.
3.
I have a fixed set of rules.
4.
Each mailer (a thread that is handling a single
message) is inserting the message to the working memory, calls the
"fireAllRules" method and retracts the message.
5.
Rules that r executed change custom attributes
in the message.
Problem:
I noticed that sometimes a rule can b executed on the
same message more then once.
Assumption:
My guess is that because i'm working is a multi
threading environment but using a stateful session, what happens is:
1. Thread A is inserting Message A.
2. Thread B is inserting Message B
3. Thread A is calling fireAllRules
4. Rule X is executed on messages A + B.
5. Thread B is calling fireAllRules
6. Rule X is executed on messages A + B
7. Thread A is retracting Message A
8. Thread B is retracting message B
Question:
My goal is 2 make sure a rule is executed only once on a
single message.
Any ideas on how 2 avoid the situation described above?
TnX
Dotan
________________________________
Invite your mail contacts to join your friends list with
Windows Live Spaces. It's easy! Try it!
<http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.
aspx&mkt=en-us>
________________________________
Discover the new Windows Vista Learn more!
<http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE>
16 years, 6 months
Decision table
by Vanina Beraudo
Hello,
I need use a excel Decision table, in the CONDITION I invoque a
method, not a getter, and this method have a parameter. I dont know
how is the correct way to call a method with a parameter in CONDITION
part.
I do this,
CONDITION
i:Tax
taxValue("$1") < $2
10, 20
Could somebody give some idea how can I call a method with parameters?
Thanks,
--
Lic. Vanina Beraudo
16 years, 6 months
Re:[rules-users] Decision table
by tizianalauciello@libero.it
Hi,
I think that you would associate a variable to the method, like Java notation.
I hope this can help you.
Bye
Tiziana
---------- Initial Header -----------
>From : rules-users-bounces(a)lists.jboss.org
To : rules-users(a)lists.jboss.org
Cc :
Date : Thu, 10 Jul 2008 11:44:07 -0300
Subject : [rules-users] Decision table
> Hello,
>
> I need use a excel Decision table, in the CONDITION I invoque a
> method, not a getter, and this method have a parameter. I dont know
> how is the correct way to call a method with a parameter in CONDITION
> part.
>
> I do this,
>
> CONDITION
> i:Tax
> taxValue("$1") < $2
>
> 10, 20
>
> Could somebody give some idea how can I call a method with parameters?
>
> Thanks,
>
>
>
>
>
> --
> Lic. Vanina Beraudo
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 6 months
Compilation error: "Syntax error, insert "; " to complete BlockStatements "
by Kris Nuttycombe
Hi, all,
I'm new to Drools, and am a bit confused by the compilation error that
I'm getting. From the line number, it appears to be in a generated
Java file instead of in my rules file, so I'm having a hard time
debugging the issue. Here is the full error:
Rule Compilation error : [Rule name=Assert Total Accumulator for
Order, agendaGroup=init, salience=0, no-loop=false]
com/gaiam/gcsi/rules/Rule_Assert_Total_Accumulator_for_Order_0.java
(7:429) : Syntax error, insert ";" to complete BlockStatements
Here is the rule that's being referred to:
rule "Add charge amounts to total."
agenda-group "calc_total"
when
$total : Total()
$event : ProgramBillingEvent( $amount : amount)
then
modify( $total ) {
addCharge($event, $amount)
}
end
I'm working from the example modify block discussed in the docs at
http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html/ch02s05.html#d...
- I haven't been able to find other documentation referring to this
construct.
What am I doing wrong?
Thanks,
Kris
16 years, 6 months
Re: Rules 'firing' multiple times? (pramod george)
by pramod george
oh!
Thanks Anstis.. I would like to take somemore time
to comprehend what exactly you said. Yes I knew about
the working mem and that I meant was this when I said DB.
Thank you so much. Your reply is appreciated.
-Promod
16 years, 6 months