Hi Wolfgang,

I do not know if i can use the issue tracker to post this as an issue, as i don't know if i'm allowed to do so, and also if this is officially, really a bug or the expected behaviour :) .

However i left a complete piece of code showing the behaviour i'm getting :

RuleTester.java

package org.drools.test;

import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.RuleBaseConfiguration;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;

public class RuleTester {
           
    private static final int MAX_EVENTS = 5;
   
    public class Foo { }           

    public void test() {   

        KnowledgeBaseConfiguration config =   KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        ((RuleBaseConfiguration)config).setRuleBaseUpdateHandler( null );
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
               
        StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
               
        for (int i=0; i<MAX_EVENTS; i++) {
            session.insert(new Foo());
        }
       
        for (int i=1; i<3; i++) {           
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
            kbuilder.add( ResourceFactory.newClassPathResource( "test"+i+".drl" ), ResourceType.DRL);
           
            if( kbuilder.hasErrors() ) {
                System.out.println( kbuilder.getErrors() );
                return;
            }
           
            kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
           
            int fireCount = session.fireAllRules();
           
            System.out.println("Test"+i+".drl , number of rules fired = "+fireCount);           
           
        }
       
        session.dispose();   
       
    }   
   
    public static void main(String[] args) {
        RuleTester tester = new RuleTester();
        tester.test();
    }
       
}


test1.drl

import org.drools.test.RuleTester.Foo;

rule "notNotRule"
    when       
        exists ( Foo() );       
    then     
        System.out.println("Rule fired...");     
end

test2.drl

import org.drools.test.RuleTester.Foo;

rule "notNotRule"
    when       
        not ( not ( Foo() ) );       
    then     
        System.out.println("Rule fired...");     
end


Using Drools 5.0.1-Final , the expected output would be :

> Test1.drl , number of rules fired = 0
> Rule fired...
> Test2.drl , number of rules fired = 1

If someone allows me to open this a a JIRA i would try to understand how to use it :D and would do so.

Regards,
Manuel.


2009/7/13 Wolfgang Laun <wolfgang.laun@gmail.com>
Quite right, since not(not(Foo())) is equivalent to exists(Foo()).

Martin, would you please submit a JIRA?

-W


On 7/13/09, Chivotario Martin <chivotario@gmail.com> wrote:
> Hi Visu,
>
> My understanding (also tested) is that activations are created no matter the
> knowledge base has the rule packages loaded
> before or after the working memory is filled with facts, but the execution
> of the rules happens automatically if the working memory is filled in
> advance.Setting the RuleBaseUpdateHandler to null, prevents the execution of
> the rules but keeps activations to be created when adding a rule to the
> kbase.
> In this case, it seems the exists CE only creates activations if the rules
> are loaded before the working memory is populated.
> But this doesn't happen if i change the statement :
>
>   exists ( Foo() ) --> not ( not ( Foo() ) )
>
> In this case, activations are created no matter whether the kbase is empty
> or not before populating the WM.
>
>
>
>
> 2009/7/13 Viswanathan Nageswaran <visu.nageswaran@in.ibm.com>
>
> > Chivotario,
> >
> > >From what I understand, the activation of rules happen as facts are
> > inserted into the working memory; hence it is important for the session to
> > be begun against a knowledge base that has the rule packages loaded before
> > the facts are inserted.
> >
> > -Visu
> >
> >
> >
> >
> >             Chivotario Martin
> >             <chivotario@gmail
> >             .com>                                                      To
> >             Sent by:                  rules-users@lists.jboss.org
> >             rules-users-bounc                                          cc
> >             es@lists.jboss.or
> >             g                                                     Subject
> >                                       [rules-users] "Exists" CE behaviour
> >
> >             13/07/2009 14:11
> >
> >
> >             Please respond to
> >             Rules Users List
> >             <rules-users@list
> >               s.jboss.org>
> >
> >
> >
> >
> >
> >
> >
> > Hi ,
> >
> > I'm trying to use the Exists keyword within my rules with the following
> > snippet :
> >
> > // Create a session
> > KnowledgeBaseConfiguration config =
> >
> KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
> >
> ((RuleBaseConfiguration)config).setRuleBaseUpdateHandler(
> null ); *
> > KnowledgeBase kbase =
> KnowledgeBaseFactory.newKnowledgeBase(config);
> > StatefulKnowledgeSession session =
> kbase.newStatefulKnowledgeSession();
> >
> > // Add some objects
> > for (int i=0; i<5; i++) {
> > }
> >
> >
> > // Add a DRL to the kbase
> > KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
> > kbuilder.add( ResourceFactory.newClassPathResource(
> "test/existsTest.drl"
> > ), ResourceType.DRL);
> > kbase.addKnowledgePackages(
> kbuilder.getKnowledgePackages() );
> >
> > // Fire rules
> > int fireCount = session.fireAllRules();
> >
> >
> > existsTest.drl :
> >
> > rule "existsTest"
> > ( Foo() ) ); (2)
> >
> > end
> >
> > When launched , the rule is not fired (no messages , fireCount 0), but it
> > is when changing
> > exists with a double not condition (2).
> > If the working memory is populated after adding the rules file, the exists
> > CE works as expected.
> > * I've used no RuleBaseUpdateHandler preventing automatic activations to
> be
> > executed so fireAllRules can be used to get the fireCount, but commenting
> > this line out doesn't change the results.
> >
> > Probably i'm doing something wrong so a little help would be very
> > appreciated.
> >
> > Regards,
> > Manuel.
> > _______________________________________________
> > 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
> >
>
>
> _______________________________________________
> 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