That's why I said It probably wasn't the answer you expected.
You could use an inline function that would compare the value and return
true if it matches one argument or the other :
when
Player1 ( hisage : age -> ( compare(hisage, 19, 21) ) )
then
doStuff();
end
function boolean compare(int age, int firstValue, int secondValue) {
if (age == firstValue)
return true;
if (age == secondValue)
return true;
return false;
}
But I must admit it is not very clean either.
Now, in drools doc section *3.23 *it is stated you can group using
parenthesis and keywords, pretty much like you would in algebra. I
abandoned the idea though, and did the same by writing several rules.
John Cocktolstoy a écrit :
Thanks for the answer!
Yep, in case of String types I could use 'matches' . But what if each
player have also field:
int age
and instead of names I would like to compare age of players? How to
cope with that?
As to the second idea - I think I can't just write the rule the exact
way I did with "and" and "or" keywords. I believe it is impossible to
nest "and"s and "or"s. Am I right? I also wasn't able to successfully
write such a rule.
regards
John
On 11/8/06, *gabriel quennesson* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
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 <http://player1.name/> == "Roy") or (
Player1.name <http://player1.name/> == "Bob"))
and
((Player2.name <http://player2.name/> == "Tom") or (
Player2.name <http://player2.name/> == "Eric"))
and
...
and
((Player11.name <http://player11.name/> == "Paulo") or
(Player11.name <http://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
--
___________________
*Gabriel Quennesson *| CTC/I | *SEAM*
Int :* *7 906 6910 | Ext: 04 73 64 69 10
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email