[rules-users] looking for more information on drools expert

Edson Tirelli tirelli at post.com
Fri Jul 10 15:21:22 EDT 2009


   Hi Aldian,

   I think you misunderstood the semantics of forall(). Forall in Drools is
the same forall quantifier from the First Order Logic.

http://en.wikipedia.org/wiki/First-order_logic

   So, if you want to write a rule that says: "When for all equipments of
type 'router' there is an alarm, then raise a general failure alarm".

when
    forall( $e : Equipment( type == "router" )
             Alarm( source == $e ) )
then
    // raise a general failure alarm
end

    So, if you have 10 routers in the working memory and only 9 of them have
associated alarms, this rule will NOT fire, because the condition is not
matched. But, if an alarm is raised for the 10th router, then all of them
have an associated alarm and the rule will fire.

    So, as you can see, "forall" is a quantifier CE, in the same way that
"not" and "exists" are quantifiers. They operate on multiple facts at once,
and as so, you can not use the variables bound inside their scope outside of
it. In the above example, if you tried to use $e in the consequence, which
of the 10 routers would it be bound to? So, since it makes no sense, the
engine disallow the usage of variables bound inside quantifiers outside of
them.

    Just to be easier to remember I call quantifier CEs "scope delimiters".
The general rule is: variables bound inside a scope delimiter are never
available outside of them.

    I don't understand what you are trying to do in your first rule in your
example. If you write your rule in plain English, the people from the list
can help you write it correctly.

    Finally, just for completeness, be careful with the semantics of time.
Your Alarm class is using the system clock to define timeout, and that will
give you all kinds of headaches, not to mention wrong/unexpected results.
But this e-mail is already too long. I suggest you take a look at the Drools
Fusion docs on temporal reasoning.

    []s
    Edson


2009/7/10 Gab Aldian <aldian.gp at gmail.com>

> Hi everybody
>
> I have read with attention the drools expert documentation, which was
> very interesting, but a little 'too simple". For example, most
> examples don't present rules with the keyword "forall". I also met big
> difficulties mixing the references on the objects to my javacode. This
> is why I would need some more documentation with examples that go
> deeper into drools capacities.
>
>
> To give you clues about my plan, here is an example (which works
> perfectly in drools 5) that I have developed:
> java code - http://drools.pastebin.com/m1a705614
> rule code - http://drools.pastebin.com/m3f30cbdc
>
> As you can see I am studying the case where drools is used for the
> monitoring of a network of equipments that send alarms about their
> problems. But I have big difficulties, because I would like to get
> references on the objects of the "forall", and to execute javacode
> such as $toto.method($titi, $tata), but such things seems impossible
> (systematic failed of compilation)
>
> Could you please help me?
>
> Thank you very much!
>
> Aldian
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090710/8e5f19c8/attachment.html 


More information about the rules-users mailing list