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