Thanks for your all help.
with your help, my rule looks now as:
WHEN $meter:UoM( ) from UoMs.get("length","m")
$2m:Quantity() from Quantities.get(2,$meter)
Person( height < $2m )
My Quantity class implements Comparable interface. When running the rule on
a good dataset (where I expect the rule to fire), the rule fails with no
error. in addition, the compareTo(Object o) method is not called (the
debugger doesn't stop in this method).
Can you please help?
Thanks, David
Greg Barton wrote:
If the Quantity and Duration object already exist in your application, can
they be inserted into working memory automatically? (i.e. their existence
can be assumed when writing the rules.)
Another option is to get them using the from keyword and an external
method that generates objects. (Or optionally gets them from a map if
they've alreay been created.)
rule "foo"
when
$quantity : Quantity() from getQuantity(2, "m");
$Person($height > $quantity.height)
then
...
end
I'm not completely sure that syntax will work as written, but you get the
idea.
And, not to go too far into a philosophy discussion, but the domain expert
should not be writing DRL directly if they're a non-programmer. Actually,
domain experts should not be writing rules at all. That's the job of the
knowledge engineer. There are many complexities to consider when
authoring rules. If a domain expert is stymied by something as simple as
initializing the working memory properly they're going to have a steep
learning curve.
--- On Wed, 2/25/09, David Boaz <davidb(a)dbmotion.com> wrote:
> From: David Boaz <davidb(a)dbmotion.com>
> Subject: Re: [rules-users] Creating objects in WHEN clause
> To: rules-users(a)lists.jboss.org
> Date: Wednesday, February 25, 2009, 1:02 PM
> Thanks,
> These Quantity and Duration objects are commonly used in
> our application. My
> concern is from the software-engineering prespective. Now,
> the rule author
> (which is supposed to be a "domain expert") has
> to maintain the information
> twice: once when inserting these objects to the working
> memory (at the
> initialization), and then when writing the concrete rules.
> Im looking for a trick to make the rule-aurhor life more
> convienient...
>
> Greg Barton wrote:
> >
> > I'd second this idea, and to get around the
> inconcenience of inserting the
> > Quantity objects from the calling application, use a
> rule that fires once
> > on initialization.
> >
> > rule
> > no-loop true
> > when
> > //No condition
> > then
> > insert(new Quantity("m", 2));
> > end
> >
> > This rule should fire first. You could also put it in
> it's own
> > agenda-group (call it "initialization" or
> some such) and set focus to that
> > group when starting.
> >
> > rule
> > agenda-group "initialization"
> > no-loop true
> > when
> > //No condition
> > then
> > insert(new Quantity("m", 2));
> >
> drools.setFocus("whatever_your_next_group_is");
> > end
> >
> > --- On Wed, 2/25/09, Mauricio Salatino
> <salaboy(a)gmail.com> wrote:
> >
> >> From: Mauricio Salatino <salaboy(a)gmail.com>
> >> Subject: Re: [rules-users] Creating objects in
> WHEN clause
> >> To: "Rules Users List"
> <rules-users(a)lists.jboss.org>
> >> Date: Wednesday, February 25, 2009, 11:40 AM
> >> How about :
> >> WHEN
> >> $quantity: Quantity(value == 2, unit ==
> "m")
> >> $Person($height == $quantity:)
> >> then
> >> ...
> >>
> >>
> >>
> >> On Wed, Feb 25, 2009 at 2:27 PM, David Boaz
> >> <davidb(a)dbmotion.com> wrote:
> >> >
> >> > In my application, we often compare the
> fact's
> >> field values against a known
> >> > object. For example:
> >> > WHEN person(height> new Quantity(2,
> "m"))
> >> // the height is greater than 2
> >> > meters.
> >> > will DROOLS create a "singleton"
> Quantity
> >> object, or will it create one
> >> > object for each fact evaluation?
> >> >
> >> > We consider using anoter approach, using
> GLOBALS.
> >> Then, the Quantity object
> >> > will be created applicatively, and passed by
> the API
> >> to the engine.
> >> > something like:
> >> > GLOBAL Quantity 2meters
> >> > WHEN person(height > 2meters)
> >> > But this approach is combersom, because the
> rule
> >> author has to define part
> >> > of the information in the calling
> application, and
> >> part in the rule.
> >> >
> >> > Do you have a good practice how to handle
> these
> >> situations?
> >> >
> >> > Thanks, David
> >> > --
> >> > View this message in context:
> >>
>
http://www.nabble.com/Creating-objects-in-WHEN-clause-tp22207616p22207616...
> >> > Sent from the drools - user mailing list
> archive at
> >>
Nabble.com.
> >> >
> >> >
> _______________________________________________
> >> > rules-users mailing list
> >> > rules-users(a)lists.jboss.org
> >> >
>
https://lists.jboss.org/mailman/listinfo/rules-users
> >> >
> >>
> >>
> >>
> >> --
> >> - Salatino Mauricio -
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users(a)lists.jboss.org
> >>
>
https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> >
https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context:
>
http://www.nabble.com/Creating-objects-in-WHEN-clause-tp22207616p22209417...
> Sent from the drools - user mailing list archive at
>
Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users