Thanks, It looks your example is much clear for "Not join", but

rule "not rule test"
    when

        not Cheese( price == 5 )
    then
                list.add( new Integer( 5 ) );
end

// the code is from
http://anonsvn.labs.jboss.com/trunk/labs/jbossrules/drools-compiler/src/test/resources/org/drools/integrationtests/not_rule_test.drl

the working memory contains more Cheese object, some with price==5,
some without,
in the case, how the Join operating?  as the TestCase below, when
there is the case, the consequence is not executed.

public void testNot() throws Exception {
        PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl( new InputStreamReader(
getClass().getResourceAsStream( "not_rule_test.drl" ) ) );
        Package pkg = builder.getPackage();

        RuleBase ruleBase = getRuleBase();
        ruleBase.addPackage( pkg );
        WorkingMemory workingMemory = ruleBase.newWorkingMemory();

        List list = new ArrayList();
        workingMemory.setGlobal( "list", list );

        Cheese stilton = new Cheese("stilton", 5);
        FactHandle stiltonHandle = workingMemory.assertObject( stilton );
        Cheese cheddar = new Cheese("cheddar", 7);
        FactHandle cheddarHandle = workingMemory.assertObject( cheddar
);
        workingMemory.fireAllRules();

        assertEquals( 0, list.size() );

        workingMemory.retractObject( stiltonHandle );

        workingMemory.fireAllRules();

        assertEquals( 1, list.size() );
    }


2006/3/22, Peter Lin <[EMAIL PROTECTED]>:
>
> strictly speaking, the simple "not cheese ( prince == 5) would get
> translated to an alphaNode that is (price !=5).
>
> Not join is for checking cases where two or more objects are joined and
> the
> entire condition is negated. As in
>
> rule "not example"
>   when
>     object1($blah:blah)
>     object2($blah2:blah2)
>     not ($blah == $blah2)
> then
>     do something
>
> Not exists is different. Not exists means that if a single fact matching
> the
> conditions do not exist. In other words
>
> rule "politician"
>   when
>     not exist politician (honest == true)
>   then
>     incarcerate all politicians
>
> In the not join case, there may be multiple matches that will fire. in the
> Not exist case, it should only fire that rule once.
>
> peter
> On 3/21/06, 王在祥 <[EMAIL PROTECTED]> wrote:
> >
> > How to understand the not expression?
> >
> > rule "not rule test"
> >     when
> >
> >         not Cheese( price == 5 )
> >     then
> >                 list.add( new Integer( 5 ) );
> > end
> >
> >
> > Does it means that for each Cheese(price != 5), then fire the rule, or
> if
> > there not exists Cheese(price == 5) then fire the rule?
> >
> >
> > >
> >
> >
>
>

Reply via email to