[rules-users] Fetching values of an object's attribute setbydifferent rules

Anstis, Michael (M.) manstis1 at ford.com
Tue Aug 12 07:36:03 EDT 2008


Globals don't pass down the RETE network and so Drools won't try to pass
them down the network (although if the Class you insert is not used in
any LHS patterns it will probably be filtered out at the top of the
network by a ObjectTypeNode) so they might offer (insignificantly)
faster performance. Also to insert a fact and retrieve later it'd be a
good idea to hang onto the FactHandle... Not much in it (I think), just
personal preference.

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of psentosa
Sent: 12 August 2008 11:26
To: rules-users at lists.jboss.org
Subject: RE: [rules-users] Fetching values of an object's attribute
setbydifferent rules


yup, that's what I'm planing to use now.
Now that you mentioned it, is there any advantage of using the list as
global over using it by just inserting it normally (session.insert)?
Again, really appreciate your answers a lot!Thanks

Paul



Anstis, Michael (M.) wrote:
> 
> OK, so here is my take on things:-
> 
> +--------------+   +----------------+   +-------------------+
> |              |   |                |   |                   |
> | Sub-system 1 |-->| Sub-system 2   |-->| Sub-system 3 uses |
> | sets up data |   | Rules \ Drools |   | results from sub- |
> +--------------+   |                |   | system 2          |
>                    +----------------+   +-------------------+
> 
> 
> I would be inclined to have List<WashRuleValueHolder > as a global in
WM
> and append instances of WashRuleValueHolder to the list in RHS of
rules
> (or a Map or something so you can retrieve what you want easily). Also
> have you looked at StatelessSession.executeWithResults() - which I
> haven't personally used but would give you what (I think) you need (if
> stateless is acceptable too!).
> 
> Cheers,
> 
> Mike
> 
> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org
> [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of psentosa
> Sent: 12 August 2008 09:45
> To: rules-users at lists.jboss.org
> Subject: Re: [rules-users] Fetching values of an object's attribute
set
> bydifferent rules
> 
> 
> Thank you Mike and Kris for the answer.
> So I'll give it a try again to explain :)
> 
> The rules I described have information that I need to go further with
my
> application,
> i.e. with the wash example, when rule A fires, it'll give information
> about
> the washing instruction regarding the temperature and detergent.
> Now, let's say, I have another block of codes apart from this RE-part,
> which
> needs those information (.e.g a WashMachine Object). These info should
> only
> be defined within the rules. So my question before was, how can I pass
> those
> to my washMachine?
> That's why idea was to insert a new/empty value holder, set the value
to
> the
> holder when the rule fire, and I can use the value holder (which
already
> contains value/has info from the fired rules).
> I'm not sure if using such a ValueHolder is the best way to fetch some
> values set within the rules.
> I hope this is clearer now, and any idea would be great!
> Thanks in advance
> 
> Paul 
> 
> 
> 
> 
> 
> psentosa wrote:
>> 
>> Hi, 
>> 
>> I have the following problems:
>> I need to prove an object based on certain rules, where the parts of
> the
>> rules should be kept to be used in further process within my
> application.
>> In order to fetch those parts, my idea was to insert an additional
> object
>> as value holder for the rule's parts,
>> put values on them when the corresponding rule is fired, so that
later
> on
>> I can process those value holder after my appl gets the control back
> from
>> Ruleengine.
>> 
>> 
>> The example below:
>> 
>> Shirt shirt = new Shirt(...)
>> WashRuleValueHolder holder = new WashRuleValueHolder();
>> 
>> session.insert(shirt);
>> session.insert(holder);
>> ......
>> 
>> session.dispose()
>> 
>> System.out.println(holder.getTemperature());
>> System.out.println(holder.getDetergent());
>> =======================
>> 
>> rule A
>> when
>>       Shirt (dirtinessLevel == high)
>>       $holder : WashRuleValueHolder()
>> then
>>       System.out.println ("this cloth should be washed in 60 degree
> water
>> with 1 spoon of detergent")
>>      $holder.temperature = 60;
>>      $holder.detergent = 1;
>> 
>> rule B
>> when
>>      Shirt(material == satin)
>>      $holder : WashRuleValueHolder()
>> then
>>        System.out.println ("this cloth should be washed in 30 degree
> water
>> with 0,5 spoon of detergent")
>>      $holder.temperature = 30;
>>      $holder.detergent = 0,5;
>> 
>> Now, in case both rules evaluate to true, I'd have problem with my
>> valueholder, bcs depending on which one of the rules was fired
latest,
>> that'd be the value I got from the holder, and I need both of them.
>> So, my questions:
>> 
>> - Is using such a value holder a good solution to fetch the rules'
> value?
>> Or is there any better solution?
>> - How to handle this problem of multiple value association to the
> holder,
>> so I still can get all the values without one overwriting the other
> and
>> they are still connected?
>> 
>> Any idea highly appreciated, thanks in advance!
>> 
>> 
>> 
>> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/Fetching-values-of-an-object%27s-attribute-set-by-
> different-rules-tp18922201p18940166.html
> Sent from the drools - user mailing list archive at Nabble.com.
> 
> _______________________________________________
> 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
> 
> 

-- 
View this message in context:
http://www.nabble.com/Fetching-values-of-an-object%27s-attribute-set-by-
different-rules-tp18922201p18941569.html
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




More information about the rules-users mailing list