[rules-users] Can only reason over sub-objects if you use the FromConditional Element

Edson Tirelli tirelli at post.com
Mon Mar 17 13:04:03 EDT 2008


   Can you please open a JIRA with your test case?

   Thanks,
      Edson

2008/3/17, Aaron Dixon <atdixon at gmail.com>:
>
> Hello, Mike,
>
> The behavior is identical whether I update the sub-object or not --
> the "good" rule always works as long as I update the root person
> object AND the "bad" rule will not work even if I explicitly update
> the sub-object as you've suggested.
>
> This leads me to interpret the engine behavior as:
>
> 1) An update() to a root object is enough to communicate to the rules
> engine that the entire object graph has (potentially) changed
> 2) The engine will properly reason over sub-objects only if you use
> the From conditional element (but not if you use MVEL sub-property
> expressions)
>
> So if (1) is the intended behavior of the engine, then my question is
> still this... is (2) a necessary constraint? Shouldn't the engine be
> able to reason over MVEL sub-property expressions without requiring
> the From conditional element? If so, it makes for a more direct syntax
> to allow MVEL sub-property expressions in the LHS, doesn't it?
>
> Thanks in advance for any help on this!
>
>
> Aaron
>
>
>
> On Mon, Mar 17, 2008 at 4:08 AM, Anstis, Michael (M.) <manstis1 at ford.com>
> wrote:
> > IMO, you have not informed the engine\RETE network that details have
> changed
> >  in your first example.
> >
> >  This would probably be a better example:-
> >
> >
> >  rule "30 is the new 20"
> >  when
> >         person : Person( $d : details.age == 30 )
> >
> > then
> >         person.getDetails().setAge(20);
> >         System.out.println( "Now 20 : " + person );
> >         update( person );
> >         update( $d );
> >  end
> >
> >  The From works because it gets external data rather than using that
> already
> >  in the engine\RETE network.
> >
> >  IMO, I think the rules are working correctly; it's just a
> misunderstanding
> >  of how the engine\RETE network function.
> >
> >  I hope this helps.
> >
> >  Thanks,
> >
> >  Mike
> >
> >
> >
> >  -----Original Message-----
> >  From: rules-users-bounces at lists.jboss.org
> >  [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Aaron Dixon
> >  Sent: 14 March 2008 20:51
> >  To: Rules Users List
> >  Subject: [rules-users] Can only reason over sub-objects if you use the
> >  FromConditional Element
> >
> >  It appears that you MUST use the From Condition Element to reason over
> >  sub-objects.
> >
> >  I have a Person class. Person::getDetails() returns a Details
> >  instance, which has the name and age of the person. (This is a
> >  contrived example to demonstrate the issue.)
> >
> >  My rules are:
> >
> >  rule "30 is the new 20"
> >  when
> >         person : Person( details.age == 30 )
> >  then
> >         person.getDetails().setAge(20);
> >         System.out.println( "Now 20 : " + person );
> >         update( person );
> >  end
> >
> >  rule "Older than 20 - Good"
> >  salience -100
> >  when
> >         person : Person( )
> >         Details( age > 20 ) from person.details
> >  then
> >         System.out.println( "Older than 20 (good) : " + person );
> >  end
> >
> >  rule "Older than 20 - Bad"
> >  salience -100
> >  when
> >         person : Person( details.age > 20 )
> >  then
> >         System.out.println( "Older than 20 (bad) : " + person );
> >  end
> >
> >  I assert Abe, Bob, Cat, Don, and Eve with ages of 10, 20, 30, 40, and
> >  50, respectively. The output is as follows.
> >
> >  Now 20 : Person(Details(Cat,20))
> >  Older than 20 (good) : Person(Details(Eve,50))
> >  Older than 20 (bad) : Person(Details(Eve,50))
> >  Older than 20 (good) : Person(Details(Don,40))
> >  Older than 20 (bad) : Person(Details(Don,40))
> >  Older than 20 (bad) : Person(Details(Cat,20))
> >
> >
> >  You can see that the "Bad" rule is more concise but it does not use
> >  the From Conditional Element and therefore it doesn't work properly
> >  (Cat is determined to be older than 20 when she is not.)
> >
> >  Why does Drools allow the "Bad" rule to be written and compiled when
> >  it does not behave properly?
> >
> >  Thanks,
> >  Aaron
> >  _______________________________________________
> >  rules-users mailing list
> >  rules-users at lists.jboss.org
> >  https://lists.jboss.org/mailman/listinfo/rules-users
> >
> > _______________________________________________
> >  rules-users mailing list
> >  rules-users at lists.jboss.org
> >  https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> _______________________________________________
> rules-users mailing list
> rules-users at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080317/3a342f1b/attachment.html 


More information about the rules-users mailing list