[rules-users] Simple rulebase not behaving as expected

Dean Jones dean.m.jones at gmail.com
Wed Aug 22 16:24:34 EDT 2007


Hi Edson,

Thanks for the response. I was just writing a quick test as we have a
problem with some rules which contain negated rule columns (probably
just a local issue) and what you see are the simplest tests I could
write to check the behaviour of negated rule columns.

Thanks again,

Dean.

On 8/22/07, Edson Tirelli <tirelli at post.com> wrote:
>
>    Well, I'm not sure why are you constraining your rule using the class
> Object. What is happening is that the engine always inserts a fact into the
> engine known as InitialFact, that as all objects in java, is a subclass of
> Object, and that is why the rule fires.
>    If instead of Object, you use a different class, like Integer for
> instance, to constrain your rule, you will get the behavior you are looking
> for.
>
>    []s
>    Edson
>
> 2007/8/22, Dean Jones < dean.m.jones at gmail.com>:
> >
> > Hi,
> >
> > I have the following simple rulebase:
> >
> > package org.drools.examples
> > rule "Hello World"
> >         when
> >             o : Object( )
> >         then
> >             System.out.println("Hello world (o=" + o + ")");
> > end
> > rule "Goodbye World"
> >         when
> >             not Object( )
> >         then
> >             System.out.println("Goodbye cruel world");
> > end
> >
> > and the following code:
> >
> > public class TestReadRuleFile {
> >
> > public static void main(String[] args) throws Exception {
> >   PackageBuilder builder = new PackageBuilder();
> >   builder.addPackageFromDrl(
> >     new InputStreamReader(
> >         TestReadRuleFile.class.getResourceAsStream
> ("test.drl")));
> >   Package pkg = builder.getPackage();
> >   RuleBase rulebase = RuleBaseFactory.newRuleBase();
> >   rulebase.addPackage(pkg);
> >   StatefulSession session = rulebase.newStatefulSession();
> >    session.fireAllRules();
> > }
> >
> > }
> >
> > which produces the following output:
> >
> > Hello world
> (o=org.drools.reteoo.InitialFactImpl at 4dde85f0)
> >
> > I expected the "Goodbye World" rule to fire, as there should not be
> > any Objects in the working memory. If I change my code to insert an
> > object into the working memory as follows:
> >
> >   session.insert(new Object());
> >
> > I now get the following output:
> >
> > Hello world (o=org.drools.reteoo.InitialFactImpl at 4dde85f0
> )
> > Hello world (o=java.lang.Object at 17ba38f)
> >
> > In this case, I expected the "Hello World" rule to fire only once. Any
> > thoughts on what I'm doing wrong here?
> >
> > Thanks,
> >
> > Dean.
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
>
>
> --
>   Edson Tirelli
>   Software Engineer - JBoss Rules Core Developer
>   Office: +55 11 3529-6000
>   Mobile: +55 11 9287-5646
>   JBoss, a division of Red Hat @ www.jboss.com
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>



More information about the rules-users mailing list