Re: [rules-users] newbie question on "when" condition syntax

2008-05-03 Thread Michael Anstis
Glad my hasty original reply has been ripped apart ;-)

Goes to show that everybody has something new to learn.

Thanks to everyone for the corrections (and simpler, correct, solution!).

Mike


On 02/05/2008, mashup <[EMAIL PROTECTED]> wrote:
>
>
> Ahhh I wondered about that, thanks. Again, now I see it, it makes complete
> sense. This drools stuff is actually pretty damn good!
>
> Richard
>
> Chris Woodrow wrote:
> >
> > You're right, if you want to do this with 2 facts, you'll need to do :
> >
> >   $test : Test( $y : y )
> >   Test(
> > this == $test,
> > x == ($y + 1) )
> >
> > Chris
> >
> > 2008/5/2 Raffi Khatchadourian <[EMAIL PROTECTED]>:
> >
> >> On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:
> >>
> >> > The "when" section matches fact (object) patterns, so your
> requirement
> >> > could be written as:-
> >> >
> >> > when there is a Test Fact 'A' and another Test Fact 'B' where "the
> 'x'
> >> > property of 'A'" equals "the 'y' property of fact 'B' plus 1"
> then.
> >> >
> >> > This would become:-
> >> >
> >> > rule "Rule 1"
> >> > when
> >> >   Test( $y : y )
> >> >   Test( x == ($y + 1) )
> >> >
> >>
> >> Actually, please correct me if I am mistaken, but is this condition
> >> correct? I believe that the original question is that for a single
> >> instance of class Test t, fire the rule when t.x == t.y + 1 (where 't'
> >> refers to the *same* instance of class Test). I believe the rule above
> >> would match any instance of class Test whose x value is equal to the
> >> value of the instance field y from *any* instance of class Test plus 1.
> >> Does that make sense?
> >> ___
> >> rules-users mailing list
> >> rules-users@lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>
> >
> > ___
> > rules-users mailing list
> > rules-users@lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/newbie-question-on-%22when%22-condition-syntax-tp17015309p17028019.html
> Sent from the drools - user mailing list archive at Nabble.com.
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread mashup

Ahhh I wondered about that, thanks. Again, now I see it, it makes complete
sense. This drools stuff is actually pretty damn good!

Richard

Chris Woodrow wrote:
> 
> You're right, if you want to do this with 2 facts, you'll need to do :
> 
>   $test : Test( $y : y )
>   Test(
> this == $test,
> x == ($y + 1) )
> 
> Chris
> 
> 2008/5/2 Raffi Khatchadourian <[EMAIL PROTECTED]>:
> 
>> On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:
>>
>> > The "when" section matches fact (object) patterns, so your requirement
>> > could be written as:-
>> >
>> > when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
>> > property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.
>> >
>> > This would become:-
>> >
>> > rule "Rule 1"
>> > when
>> >   Test( $y : y )
>> >   Test( x == ($y + 1) )
>> >
>>
>> Actually, please correct me if I am mistaken, but is this condition
>> correct? I believe that the original question is that for a single
>> instance of class Test t, fire the rule when t.x == t.y + 1 (where 't'
>> refers to the *same* instance of class Test). I believe the rule above
>> would match any instance of class Test whose x value is equal to the
>> value of the instance field y from *any* instance of class Test plus 1.
>> Does that make sense?
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> 
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/newbie-question-on-%22when%22-condition-syntax-tp17015309p17028019.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread Chris Woodrow
You're right, if you want to do this with 2 facts, you'll need to do :

  $test : Test( $y : y )
  Test(
this == $test,
x == ($y + 1) )

Chris

2008/5/2 Raffi Khatchadourian <[EMAIL PROTECTED]>:

> On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:
>
> > The "when" section matches fact (object) patterns, so your requirement
> > could be written as:-
> >
> > when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
> > property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.
> >
> > This would become:-
> >
> > rule "Rule 1"
> > when
> >   Test( $y : y )
> >   Test( x == ($y + 1) )
> >
>
> Actually, please correct me if I am mistaken, but is this condition
> correct? I believe that the original question is that for a single
> instance of class Test t, fire the rule when t.x == t.y + 1 (where 't'
> refers to the *same* instance of class Test). I believe the rule above
> would match any instance of class Test whose x value is equal to the
> value of the instance field y from *any* instance of class Test plus 1.
> Does that make sense?
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread mashup

Thanks Chris, that does work. 

oh man, I tried something so similar to that with the parenethisis last
night using my "programming by trial and error" methodology.

many thanks to everyone who replied, it's all been a great help!

Richard


Chris Woodrow wrote:
> 
> Hi,
> even
> Test (y == (x + 1))
> works.
> 
> Richard : I think you should take a look at this before planning doing
> complicated calculations with drools
> http://lists.jboss.org/pipermail/rules-users/2008-April/005247.html but it
> might be fixed now.
> 
> Chris
> 
> 
> 2008/5/2 Raffi Khatchadourian <[EMAIL PROTECTED]>:
> 
>> On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:
>>
>> > The "when" section matches fact (object) patterns, so your requirement
>> > could be written as:-
>> >
>> > when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
>> > property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.
>> >
>> > This would become:-
>> >
>> > rule "Rule 1"
>> > when
>> >   Test( $y : y )
>> >   Test( x == ($y + 1) )
>> >
>>
>> Could you combine these conditions? As in:
>>
>> when
>>Test($y : y, x == $y + 1)
>> //...
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> 
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/newbie-question-on-%22when%22-condition-syntax-tp17015309p17026473.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread mashup

wow, you guys are good, nice observation Raffi I had not considered that but
this is all making me comprehend how Drools works. Actually I think I need
to switch my brain on! Java is so easy it doesn't tend to require much
thought, now I'm having to think about this stuff it hurts :-)

thanks

Richard


Raffi Khatchadourian wrote:
> 
> On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:
>>The "when" section matches fact (object) patterns, so your requirement
>>could be written as:-
>> 
>>when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
>>property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.
>> 
>>This would become:-
>> 
>>rule "Rule 1"
>>when
>>Test( $y : y )
>>Test( x == ($y + 1) )
> 
> Actually, please correct me if I am mistaken, but is this condition
> correct? I believe that the original question is that for a single
> instance of class Test t, fire the rule when t.x == t.y + 1 (where 't'
> refers to the *same* instance of class Test). I believe the rule above
> would match any instance of class Test whose x value is equal to the
> value of the instance field y from *any* instance of class Test plus 1.
> Does that make sense?
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/newbie-question-on-%22when%22-condition-syntax-tp17015309p17026266.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread Raffi Khatchadourian

On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:

The "when" section matches fact (object) patterns, so your requirement
could be written as:-

when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.

This would become:-

rule "Rule 1"
when
   Test( $y : y )
   Test( x == ($y + 1) )


Actually, please correct me if I am mistaken, but is this condition
correct? I believe that the original question is that for a single
instance of class Test t, fire the rule when t.x == t.y + 1 (where 't'
refers to the *same* instance of class Test). I believe the rule above
would match any instance of class Test whose x value is equal to the
value of the instance field y from *any* instance of class Test plus 1.
Does that make sense?
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread Edson Tirelli
   Yes, newest mvel version works fine, but that problem only happened when
using mvel dialect. For java, just do as Chris mentioned:

when
   Test( y == (x+1) )
then

   And it will work. The () is needed to tell the engine that what is inside
is a semantic code block, i.e., an expression that will return a value to be
compared to y.

   []s
   Edson



2008/5/2 Chris Woodrow <[EMAIL PROTECTED]>:

> Hi,
> even
> Test (y == (x + 1))
> works.
>
> Richard : I think you should take a look at this before planning doing
> complicated calculations with drools
> http://lists.jboss.org/pipermail/rules-users/2008-April/005247.html but it
> might be fixed now.
>
> Chris
>
>
> 2008/5/2 Raffi Khatchadourian <[EMAIL PROTECTED]>:
>
> On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:
> >
> > > The "when" section matches fact (object) patterns, so your requirement
> > > could be written as:-
> > >
> > > when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
> > > property of 'A'" equals "the 'y' property of fact 'B' plus 1"
> > > then.
> > >
> > > This would become:-
> > >
> > > rule "Rule 1"
> > > when
> > >   Test( $y : y )
> > >   Test( x == ($y + 1) )
> > >
> >
> > Could you combine these conditions? As in:
> >
> > when
> >Test($y : y, x == $y + 1)
> > //...
> > ___
> > rules-users mailing list
> > rules-users@lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread Chris Woodrow
Hi,
even
Test (y == (x + 1))
works.

Richard : I think you should take a look at this before planning doing
complicated calculations with drools
http://lists.jboss.org/pipermail/rules-users/2008-April/005247.html but it
might be fixed now.

Chris


2008/5/2 Raffi Khatchadourian <[EMAIL PROTECTED]>:

> On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:
>
> > The "when" section matches fact (object) patterns, so your requirement
> > could be written as:-
> >
> > when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
> > property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.
> >
> > This would become:-
> >
> > rule "Rule 1"
> > when
> >   Test( $y : y )
> >   Test( x == ($y + 1) )
> >
>
> Could you combine these conditions? As in:
>
> when
>Test($y : y, x == $y + 1)
> //...
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread Raffi Khatchadourian

On Fri  2.May'08 at 10:05:20 +0100, Anstis, Michael (M.) wrote:

The "when" section matches fact (object) patterns, so your requirement
could be written as:-

when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.

This would become:-

rule "Rule 1"
when
   Test( $y : y )
   Test( x == ($y + 1) )


Could you combine these conditions? As in:

when
Test($y : y, x == $y + 1)
//...
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread Anstis, Michael (M.)
Hi Richard,
 
Glad I can be of help (this forum as a whole is actually very helpful).
 
Reading your email you understand me correctly (you even picked up on the
implicit AND between pattern matches).
 
With a bit of imagination complex problems can be solved with Drools; just
like programming you need to adjust your mindset sometimes and try a
different tact.
 
Personally, if your rules are not user-facing, I wouldn't worry about DSL -
even if they do don't worry for the time being!
 
Make sure to read the excellent manual, many people have put a lot of work
into this and it is invaluable.
 
Read about "dialect" to answer your question about rule language, to save me
copy and pasting.
 
Good luck,
 
Mike

  _  

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Richard Bremner
Sent: 02 May 2008 11:38
To: Rules Users List
Subject: Re: [rules-users] newbie question on "when" condition syntax


Hi Mike,

Thanks very much, after a few minutes of staring I think I have understood
your very well put answer!

If I understand you right, what is happening is:

Test( $y : y )

This means, WHEN there is an instance of Test, assign the value of its "y"
property to $y

AND

WHEN there is an instance of Test where it's "x" property is equal to $y + 1

THEN fire.


I think I understand that. I am going to need to do this with some pretty
complicated formulae, containing up to 8 different variables. I have a fixed
data set and need to find certain patterns in them based on the formulae. I
have most of the program figured out, my only trouble is expressing my
formulae in the correct syntax. I will try to extend this principle you have
explained to me and hope it can cope with the extra complication... unless
there would be a better way to achieve this?

I am really sorry but I am totally new to drools - but am committed to using
it on a project so I guess I'm going to get to know it pretty well :-)

I read briefly that one can define a DSL, I might look at this eventually to
build an easier mechanism for expressing my formulae - if that can be
achieved using a DSL.

Can the whole rule be defined in Groovy/Java - if so I might be easier doing
that. I have so much work to do!


many thanks

Richard




2008/5/2 Anstis, Michael (M.) <[EMAIL PROTECTED]>:


Hi Richard,
 
The "when" section matches fact (object) patterns, so your requirement could
be written as:-
 
when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.
 
This would become:-
 
rule "Rule 1"
when
Test( $y : y )
Test( x == ($y + 1) )
then
System.out.println("Rule 1 matches");
end
  
By default both patterns can match the same object, so test data:-
 
A : x = 1, y = 1
B : x = 2, y = 1
 
Will cause the rule to activate twice:-
 
A and B
B and B
 
With kind regards,
 
Mike



  _  

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Richard Bremner
Sent: 02 May 2008 08:53
To: rules-users@lists.jboss.org
Subject: [rules-users] newbie question on "when" condition syntax


Hi, 

say I have a class with two fields, x and y: 

public class Test { 
int x = 1; 
int y = 2; 

getters/setters... 
} 


I would like a rule which fires when y = x + 1 

my initial thought would be something like: 

rule "Rule 1" 

when 
test : Test (y == x + 1) 
then 
System.out.println("Rule 1 matches."); 

end 


but this is invalid syntax and I can not find any examples of such a rule.
I'm doing my best but reading the manual etc. I'm struggling with the syntax
here and can't figure it out.

any help really appreciated! 


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users






smime.p7s
Description: S/MIME cryptographic signature
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread Richard Bremner
Hi Mike,

Thanks very much, after a few minutes of staring I think I have understood
your very well put answer!

If I understand you right, what is happening is:

Test( $y : y )

This means, WHEN there is an instance of Test, assign the value of its "y"
property to $y

AND

WHEN there is an instance of Test where it's "x" property is equal to $y + 1

THEN fire.


I think I understand that. I am going to need to do this with some pretty
complicated formulae, containing up to 8 different variables. I have a fixed
data set and need to find certain patterns in them based on the formulae. I
have most of the program figured out, my only trouble is expressing my
formulae in the correct syntax. I will try to extend this principle you have
explained to me and hope it can cope with the extra complication... unless
there would be a better way to achieve this?

I am really sorry but I am totally new to drools - but am committed to using
it on a project so I guess I'm going to get to know it pretty well :-)

I read briefly that one can define a DSL, I might look at this eventually to
build an easier mechanism for expressing my formulae - if that can be
achieved using a DSL.

Can the whole rule be defined in Groovy/Java - if so I might be easier doing
that. I have so much work to do!


many thanks

Richard



2008/5/2 Anstis, Michael (M.) <[EMAIL PROTECTED]>:

>  Hi Richard,
>
> The "when" section matches fact (object) patterns, so your requirement
> could be written as:-
>
> when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
> property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.
>
> This would become:-
>
> rule "Rule 1"
> when
> Test( $y : y )
> Test( x == ($y + 1) )
> then
> System.out.println("Rule 1 matches");
> end
>
> By default both patterns can match the same object, so test data:-
>
> A : x = 1, y = 1
> B : x = 2, y = 1
>
> Will cause the rule to activate twice:-
>
> A and B
> B and B
>
> With kind regards,
>
> Mike
>
>  --
> *From:* [EMAIL PROTECTED] [mailto:
> [EMAIL PROTECTED] *On Behalf Of *Richard Bremner
> *Sent:* 02 May 2008 08:53
> *To:* rules-users@lists.jboss.org
> *Subject:* [rules-users] newbie question on "when" condition syntax
>
> Hi,
>
> say I have a class with two fields, x and y:
>
> public class Test {
> int x = 1;
> int y = 2;
>
> getters/setters...
> }
>
>
> I would like a rule which fires when y = x + 1
>
> my initial thought would be something like:
>
> rule "Rule 1"
>
> when
> test : Test (y == x + 1)
> then
> System.out.println("Rule 1 matches.");
>
> end
>
>
> but this is invalid syntax and I can not find any examples of such a rule.
> I'm doing my best but reading the manual etc. I'm struggling with the syntax
> here and can't figure it out.
>
> any help really appreciated!
>
>
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] newbie question on "when" condition syntax

2008-05-02 Thread Anstis, Michael (M.)
Hi Richard,
 
The "when" section matches fact (object) patterns, so your requirement could
be written as:-
 
when there is a Test Fact 'A' and another Test Fact 'B' where "the 'x'
property of 'A'" equals "the 'y' property of fact 'B' plus 1" then.
 
This would become:-
 
rule "Rule 1"
when
Test( $y : y )
Test( x == ($y + 1) )
then
System.out.println("Rule 1 matches");
end
  
By default both patterns can match the same object, so test data:-
 
A : x = 1, y = 1
B : x = 2, y = 1
 
Will cause the rule to activate twice:-
 
A and B
B and B
 
With kind regards,
 
Mike



  _  

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Richard Bremner
Sent: 02 May 2008 08:53
To: rules-users@lists.jboss.org
Subject: [rules-users] newbie question on "when" condition syntax


Hi, 

say I have a class with two fields, x and y: 

public class Test { 
int x = 1; 
int y = 2; 

getters/setters... 
} 


I would like a rule which fires when y = x + 1 

my initial thought would be something like: 

rule "Rule 1" 

when 
test : Test (y == x + 1) 
then 
System.out.println("Rule 1 matches."); 

end 


but this is invalid syntax and I can not find any examples of such a rule.
I'm doing my best but reading the manual etc. I'm struggling with the syntax
here and can't figure it out.

any help really appreciated! 



smime.p7s
Description: S/MIME cryptographic signature
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users