[rules-users] How Can a Drools Rule call another Drools Rule?

Wolfgang Laun wolfgang.laun at gmail.com
Mon Aug 23 02:01:11 EDT 2010


Some remarks to put things right, see below.

2010/8/23 Socrates Frangis <soc.frangis at gmail.com>

>
> I meant it in the sense of in JESS/CLIPS you can assert an non-structured
> template to trigger another rule (as in this message board question where
> the issue was how to cause a rule to fire when another rule fires)
>
> JESS/CLIPS Example:
> (deftemplate fire-my-special-rule) //Notice no structure of the template,
> its just an object called 'fire-my-special-rule'
>
> (defrule initial-rule
>    (blah...blah...patterns which make the first rule fire)
>     =>
>    (do some RHS actions)
>    (assert (fire-my-special-rule))
> )
>
> (defrule special-rule
>    (fire-my-special-rule) //here im just checking for the existance or
> truth of 'fire-my-special-rule'
>   =>
>     (RHS ACTIONS)
> )
>
> What i was getting at was, in JESS/CLIPS you can achieve what this question
> was asking by creating a deftemplate in the rule file that has no structure
> and use it to trigger another rule. In Drools you can not do this exactly,
>

But you *can* do this in Drools, using
   declare fireMySpecialRule
       x : int
   end
in a .drl file to declare the trigger class, or you could even one of the
classes from Java, String or Integer or whatever.


> Sorry, going on tangent, but yes i misspoke when i said Drools did not have
> Logical Assertions, it does. It just doesn't allow you to assert an
> unstructured template as does other rule engines do
>

Since Jess' "ordered template" implies a field for its data, there's not
much difference here. Drools simply uses Java objects throughout, while Jess
has its (legacy) deftemplates which have to be linked to POJOs with the
"shadow fact" mechanism.


> (which would have answered the original question in an easier / less hacked
> manner than my Flag POJO suggestion)
>
>
But I don't think that setting up a LHS with a single trigger pattern as you
do in the rule  "special-rule" and to insert a matching trigger fact just to
execute a few statements in the RHS of that rule is what the original poster
meant by "firing a rule". That would be utterly pointless and contrived.
Executing some statements is better done by defining a function and calling
it, both in Drools and Jess.

-W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100823/5c807644/attachment.html 


More information about the rules-users mailing list