[rules-users] Beginner looking for help with some Drools/Rule concepts

Kabe kabriel at robichaux.com
Thu Jan 11 10:53:01 EST 2007


Thanks Michael. Sure if i assert the Engine of each Car i can create a rule
to return every running Engine, but if my object model does not link an
Engine to a Car (which most OO models would not have double links from Car
<-> Engine as the Engine should not be aware of the Car that encapsulates
it) then i have found an Engine but no Car, and my requirement is to get a
list of all running Cars.

So what i've come to so far is that a rule system working memory is a very
specific model for rules, and it is hard/impossible/notpractical to try and
use an existing object model of a system, and apply rules to it (which i
originally thought i could do). Is that correct? Facts within the working
memory only seem to work if they are flat, in that you evaluate them and
their field values directly, and not a deeper level of traversal like their
contained or referenced object's fields, etc. If you want a structured model
then you need to make sure links between the flat facts can give you the
references you need, such that Car and Engine will both need references to
each other, which is not something you would normally do.

Thanks for the reply.

....
Kabe


On 1/11/07, Michael Neale <michael.neale at gmail.com> wrote:
>
> If you assert engine as a seperate fact, you can then access the engine
> directly.
>
> In the next version, you will be able to do
> Car(engine.running == true) and it will be converted to a predicate
> (sugar) - but always less efficient in RETE terms then accessing a field
> directly on a fact.
>
> On 1/11/07, Kabe <kabriel at gmail.com> wrote:
>
> > Hi, i've been attempting to use Drools/JBossRules (3.0.5) in a project
> > i'm working on and i've run into a few issues that i could use some help
> > with. For the most part i'm struggling with design patterns on how to
> > structure my facts and my programs object model.
> >
> > I'm struggling a bit with how to properly introduce my object model into
> > the working memory. For example, lets say i have an object model such as:
> >
> >    Car(
> >       Engine(
> >          boolean : running
> >       ) : engine,
> >       color,
> >       Door(
> >          boolean : open
> >       )[]:doors
> >    )[] : cars
> >
> > This would model a list of cars and some fields such as engine, color,
> > and doors. Now how would i create a rule that would return every car with a
> > running engine? I can't seem to figure out how to correctly reference a
> > field of a field of a fact. i would want to do something like Car(
> > engine.running == true ) or Car( Engine( running == true ) ) but that
> > doesn't work. I can't make the Engine itself a fact because it has to be a
> > field of the Car, and i can't give the car a field that holds the state of
> > the engine because then that breaks encapsulation and makes the Car class
> > very bloated with the state of all of its many components.
> >
> > Is there a way to do this correctly? i could use a real messy predicate
> > or something like this:
> >
> > $car : Car()
> > eval( isCarRunning( $car ) )
> >
> > But then what is the point of using Rete? doesn't that just equate down
> > to about the same amount of work if i just put this in some standard java
> > if/else code?
> >
> > Thanks for the help,
> >
> > ....
> > Kabe
> >
> >
> >
> > _______________________________________________
> > 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/20070111/d3fdf3a4/attachment.html 


More information about the rules-users mailing list