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

Socrates Frangis soc.frangis at gmail.com
Sun Aug 22 21:05:22 EDT 2010


I apologize, should have chosen my words better...

Drools does have 'logical assertion' in the sense that a fact will be
inserted and automatically retracted when it's conditions are no longer
true.

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 if you created your own POJO 'flag' that stores a string and a boolean,
then you could store to the string "fire-my-special-rule" and set the
boolean to TRUE. In your Drool DRL rule, check to see if the flag pojo has
it's string value as "fire-my-special-rule" and boolean "true".

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 (which would have
answered the original question in an easier / less hacked manner than my
Flag POJO suggestion)


2010/8/22 Salaboy <salaboy at gmail.com>

> Drools have logicalInsert, what do you mean with: drools doesn't have this?
> It behaves differently than Jess and clips?
>
> - CTO @ <http://www.plugtree.com>http://www.plugtree.com
> - MyJourney @ <http://salaboy.wordpress.com>http://salaboy.wordpress.com
> - Co-Founder @ <http://www.jbug.com.ar>http://www.jbug.com.ar
> - Mauricio "Salaboy" Salatino -
>
> On 21/08/2010, at 23:53, Socrates Frangis <soc.frangis at gmail.com> wrote:
>
> Keep in mind that rules are declarative, it is against the nature of a rule
> based expert system to force a rule to fire; youre kind of treating the rule
> like a function.
>
> My best advice is....
> !
> 1)Create a POJO called "Flag", store a String and Boolean inside of it.
>
> 2)On the RHS of the first rule, create the POJO and set the string to
> something like "rule-03-fired" and set the boolean to 'true'
>
> 3)In the rule you want to fire, add a pattern to check for a Flag Fact
> Template with String value 'rule-03-fired' and 'true'
>
> Note, this is normally done in CLIPS/JESS as logical assertions, but Drools
> does not have this. However, i'm sure it's implemented the same on the back
> end.
>
> 2010/8/21 Michael Anstis < <michael.anstis at gmail.com>
> michael.anstis at gmail.com>
>
>> Look at the API; the overloaded method you use will only fire 2 rules.
>>
>> You probably need fireAllRules();
>>
>> 2010/8/20 Sanjib Karmakar < <sanjibk at skytechsolutions.co.in>
>> sanjibk at skytechsolutions.co.in>
>>
>>>
>>> Sir
>>>
>>> Thank you very much for your reply.
>>> In fact what I wanted to execute the specific rule out of say 10 rules.
>>>
>>> I have tried
>>> ksession.fireAllRules(2);
>>> Then only first 2 rules get executed.
>>>
>>> Please let me know if there is any way-out to call specific rules out of
>>> bunch of rules.
>>> It would be extremely helpful if you please share a code snippet
>>> regarding this.
>>>
>>> Regards
>>> Sanjib Karmakar
>>> SkyTech Solutions Pvt. Ltd
>>>
>>> Please consider the environment before printing this email.
>>>
>>>
>>>  *"Wolfgang Laun-2 [via Drools - Java Rules Engine]" <[hidden email]<http://user/SendEmail.jtp?type=node&node=1238924&i=0>
>>> >*
>>>
>>> 08/19/2010 07:45 PM
>>>   To
>>> Sanjib Karmakar <[hidden email]<http://user/SendEmail.jtp?type=node&node=1238924&i=1>
>>> >
>>> cc
>>>   Subject
>>> Re: How Can a Drools Rule call another Drools Rule?
>>>
>>>
>>>
>>>
>>> Rules are never "called". Changes in WM create (and also delete)
>>> "activations": tuples consisting of a rule and the fact objects
>>> matching the left hand side patterns. From this set of activations,
>>> rule right hand sides are executed according to salience (and other
>>> criteria).
>>>
>>> Perhaps if you describe the actual problem...?
>>>
>>> -W
>>>
>>>
>>> On 19 August 2010 06:58, Sanjib Karmakar <*[hidden email]*<http://user/SendEmail.jtp?type=node&node=1225490&i=0&by-user=t>>
>>> wrote:
>>>
>>> >
>>> > Hi friends
>>> >
>>> > I would like to execute a rule say Rule-1 from inside another rule say
>>> > Rule-2.
>>> > In project I am using xml and not drl, and I am using Drools 5.0
>>> >
>>> > Please let me know how to call a rule from another rule.
>>> >
>>> > Thanks
>>> > Sanjib
>>> > --
>>> > View this message in context: *
>>> http://drools-java-rules-engine.46999.n3.nabble.com/How-Can-a-Drools-Rule-call-another-Drools-Rule-tp1219190p1219190.html
>>> *<http://drools-java-rules-engine.46999.n3.nabble.com/How-Can-a-Drools-Rule-call-another-Drools-Rule-tp1219190p1219190.html?by-user=t&by-user=t>
>>> > Sent from the Drools - User mailing list archive at Nabble.com.
>>> > _______________________________________________
>>> > rules-users mailing list
>>> > *[hidden email]*<http://user/SendEmail.jtp?type=node&node=1225490&i=1&by-user=t>
>>> > *https://lists.jboss.org/mailman/listinfo/rules-users*<https://lists.jboss.org/mailman/listinfo/rules-users>
>>> >
>>> _______________________________________________
>>> rules-users mailing list *
>>> **[hidden email]*<http://user/SendEmail.jtp?type=node&node=1225490&i=2&by-user=t>
>>> *
>>> **https://lists.jboss.org/mailman/listinfo/rules-users*<https://lists.jboss.org/mailman/listinfo/rules-users>
>>>  ------------------------------
>>>
>>> View message @ *
>>> http://drools-java-rules-engine.46999.n3.nabble.com/How-Can-a-Drools-Rule-call-another-Drools-Rule-tp1219190p1225490.html
>>> *<http://drools-java-rules-engine.46999.n3.nabble.com/How-Can-a-Drools-Rule-call-another-Drools-Rule-tp1219190p1225490.html?by-user=t>
>>> To unsubscribe from How Can a Drools Rule call another Drools Rule?, *click
>>> here*<http://drools-java-rules-engine.46999.n3.nabble.com/template/NodeServlet.jtp?tpl=unsubscribe_by_code&node=1219190&code=c2Fuamlia0Bza3l0ZWNoc29sdXRpb25zLmNvLmlufDEyMTkxOTB8MTQzMDExODQ0MA==&by-user=t>.
>>>
>>>
>>> ------------------------------
>>> View this message in context: Re: How Can a Drools Rule call another
>>> Drools Rule?<http://drools-java-rules-engine.46999.n3.nabble.com/How-Can-a-Drools-Rule-call-another-Drools-Rule-tp1219190p1238924.html>
>>> Sent from the Drools - User mailing list archive<http://drools-java-rules-engine.46999.n3.nabble.com/Drools-User-f47000.html>at
>>> Nabble.com.
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>>  <rules-users at lists.jboss.org>rules-users at lists.jboss.org
>>>  <https://lists.jboss.org/mailman/listinfo/rules-users>
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>>  <rules-users at lists.jboss.org>rules-users at lists.jboss.org
>>  <https://lists.jboss.org/mailman/listinfo/rules-users>
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100822/23b38fcb/attachment.html 


More information about the rules-users mailing list