Re: [rules-users] Fetching values of an object's attribute set by different rules

2008-08-12 Thread psentosa

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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] Fetching values of an object's attribute set bydifferent rules

2008-08-12 Thread psentosa

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 ListWashRuleValueHolder  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: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of psentosa
 Sent: 12 August 2008 09:45
 To: rules-users@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@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 ___
 rules-users mailing list
 rules-users@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.


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

2008-08-12 Thread Anstis, Michael (M.)
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: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of psentosa
Sent: 12 August 2008 11:26
To: rules-users@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 ListWashRuleValueHolder  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: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of psentosa
 Sent: 12 August 2008 09:45
 To: rules-users@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:


Re: [rules-users] Composition of Fact Templates

2008-08-12 Thread Edson Tirelli
   In other words, in 5.0 you can do:

declare Address
   line1 : String
   line2 : String
end

declare Person
  name : String
  age : int
  address : Address
end

   There are additional notation and features you are able to use when
working with type declarations, but the above is what you asked for.

   []s
   Edson


2008/8/11 Mark Proctor [EMAIL PROTECTED]

 FactTemplates are an experimental feature and only supports primitives and
 strings as fields. It was based around using arrays for the models, this
 made the implementation easy but tooling and integration with other
 libraries being very hard. For 5.0 we using type declarations which
 basically are generated pojos, which causes a nightmare for custom
 classloader stuff, but is much more tooling and 3rd party library
 integration friendly. These type declarations support primitives and classes
 for their fields.

 Mark

 Stephen Kestle wrote:

 I'm trying to make some fact templates in the form of

 template Address
   String line1
   String line2
 end

 template Person
   String name
   int age
   Address address
 end

 It complains that it is Unable to resolve class Address

  1. Is there any way around this - am I just getting syntax wrong?
  2. Is this being fixed in 5.0 or  4.0.7 (which I have)
  3. Am I able to modify the class loader to grab the FactTemplate
 class types and infer the correct object? e.g. is this something
 that's ridiculously hard, and so hasn't already been included?
  4. Am I going about this entirely the wrong way?
1. Are nested types at all useful in the rules?
2. Is it possible to even have a rule like:
   p: Person( age == 5, Address(line1 == My address))
   ? (given a java object schema)
3. Should I be using variables and other rules to assert facts?
4. Off topic: Is rules composition achieved by the assertion of
   facts for other rules to use?

 What I want to do:
 I am dealing with (xml) schemas and ontologies, and need to be able to
 create Fact Templates from these definitions.  While I can do this easily
 enough in java side, I believe I need to create the templates to match my
 java objects so that the rules can be compiled.

 Thanks heaps

 Stephen
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




-- 
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat @ www.jboss.com
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] or not working

2008-08-12 Thread Yu Wang
The either method is clever, and it works! Thank you so much, Edson.


On 8/8/08, Edson Tirelli [EMAIL PROTECTED] wrote:

   You must escape ( ...

 [condition][]\(=(

   But I'm not sure it will work, because expansion is doing nothing... I
 mean, text before and after expansion is the same and the system was
 designed to check for changes...
   Do you need to have ( alone in a line? Can't you use a more textual
 representation for ( or? Like:

 rule XYX
 when
 Either
  Condition_1
  Condition_2
 End_Either
  then
 Action_1
 end

So you can map Either to ( or and End_either or whatever word you chose
 to )?

Just trying to find alternate ways.


   Edson

 2008/8/8 Yu Wang [EMAIL PROTECTED]
  This doesn't work.  :(
 
  Acutally I am using the eclipse plugin and the DSL viewer shows that
  the source code looks fine. The code I put in my first email was taken
  from the DSL viewer.
 
  but when I add the three lines:
  [condition][](=(
  [condition][])=)
  [condition][]or=or
 
  The DSL viewer refuses to work and shows the following msg:
  DSL Rule Translation Error!
  Reason:
  java.util.regex.PatternSyntaxException: Unclosed group
 near index 13
  (\W|^)((\W|$)
 
  I think it means ( in the last word.
  I also tried (=(, and '(', didn't work either.
  So I can't add the three mappings this way. Any ideas? Thanks!
 
 
 
 
 
 
 
  On 8/8/08, Yu Wang [EMAIL PROTECTED] wrote:
   Thanks for your reply. Yes, I am using a DSL. So what you mean is I
   need to add 3 mappings in DSL like the following:
   ( mapped to (
   ) mapped to )
   or mapped to or
   right? I'll try that.
   Thanks a lot!
  
   On 8/8/08, Edson Tirelli [EMAIL PROTECTED] wrote:
   
   The error message indicates you are using DSL and the problem is
 not in
the DRL, but in DSL.
   DSL requires every single line to be matches (or expanded), so if
 you
have a line with a single ( and nothing more, either you have a
 mapping for
it, or you escape the line with .
   
   Best way to fix your problem is to use the drools eclipse plugin
 for
.dslr files, and using the DRL preview feature.
   
   []s
   Edson
   
2008/8/8 Yu Wang [EMAIL PROTECTED]

 Hi, I need help in making the or work. I have the following rule:


 rule
 when
 (
 or
 Condition_clause_1
 Condition_clause_2
 )
 then
Consequence_clause_1
 end

 -

 It gives me the following compilation error:

 org.drools.rule.InvalidRulePackage: [4] Unable to
 expand:
(  [5]
 Unable to expand: or[8] Unable to expand: )

 Seems it doesn't recognize (, or, and ). But I totally follow
 the documentation on section 6.5.2.3 of version 4.0.7.


 Any help is highly appreciated.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org

 https://lists.jboss.org/mailman/listinfo/rules-users

   
   
   
--
Edson Tirelli
JBoss Drools Core Development
JBoss, a division of Red Hat @ www.jboss.com
   
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
   
   
  
  ___
  rules-users mailing list
  rules-users@lists.jboss.org
  https://lists.jboss.org/mailman/listinfo/rules-users
 



 --
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Fetching values of an object's attribute set bydifferent rules

2008-08-12 Thread Kris Nuttycombe
StatelessSession.executeWithResults() was what I had in mind when I
suggested obtaining the newly asserted facts from the working memory
using a query. In my application, I assert a new fact accumulator when
appropriate from within the rules themselves, and then have a simple
query that looks like this:

query findAccumulator
result : Accumulator()
end

Then I use something like this to get my accumulator back:

StatelessSessionResult results = session.executeWithResults(new Object[] {...});
QueryResults queryResults = results.getQueryResults(findAccumulator);
Accumulator acc = (Accumulator) QueryResults.get(0).get(result);

Kris

On Tue, Aug 12, 2008 at 3:42 AM, Anstis, Michael (M.) [EMAIL PROTECTED] 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 ListWashRuleValueHolder  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: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of psentosa
 Sent: 12 August 2008 09:45
 To: rules-users@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@lists.jboss.org
 

[rules-users] Max packages

2008-08-12 Thread Joe White
Can someone help me understand the relationship between the number of
Packages in a single RuleBase and PermGen memory consumption? I have a
test that generates  200 rules and then adds those rules as different
packages to a single rule base. PermGen consumption grows near linearly
with the addition of Packages to the rule base and on a default PermGen
setting the JVM runs out of PermGen after about 120 packages.

 

Is every new Package and RuleBase backed by a set of generated Classes?
Is there a way to get around the amount of class generation that is
taking place?

The test has been run against Drools 5.

 

Thank you for your help,

Joe

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users