[rules-users] Collect all occurrences of resulting data.

Wolfgang Laun wolfgang.laun at gmail.com
Mon Apr 21 13:45:05 EDT 2014


Just an additional hint: it's possible to switch between agenda groups
(sorry for using the wrong term, but I didn't confuse you, did I?) from
within rules as well.

-W

On 21/04/2014, Ephemeris Lappis <ephemeris.lappis at gmail.com> wrote:
> Hello again.
>
> It seems clear that too many salience levels would make it all worse !
>
> My ruleset executes over a simple list of initial facts, and proceeds
> more or less as you say in three phases :
>
> 1) Analise initial facts using several deduced facts to make
> intermediary conclusions implemented as locally declared types.
>
> 2) Consolidate the scattered produced facts to build seven main business
> rules : here is where I need to gather all the facts into a unique
> collection. Depending on each of the seven rules, the result may use a
> simple input fact, or, at the opposite, different collections of
> temporary facts...
>
> 3) At the end, for each input fact, generate a global decision using the
> seven rules, and output it into a global map.
>
> For that, I think that it may be rather reasonable [:)] setting 3
> salience levels representing the three main steps of the rule system.
>
> I have had a look to the activation groups, but I don't think it could
> match this current need. Moreover this would be more intrusive since
> such a way the Java code should knows the layered structure of the
> rules. At this time the application code just puts the initial facts and
> extract the resulting map to produce a JSON like object to be written
> into a Mongo base...
>
> Thanks a lot for your help. Any new advice is welcome !
>
> Best regards.
>
> Ephemeris Lappis
>
> Le 21/04/2014 17:48, laune [via Drools] a écrit :
>> I recommend at most 3 levels of salience, and only if you have a
>> very limited scenario of insert / fire.
>>
>> Alternatively, you can use agenda groups.
>>
>> If I understand you correctly, you have some rules that execute
>> "Before" and others that should execute "After". In your .drl,
>>
>> activation-group "Before"
>> rule ... when ... then ... end ... rule ... when ... then ... end
>> activation-group "After"
>> rule ... when ... then ... end ... rule ... when ... then ... end
>>
>> You can set (the group "Before" before you insert facts, call
>> fireAllRules, set "After" and fire again; then start over again. - See
>> the Expert manual for some more about activation groups.
>>
>> Setting the agenda group from Java takes a little digging in the API doc:
>>    session.getAgenda().getAgendaGroup( "Before" ).setFocus();
>>
>> -W
>>
>>
>>
>> On 21/04/2014, Ephemeris Lappis <[hidden email]
>> </user/SendEmail.jtp?type=node&node=4029304&i=0>> wrote:
>>
>> > Hello.
>> >
>> > Thanks for this advice.
>> >
>> > I've tried it with a small test case, and it actually works fine : the
>> > collecting rule seems to be fired at the end.
>> >
>> > Nonetheless, I'm not confident at all with salience, since in my real
>> > use case I have many rules before and after that, and I worry that
>> > salience might move the problem elsewhere, and values must be set to
>> all
>> > of them to ensure they're all executed according to the expected order.
>> >
>> > At this moment, the rules before the collecting rule also produce facts
>> > that are expected by the rules that follow it, and, I suppose, it's for
>> > that reason that all the ending part of the job is executed after the
>> > correct collection of the intermediary results.
>> >
>> > Another alternative ?
>> >
>> > Thanks again.
>> >
>> > Regards
>> >
>> >
>> >
>> > Ephemeris Lappis
>> >
>> > Le 21/04/2014 13:11, laune [via Drools] a écrit :
>> >> This is one of the (rare) cases where I'd advocate salience.
>> >>
>> >> rule "Collect results when complete"
>> >> salience -999999
>> >>     when
>> >>                 $all : List from collect(Result())
>> >>     then
>> >>             ...do something with $all...
>> >> end
>> >>
>> >> -W
>> >>
>> >>
>> >> On 21/04/2014, Ephemeris Lappis <[hidden email]
>> >> </user/SendEmail.jtp?type=node&node=4029298&i=0>> wrote:
>> >>
>> >> > Hello.
>> >> >
>> >> > I'm looking for the better way to write a rule that collects data
>> >> only when
>> >> > they have been all processed.
>> >> >
>> >> > For example, two input objects classes as facts : *Data* and
>> >> *Category*.
>> >> >
>> >> > I declare a local type to memorize the result of the evaluation for
>> >> each
>> >> > pair of fact.
>> >> >
>> >> >
>> >> >
>> >> > Some rule evaluates the Cartesian product of all *Data* by all
>> >> *Category* :
>> >> >
>> >> >
>> >> >
>> >> > Now I want to collect all the results, but only when the previous
>> >> rule has
>> >> > been fired for all the data.
>> >> > Something like :
>> >> >
>> >> >
>> >> >
>> >> > Any advice ?
>> >> >
>> >> > Thanks in advance for your help.
>> >> >
>> >> > Regards.
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > View this message in context:
>> >> >
>> >>
>> http://drools.46999.n3.nabble.com/Collect-all-occurrences-of-resulting-data-tp4029296.html
>> >> > Sent from the Drools: User forum mailing list archive at Nabble.com.
>> >> > _______________________________________________
>> >> > rules-users mailing list
>> >> > [hidden email] </user/SendEmail.jtp?type=node&node=4029298&i=1>
>> >> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >> >
>> >> _______________________________________________
>> >> rules-users mailing list
>> >> [hidden email] </user/SendEmail.jtp?type=node&node=4029298&i=2>
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >>
>> >>
>> >>
>> ------------------------------------------------------------------------
>> >> If you reply to this email, your message will be added to the
>> >> discussion below:
>> >>
>> http://drools.46999.n3.nabble.com/Collect-all-occurrences-of-resulting-data-tp4029296p4029298.html
>> >>
>> >>
>> >> To unsubscribe from Collect all occurrences of resulting data., click
>> >> here
>> >> <
>> >> NAML
>> >>
>> <http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>>
>> >>
>> >>
>> >
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> >
>> http://drools.46999.n3.nabble.com/Collect-all-occurrences-of-resulting-data-tp4029296p4029300.html
>> > Sent from the Drools: User forum mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> rules-users mailing list
>> [hidden email] </user/SendEmail.jtp?type=node&node=4029304&i=1>
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>> ------------------------------------------------------------------------
>> If you reply to this email, your message will be added to the
>> discussion below:
>> http://drools.46999.n3.nabble.com/Collect-all-occurrences-of-resulting-data-tp4029296p4029304.html
>>
>>
>> To unsubscribe from Collect all occurrences of resulting data., click
>> here
>> <http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4029296&code=ZXBoZW1lcmlzLmxhcHBpc0BnbWFpbC5jb218NDAyOTI5Nnw0OTQyMjM2NDI=>.
>> NAML
>> <http://drools.46999.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>>
>
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Collect-all-occurrences-of-resulting-data-tp4029296p4029307.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list