You want to see how I tackled the "Or" problem??
 
Just have a look at this single line taken out from my dsl...
 
[when]- Orkeyvalue with key "{keya}" having value "{valuea}" Ormaybe Orkeyvalue with key "{keyb}" having value "{valueb}" Ormaybe Orkeyvalue with key "{keyc}" having value "{valuec}" Ormaybe Orkeyvalue with key "{keyd}" having value "{valued}" Ormaybe Orkeyvalue with key "{keye}" having value "{valuee}"=$kvp : keyValuePairMap -> (((("{valuea}").equals($kvp.get("{keya}"))) || ((("{valuea}"=="0") || ("{valuea}"=="OTH") || ("{valuea}"=="NA") || ("{valuea}"=="01/01/1900") || ("{valuea}"=="N")) && ($kvp.get("{keya}")==null)))) || (((("{valueb}").equals($kvp.get("{keyb}"))) || ((("{valueb}"=="0") || ("{valueb}"=="OTH") || ("{valueb}"=="NA") || ("{valueb}"=="01/01/1900") || ("{valueb}"=="N")) && ($kvp.get("{keyb}")==null)))) || (((("{valuec}").equals($kvp.get("{keyc}"))) || ((("{valuec}"=="0") || ("{valuec}"=="OTH") || ("{valuec}"=="NA") || ("{valuec}"=="01/01/1900") || ("{valuec}"=="N")) && ($kvp.get("{keyc}")==null)))) || (((("{valued}").equals($kvp.get("{keyd}"))) || ((("{valued}"=="0") || ("{valued}"=="OTH") || ("{valued}"=="NA") || ("{valued}"=="01/01/1900") || ("{valued}"=="N")) && ($kvp.get("{keyd}")==null)))) || (((("{valuee}").equals($kvp.get("{keye}"))) || ((("{valuee}"=="0") || ("{valuee}"=="OTH") || ("{valuee}"=="NA") || ("{valuee}"=="01/01/1900") || ("{valuee}"=="N")) && ($kvp.get("{keye}")==null))))
 
this is just a line to handle something like
 
 
    some_constraint
and
    name is "peter" or name is "john" or name is "paul" or name is "tom" or name is "mat"
and
    some_other_constraint
 
 
as I also should handle cases as
 
name is "peter" or name is "john" or name is not "paul" or name is "tom" or name is "mat"
name is "peter" or name is "john" or name is "paul" or name is not "tom" or name is "mat"
.....
 
I ended up with 32+16+8+4+2 lines in the dsl to handle all possible combinations of "ors" and "nots" with a maximum of 5 ors, any additional "n" number of "ors" will need (n-1 number of lines)*2 additional lines in the DSL
 
So, basically, the rule engine can do whatever you're want as long as you're ready to spend hours constructing a proper dsl file.
 
Tip: When constructing a dsl for these combinations, put the combinations in descending order, in our case:
 
5 ors -> 4 ors ..... -> 1 or
 
This has to be done as such because if you put
 
player1 or player2 (1)
 
and then
 
player 1 or player2 or player3 (2)
 
in your dsl, whenver you put
 
player1 or player2 or player3
 
in your rule, it will give you an error "OR not expected" as the match was done against line (1) i/of (2)
 
Brgrds,
Matias
 
 
 


From: gabriel quennesson [mailto:[EMAIL PROTECTED]
Sent: 08 November 2006 13:42
To: [email protected]
Subject: Re: [drools-user] Drools limitations for football managers?

I'm not sure this is the answer you expect but you could do the following :

when
    Player1 (name matches "Roy|Bob")
    Player2(name matches "Tom|Eric")
...
    Player11(name matches "Paulo|Ryan")
then
    doStuff();
end

In some trickier cases, you could use functions to perform other forms of matching.

Or you could just write the rule the exact way you did with "and" and "or" keywords, which is documented in Drools (I wasn't able to successfully write such a rule, though).

Regards,

Gabriel

John Cocktolstoy a écrit :
Hi,

I am new to Drools, I just read documentations and went through some examples.
I am wondering about the following example (I spiced it up with a story so it should not be boring :-) ):

Suppose I am a football manager and trying to use Drools to automate some processes.
I have 11 classes (these are going to be facts):
Player1, Player2, Player3, ..., Player11
One for each player of my team, each of class has one field:
String name
In run-time I will assert into working memory only one instance of each class as I would like to evaluate some rules over my current team.
Now I would like to create simple rule - I express it in pseudo-language:

when
  ((Player1.name == "Roy") or ( Player1.name == "Bob"))
and
  ((Player2.name == "Tom") or ( Player2.name == "Eric"))
and
  ...
and
  ((Player11.name == "Paulo") or (Player11.name == "Ryan"))
then
  do something

Could anyone show me how to express this rule using Drools without going into huge number of rules? As I understand from documentation each 'or' is creating two sub-rules. Isn't that limitation that makes Drools useless for football managers?

regards
John

**** DISCLAIMER ****
http://www.belgacom.be/maildisclaimer

Reply via email to