[rules-users] Insert new facts in WorkingMemory event handler

Wolfgang Laun wolfgang.laun at gmail.com
Mon Dec 6 07:36:27 EST 2010


The initially posted rules "1" and "2" are best practice. You are using a
Production Rule Engine, and these rules are what they are made for.

Doing it in an event handler is not impossible, but it requires you to
implement logic which is (apparently) part of the application domain
("There must not be a T without at least one I." and "There must not be an I
without its T.") and, moreover, logic which is readily available by the
Engine's
workings.

Don't reinvent the wheel, just start rolling along.

-W


On 6 December 2010 13:25, Gabor Szokoli <szocske at gmail.com> wrote:

> I think I've got your use case: you are making XSLT on steroi^W some
> kind of cheese that tastes stimulating and is dense in nutrients but
> is in no way controversial.
> It would allow user rules for removing stuff, and have built-in rules
> for transitively removing unreferenced stuff, right?
>
> On Mon, Dec 6, 2010 at 12:19 PM, Bruno Freudensprung
> <bruno.freudensprung at temis.com> wrote:
> > I simply plan to read my XML and add the corresponding objects into
> > the session, then to fire the rules.
>
> Ahh, silly me, rule processing is externally initiated in Drools, it's
> not some kind of perpetual event engine.
>
> > Well... I wanted to delegate the whole "logic" to Drools and I imagined
> > that I could "listen" to Drools' WorkingMemory's retraction events in
> > order to remove the corresponding elements from the input XML.
>
> Would a query work instead of the event listener then?
> I guess it would if the list of remaining stuff is good too...
> Or you could mark the unneeded stuff instead of retracting, reason
> over the marks, and be able to query the marked stuff directly:
>
> rule "orphaned Type"
> when
>       t : T(mark != true)
>       not I(type == t, mark == true)
> then
>       modify (t) {setMark(true)}
> end
>
> rule "orphaned Instance"
> when
>       t : T(mark == true)
>       I(type == t, mark != true)
>
> then
>       modify(i) {setMark(true)}
> end
>
> // transform your rules "1" and "2" as well to sanitize input!
>
> query "types to delete"
>       t : T(mark == true)
> end
>
> query "instances to delete"
>       i : I(mark == true)
> end
> _______________________________________________
> 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/20101206/fd0e2842/attachment.html 


More information about the rules-users mailing list