Hi Wolfgang,<br><br>I do not know if i can use the issue tracker to post this as an issue, as i don&#39;t know if i&#39;m allowed to do so, and also if this is officially, really a bug or the expected behaviour :) .<br><br>
However i left a complete piece of code showing the behaviour i&#39;m getting : <br><br><b><u>RuleTester.java</u></b><br><br>package org.drools.test;<br><br>import org.drools.KnowledgeBase;<br>import org.drools.KnowledgeBaseConfiguration;<br>
import org.drools.KnowledgeBaseFactory;<br>import org.drools.RuleBaseConfiguration;<br>import org.drools.builder.KnowledgeBuilder;<br>import org.drools.builder.KnowledgeBuilderFactory;<br>import org.drools.builder.ResourceType;<br>
import org.drools.io.ResourceFactory;<br>import org.drools.runtime.StatefulKnowledgeSession;<br><br>public class RuleTester {<br>            <br>    private static final int MAX_EVENTS = 5;<br>    <br>    public class Foo { }            <br>
<br>    public void test() {    <br><br>        KnowledgeBaseConfiguration config =   KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>        ((RuleBaseConfiguration)config).setRuleBaseUpdateHandler( null );<br>        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);<br>
                <br>        StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();<br>                <br>        for (int i=0; i&lt;MAX_EVENTS; i++) {<br>            session.insert(new Foo());<br>        }<br>
        <br>        for (int i=1; i&lt;3; i++) {            <br>            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br>            kbuilder.add( ResourceFactory.newClassPathResource( &quot;test&quot;+i+&quot;.drl&quot; ), ResourceType.DRL);<br>
            <br>            if( kbuilder.hasErrors() ) {<br>                System.out.println( kbuilder.getErrors() );<br>                return;<br>            }<br>            <br>            kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );<br>
            <br>            int fireCount = session.fireAllRules();<br>            <br>            System.out.println(&quot;Test&quot;+i+&quot;.drl , number of rules fired = &quot;+fireCount);            <br>            <br>
        }<br>        <br>        session.dispose();    <br>        <br>    }    <br>    <br>    public static void main(String[] args) {<br>        RuleTester tester = new RuleTester();<br>        tester.test();<br>    }<br>
        <br>}<br><br><br><b><u>test1.drl</u></b><br><br>import org.drools.test.RuleTester.Foo;<br><br>rule &quot;notNotRule&quot;<br>    when        <br>        exists ( Foo() );        <br>    then     <br>        System.out.println(&quot;Rule fired...&quot;);      <br>
end<br><br><b><u>test2.drl</u></b><br><br>import org.drools.test.RuleTester.Foo;<br><br>rule &quot;notNotRule&quot;<br>    when        <br>        not ( not ( Foo() ) );        <br>    then     <br>        System.out.println(&quot;Rule fired...&quot;);      <br>
end<br><br><br>Using Drools 5.0.1-Final , the expected output would be :<br><br>&gt; Test1.drl , number of rules fired = 0<br>&gt; Rule fired...<br>&gt; Test2.drl , number of rules fired = 1<br><br>If someone allows me to open this a a JIRA i would try to understand how to use it :D and would do so.<br>
<br>Regards,<br>Manuel.<br><br><br><div class="gmail_quote">2009/7/13 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Quite right, since not(not(Foo())) is equivalent to exists(Foo()).<br>
<br>
Martin, would you please submit a JIRA?<br>
<font color="#888888"><br>
-W<br>
</font><div><div></div><div class="h5"><br>
<br>
On 7/13/09, Chivotario Martin &lt;<a href="mailto:chivotario@gmail.com">chivotario@gmail.com</a>&gt; wrote:<br>
&gt; Hi Visu,<br>
&gt;<br>
&gt; My understanding (also tested) is that activations are created no matter the<br>
&gt; knowledge base has the rule packages loaded<br>
&gt; before or after the working memory is filled with facts, but the execution<br>
&gt; of the rules happens automatically if the working memory is filled in<br>
&gt; advance.Setting the RuleBaseUpdateHandler to null, prevents the execution of<br>
&gt; the rules but keeps activations to be created when adding a rule to the<br>
&gt; kbase.<br>
&gt; In this case, it seems the exists CE only creates activations if the rules<br>
&gt; are loaded before the working memory is populated.<br>
&gt; But this doesn&#39;t happen if i change the statement :<br>
&gt;<br>
&gt;   exists ( Foo() ) --&gt; not ( not ( Foo() ) )<br>
&gt;<br>
&gt; In this case, activations are created no matter whether the kbase is empty<br>
&gt; or not before populating the WM.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; 2009/7/13 Viswanathan Nageswaran &lt;<a href="mailto:visu.nageswaran@in.ibm.com">visu.nageswaran@in.ibm.com</a>&gt;<br>
&gt;<br>
&gt; &gt; Chivotario,<br>
&gt; &gt;<br>
&gt; &gt; &gt;From what I understand, the activation of rules happen as facts are<br>
&gt; &gt; inserted into the working memory; hence it is important for the session to<br>
&gt; &gt; be begun against a knowledge base that has the rule packages loaded before<br>
&gt; &gt; the facts are inserted.<br>
&gt; &gt;<br>
&gt; &gt; -Visu<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;             Chivotario Martin<br>
&gt; &gt;             &lt;chivotario@gmail<br>
&gt; &gt;             .com&gt;                                                      To<br>
&gt; &gt;             Sent by:                  <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; &gt;             rules-users-bounc                                          cc<br>
&gt; &gt;             es@lists.jboss.or<br>
&gt; &gt;             g                                                     Subject<br>
&gt; &gt;                                       [rules-users] &quot;Exists&quot; CE behaviour<br>
&gt; &gt;<br>
&gt; &gt;             13/07/2009 14:11<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;             Please respond to<br>
&gt; &gt;             Rules Users List<br>
&gt; &gt;             &lt;rules-users@list<br>
&gt; &gt;               <a href="http://s.jboss.org" target="_blank">s.jboss.org</a>&gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Hi ,<br>
&gt; &gt;<br>
&gt; &gt; I&#39;m trying to use the Exists keyword within my rules with the following<br>
&gt; &gt; snippet :<br>
&gt; &gt;<br>
&gt; &gt; // Create a session<br>
&gt; &gt; KnowledgeBaseConfiguration config =<br>
&gt; &gt;<br>
&gt; KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
&gt; &gt;<br>
&gt; ((RuleBaseConfiguration)config).setRuleBaseUpdateHandler(<br>
&gt; null ); *<br>
&gt; &gt; KnowledgeBase kbase =<br>
&gt; KnowledgeBaseFactory.newKnowledgeBase(config);<br>
&gt; &gt; StatefulKnowledgeSession session =<br>
&gt; kbase.newStatefulKnowledgeSession();<br>
&gt; &gt;<br>
&gt; &gt; // Add some objects<br>
&gt; &gt; for (int i=0; i&lt;5; i++) {<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; // Add a DRL to the kbase<br>
&gt; &gt; KnowledgeBuilder kbuilder =<br>
&gt; KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
&gt; &gt; kbuilder.add( ResourceFactory.newClassPathResource(<br>
&gt; &quot;test/existsTest.drl&quot;<br>
&gt; &gt; ), ResourceType.DRL);<br>
&gt; &gt; kbase.addKnowledgePackages(<br>
&gt; kbuilder.getKnowledgePackages() );<br>
&gt; &gt;<br>
&gt; &gt; // Fire rules<br>
&gt; &gt; int fireCount = session.fireAllRules();<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; existsTest.drl :<br>
&gt; &gt;<br>
&gt; &gt; rule &quot;existsTest&quot;<br>
&gt; &gt; ( Foo() ) ); (2)<br>
&gt; &gt;<br>
&gt; &gt; end<br>
&gt; &gt;<br>
&gt; &gt; When launched , the rule is not fired (no messages , fireCount 0), but it<br>
&gt; &gt; is when changing<br>
&gt; &gt; exists with a double not condition (2).<br>
&gt; &gt; If the working memory is populated after adding the rules file, the exists<br>
&gt; &gt; CE works as expected.<br>
&gt; &gt; * I&#39;ve used no RuleBaseUpdateHandler preventing automatic activations to<br>
&gt; be<br>
&gt; &gt; executed so fireAllRules can be used to get the fireCount, but commenting<br>
&gt; &gt; this line out doesn&#39;t change the results.<br>
&gt; &gt;<br>
&gt; &gt; Probably i&#39;m doing something wrong so a little help would be very<br>
&gt; &gt; appreciated.<br>
&gt; &gt;<br>
&gt; &gt; Regards,<br>
&gt; &gt; Manuel.<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; rules-users mailing list<br>
&gt; &gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; rules-users mailing list<br>
&gt; &gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>