On 08/06/2012, bdolbeare <bdolbe...@yahoo.com> wrote:
> Can someone explain to me why these two rules behave differently?  I
> expected
> that the second rule would produce the same output as the first but it
> seems
> to ignore the first half of the logical or expression.  Is this because the
> unification happens before the null checks occur?
>

It's a simple case of the "sorprise" ( sic ;-) ).

A rule containing the Conditional Element "or" is transformed into two
(or more, depending on the number of operands) rules running under the
same name. See the Expert manual.

-W

>
>
> declare Foo
>       name : String
>       item : Item
> end
> declare Item
>       id : long
> end
>
> rule "insert stuff"
>       when
>       then
>               Item item1 = new Item(1);
>               
>               Foo foo1 = new Foo("foo1", item1);
>               insert(foo1);
>               
>               Foo foo3 = new Foo("foo3", null);
>               insert(foo3);
> end
> rule "Unification Test Rule"
>       when
>               f : Foo ( item != null, $item := item )         
>               f2 : (
>                       Foo ( item == null )
>                       or Foo ( $item := item )
>                       )
>       then
>               System.out.println(String.format("%s Fired:\n\tFoo: %s\n\t%s",
> kcontext.getRule().getName(), f, f2));
> end
> rule "Unification Test Rule 2"
> salience -10
>       when
>               f : Foo ( item != null, $item := item )         
>               f2 : Foo ( ( item == null ) || ( item != null && $item := item 
> ) )
>       then
>               System.out.println(String.format("%s Fired:\n\tFoo: %s\n\t%s",
> kcontext.getRule().getName(), f, f2));
> end
>
>
> Unification Test Rule Fired:
>       Foo: Foo( name=foo1, item=Item( id=1 ) )
>       Foo( name=foo3, item=null )
> Unification Test Rule Fired:
>       Foo: Foo( name=foo1, item=Item( id=1 ) )
>       Foo( name=foo1, item=Item( id=1 ) )
>
> Unification Test Rule 2 Fired:
>       Foo: Foo( name=foo1, item=Item( id=1 ) )
>       Foo( name=foo1, item=Item( id=1 ) )
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Unification-with-logical-or-question-tp4017826.html
> Sent from the Drools: User forum 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

Reply via email to