[rules-dev] Perhaps an undocumented feature of Backward Chaining?

Mark Proctor mproctor at codehaus.org
Fri Jun 24 16:14:30 EDT 2011


On 23/06/2011 13:20, Wolfgang Laun wrote:
> Still not resolved...
>
I have added a test for all the possible insertion orders for that 
particular use case and was not able to reproduce a problem:
https://github.com/droolsjbpm/drools/commit/501f2196dcef754eed5a28b066b50665a5bc29a3

MArk
> On 22 June 2011 21:40, Mark Proctor <mproctor at codehaus.org 
> <mailto:mproctor at codehaus.org>> wrote:
>
>     heh, I made a mistake with the rule
>     ( Location(z, y;) and ?hasFood(x, z;) )
>     should be
>     ( Location(z, y;) and hasFood(x, z;) )
>
>     Otherwise it's not reactive, and then ordering matters.
>
>     With that change I can do the insertions in any order and all is fine.
>
>
> This works for the example you gave. But the one taken from the 
> "Introduction" still depends on the order the facts are inserted. 
> Below is the .drl, which does not need any pojos. Rule kickOff 
> contains the order that produces nothing to see and eat:
> You are in the table
>   You can see []
>   You can eat []
>
> Insert Here after the others, and it works.
>
> -W
>
>  import java.util.List
>
> declare Thing
>     thing : String @key
> end
>
> declare Edible extends Thing
> end
>
> declare Location extends Thing
>     location : String  @key
> end
>
> declare Here
>     place : String
> end
>
> rule kickOff
> when
> then
>     System.out.println( "insert Here" );
>     insert( new Here( "table" ) );
>     System.out.println( "insert Edible" );
>     insert( new Edible( "peach" ) );
>     System.out.println( "insert Location" );
>     insert( new Location( "peach", "table" ) );
> end
>
> # 2011-06-22
> query isContainedIn( String x, String y )
>     Location(x, y;)
>     or
>     ( Location(z, y;) and /*?*/isContainedIn(x, z;) )
> end
>
> query whereFood( String x, String y )
>     ( Location(x, y;) and
>     Edible(x;) )
>     or
>     ( Location(z, y;) and /*?*/whereFood(x, z;) )
> end
>
> query look(String place, List things, List food)
>     Here(place;)
>     things := List() from accumulate( Location(thing, place;),
>                                       collectList( thing ) )
>     food := List() from accumulate( /*?*/whereFood(thing, place;),
>                                     collectList( thing ) )
> end
>
> rule reactiveLook
> when
>     Here( $place : place)
>     /*?*/look($place, $things; $food := food)
> then
>     System.out.println( "You are in the " + $place);
>     System.out.println( "  You can see " + $things );
>     System.out.println( "  You can eat " + $food );
> end
>
>
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20110624/ebd842e7/attachment.html 


More information about the rules-dev mailing list