Subin P | 12 Jun 2006 11:44
Favicon

[drools-user] Drools recommendations.

Hi,

 

I am new to drools and I guess myself to be a little biased to the procedural way of doing things.

I am trying to author some rules for my application and am a bit confused as to :

 

1.)     Is there a problem in making use of salience or other attributes so as to order the execution of rules (for eg: there are some validations that need to be performed in a particular order. )  Are we always guaranteed that the rules will be fired in that order.  Won’t this ordering have a dependency while new rules are added? What are your recommendations ?

 

2.)     Do you recommend a single  .drl file  with all the rules or splitting the rules into multiple drl files.  Are there any performance implications ?

 

3.)  Please comment on the following approach :

Say I have a “Claim” object which has a  collection  of  LaborDetails. I need to make a validation on each of these LaborDetail. My initial instinct was to write a function to iterate through the collection and make the validations. (And I began to wonder what the rule engine was doing :)  ).  My next approach was to have a separate rule for the LaborDetail class and then from one of my previous rules, I iterate the laborDetails collection and assert it in the “then” part of the rule.  This obviously ties the two rules together. Plus, I read somewhere in the Drools manual that it is not advisable to assert objects in the “then” part of a rule that forces the

      Rule engine to invoke yet another rule. Why is that ?  What would you recommend in such a scenario ?

 

      I shall be grateful for any tips on the effective usage of the rule engine (especially tips outside of the manual.) Thanks in advance.

 

 

Thanks,
Subin

 

 

 

Edson Tirelli | 12 Jun 2006 14:40
Favicon

Re: [drools-user] Drools recommendations.

  Hi Subin,

Just a few comments:

1. There is no problem in using salience as an ordering criteria. 
Usually we don't advise to use it because sometimes people abuse it and 
try to do procedural development in the form of rules, what is really 
bad because you force the engine to work in a way that may not be the 
most efficient way. But if you write your rules correctly and make use 
of salience only where it is really needed for semanthic purposes (not 
"programing" purposes), there will be no problem. Regarding the garantee 
of fire-order, you need to understand the concept of agenda: each tuple, 
for each rule, that matches the RHS (right hand side, a.k.a. the "when" 
part) go into the agenda as an activation. Then, the engine uses 
"conflict resolution" strategies to decide wich activation to fire 
first. You can change the conflict resolution if you need to, but the 
default is a composed strategy where the first criteria is salience. So 
the highest salience rules fires first by default.
Usually you don't need to worry about that. Just write your rules with a 
"rule concept" in mind and it shall work just fine.

2. For maintanence purposes, I would say it is always better to split 
the rules in multiple DRL files. There is no "runtime" performance 
implications. I'm not sure if there is "loading" time impacts in 
separating the rules in multiple files, but the recommended approach is 
always to load the rule base once, cache it, and create as many working 
memories as you need to work with it. Working this way, loading time has 
a minimal impact on the whole application performance. Also, the rule 
base is serializable, so you can even load it once, serialize it (to 
disk, JNDI, database, or whatever is best for you), and use the 
serialized version that avoids the "rule compilation" time if your rules 
don't change too often.

3. I would go with the second approach no doubt. Functions are simply 
blocks of code that are like black boxes for the engine. The engine can 
do nothing about them, except execute them. But if you express your 
knowledge as rules, the engine can do its magic. I'm not aware of any 
advice against asserting objects in the LHS of a rule, and in fact, that 
is the way rule engines work. Of course, if your application can assert 
all objects directly, without the need of a rule whose only purpose is 
to assert objects, that is a much better approach, but in case you 
don't, go for the rules.

Hope it helps,

Edson

Subin P wrote:

> Hi,
>
> I am new to drools and I guess myself to be a little biased to the 
> procedural way of doing things.
>
> I am trying to author some rules for my application and am a bit 
> confused as to :
>
> 1.) Is there a problem in making use of salience or other attributes 
> so as to order the execution of rules (for eg: there are some 
> validations that need to be performed in a particular order. ) Are we 
> always guaranteed that the rules will be fired in that order. Won’t 
> this ordering have a dependency while new rules are added? What are 
> your recommendations ?
>
> 2.) Do you recommend a single .drl file with all the rules or 
> splitting the rules into multiple drl files. Are there any performance 
> implications ?
>
> 3.) Please comment on the following approach :
>
> Say I have a “Claim” object which has a collection of LaborDetails. I 
> need to make a validation on each of these LaborDetail. My initial 
> instinct was to write a function to iterate through the collection and 
> make the validations. (And I began to wonder what the rule engine was 
> doing :) ). My next approach was to have a separate rule for the 
> LaborDetail class and then from one of my previous rules, I iterate 
> the laborDetails collection and assert it in the “then” part of the 
> rule. This obviously ties the two rules together. Plus, I read 
> somewhere in the Drools manual that it is not advisable to assert 
> objects in the “then” part of a rule that forces the
>
> Rule engine to invoke yet another rule. Why is that ? What would you 
> recommend in such a scenario ?
>
> I shall be grateful for any tips on the effective usage of the rule 
> engine (especially tips outside of the manual.) Thanks in advance.
>
> Thanks,
> Subin
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Vishal K. Singh | 12 Jun 2006 18:16
Picon

[drools-user] Drools Questions : design inputs reqd?

Hello,

I am new to Drools engine, recently started to learn and use it. I have following questions on it:

a) What should I do if I want to use Derived Class objects to be asserted in the working memory and "when" part of rules to be based on Base Class objects.

I have a situation where I am using Drools for failure diagnosis. So, The failure types are derived from a base class.
Depending on each failure type and conditions, I need to have different consequence/then part. I could not find anywhere the behaviour when base class and derived objects are used. Since, the first instance of matching object type is used, I assumed a derived class object should be good, but I was getting IllegalObjectAccess Exceptions.

Any ideas or pointers?

b)  What happens when my different threads update the workingMemory i.e, assert object and fireAllRules().

The situation is that diagnosis(rule engine trigger)  starts whenthe  failure is detected or reported by user. Now, when a failure is obtained an object representing the failure is asserted and rule engine is fired. This may involve some diagnostic tests etc. While this object is used in rule engine processing if I get another failure, another thread is likely to create another failure object and assert it to same working memory. The problem is the first processing will be affected as the object instance may get changed as both the failure objects are of same type (FailureObject). One alternative is wait for first trigger to get completed but some of failure states and related data may be needed or failure dependencies may be needed in processing of second reported failure. Using a different workingMemory also may not be best as the previous failure becomes a fact for next failure and needs to be present in the workingMemory.

Any good ideas to handle this?  All approaches I think of lead to large inter-mixing of code and rules.

One approach could be not using the FailureObject directly but having an object which has all failureObjects and hence all the facts are in working memory and different threads just add the reference of failureobject to the wrapper object. This is not a very clean usage of rule engine and if anyone is aware of rule engine facilities rather then java facilities, I would really appreciate any pointers on that.

c)  Even with no-loop true, I am seeing sequence gettign repeated. It is not recursion.
When a condition matchers in a rule, and  some consequence is executed. As a result of this consequence a secondary condition is set, which matches in another rule and consequence of it sets the condition of 1st rule which matches again and causes the consequence of first rule  which in turn sets the condition of rule 2. This leads to rule 1 causing rule 2 and rule 2 causing rule 1. Is this normal behaviour or can be prevented.

Rule A  -> causes Rule B --> causes rule A  [infinite loop].

Thanks a lot for your help,
Regards,
Vishal

Andy Gerweck | 13 Jun 2006 01:50
Picon

[drools-user] "Not Matches" Regex?

Is there any way to specify "not matches"? There's no `(?x)`-style 
switch you can put inside the Java regex.

I need something like

    rule
     when
       Email(from matches "me <at> .*", to !matches "you <at> .*)
     then
       doSomething();
    end

I can imagine some ways to do what I need with activation groups, and 
it's easy with an `eval`, but I don't see a *good* way to do what I have 
above.

I may volunteer a patch for this feature if it's not already possible 
and there's no reason to exclude that functionality. We already have 
negations of all the other operators (!=/==, </>=, contains/excludes).

I appreciate any suggestions,
 /Andy Gerweck/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Michael Neale | 13 Jun 2006 05:02
Picon
Gravatar

Re: [drools-user] Minimum requirements

Ask and you shall receive:
I have created a brief document of the different depdendencies.

This will be included as a README file in the lib directory of future binary releases.

You can also get to it on the wiki here:
http://wiki.jboss.org/wiki/Wiki.jsp?page=RulesDependencies



On 6/9/06, Mark Proctor <mproctor <at> codehaus.org> wrote:
Don't forget you're all welcome to help out on docs :)

Michael Neale wrote:
Yes we need to have aome clearer docs on the dependencies - but he source of "truth" are the pom.xml files in each module (of source) - they specify the exact versions and dependencies - so ideally we can harvest from that the list. Manually edited documents can (and will) always get out of sync (and people often ignore "official" documents anyway).

Yes things were a little "fluid" before the release, and betas, but should settle down now. In terms of the plug in, for the forseeable future, it will always be released in sync with the main engine (no mix and match).

On 6/8/06, Sri Sankaran <sri.sankaran <at> sas.com> wrote:
Is there a source of information that tells one what are the minimum
requirements for working with JBoss Rules?  It would be nice to have

* A recommended JBoss Rules version
* Compatible Eclipse plug-in
* Minimum set of jars for using JBoss Rules on an existing project

I have wasted...erm...spent several hours over the last week or so getting
the right combination of things on my local environment to get JBoss rules
working as advertized.  The docs suggested using 3.0 RC2 however, I didn't
have quite the success shown by the webcast.  I had to fuss with building
from source to get a working environment.  Finally, matters seem to have
settled a bit with the release of 3.0 or should I say 3.0.1.

On the matter of minimum requirements, what are the jars that must be
included in a project where I want to use JBoss rules?  It isn't always that
one has the luxury of *starting* with a JBoss Rules project.  What if I have
an existing project and I want to bolt on rules-based implementation for a
segment of the application?  Right now, my approach is to
guess/infer/plagiarize (from the examples).  Maybe the odd behavior I am
seeing is because I don't have all/the right JARs.

Can you shed some light on these issues?

Thanks

Sri




---------------------------------------------------------------------
To unsubscribe from this list please visit:

     http://xircles.codehaus.org/manage_email




Sri Sankaran | 13 Jun 2006 14:40
Picon
Favicon
Gravatar

Re: [drools-user] Minimum requirements

Outstanding!  Thanks.
 
Sri
Ask and you shall receive:
I have created a brief document of the different depdendencies.

This will be included as a README file in the lib directory of future binary releases.

You can also get to it on the wiki here:
http://wiki.jboss.org/wiki/Wiki.jsp?page=RulesDependencies



On 6/9/06, Mark Proctor <mproctor <at> codehaus.org> wrote:
Don't forget you're all welcome to help out on docs :)

Michael Neale wrote:
Yes we need to have aome clearer docs on the dependencies - but he source of "truth" are the pom.xml files in each module (of source) - they specify the exact versions and dependencies - so ideally we can harvest from that the list. Manually edited documents can (and will) always get out of sync (and people often ignore "official" documents anyway).

Yes things were a little "fluid" before the release, and betas, but should settle down now. In terms of the plug in, for the forseeable future, it will always be released in sync with the main engine (no mix and match).

On 6/8/06, Sri Sankaran <sri.sankaran <at> sas.com> wrote:
Is there a source of information that tells one what are the minimum
requirements for working with JBoss Rules?  It would be nice to have

* A recommended JBoss Rules version
* Compatible Eclipse plug-in
* Minimum set of jars for using JBoss Rules on an existing project

I have wasted...erm...spent several hours over the last week or so getting
the right combination of things on my local environment to get JBoss rules
working as advertized.  The docs suggested using 3.0 RC2 however, I didn't
have quite the success shown by the webcast.  I had to fuss with building
from source to get a working environment.  Finally, matters seem to have
settled a bit with the release of 3.0 or should I say 3.0.1.

On the matter of minimum requirements, what are the jars that must be
included in a project where I want to use JBoss rules?  It isn't always that
one has the luxury of *starting* with a JBoss Rules project.  What if I have
an existing project and I want to bolt on rules-based implementation for a
segment of the application?  Right now, my approach is to
guess/infer/plagiarize (from the examples).  Maybe the odd behavior I am
seeing is because I don't have all/the right JARs.

Can you shed some light on these issues?

Thanks

Sri




---------------------------------------------------------------------
To unsubscribe from this list please visit:

     http://xircles.codehaus.org/manage_email




Sri Sankaran | 13 Jun 2006 14:49
Picon
Favicon
Gravatar

[drools-user] Retrofitting a project with JBoss Rules

In response to an earlier post, Mark had indicated that to profit from the 
JBoss Rules Eclipse IDE, one must create a "Rule Project".

Is there a way to retrofit this "rule nature" to an existing project?  I 
have an existing project that has been honed over the months to the 
project's needs (i.e. quite a large classpath, external dependencies etc, 
etc).  I would hate to have to discard all that and have to create a project 
anew.

Actually, the create-a-new-project option would not work for us at all since 
we use Maven's project.xml as the single source of truth for 
dependency-related information using Maven's eclipse plug-in to sync the 
Eclipse project.  As you may know, Maven's eclipse plug-in whacks any 
existing Eclipse project file -- ergo the futility of creating a new "rules 
project".

Thanks

Sri 

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Sri Sankaran | 13 Jun 2006 15:36
Picon
Favicon
Gravatar

[drools-user] ClassCastException

A ClassCastException in my JUnit test has me stumped.  Hope you can help.

The test fails right after a call to fireAllRules -- before I can break at 
an afterActivationFiredEvent with the following error:
etc. etc.

java.lang.ClassCastException

    at 
com.sas.mis.tides.notification.Rule_Deprecation_or_Deletion_0ConsequenceInvoker.evaluate(Rule_Deprecation_or_Deletion_0ConsequenceInvoker.java:22)

    at org.drools.common.DefaultAgenda.fireActivation(Unknown Source)

I don't know what is the file 
"Rule_Deprecation_or_Deletion_0ConsequenceInvoker.java".  It seems to be an 
auto-generated file to handle one of my rules namede "Deprecation or 
Deletion".

Any thoughts? Suggestions?

Sri

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Jean-Pierre Grillon | 13 Jun 2006 15:48
Favicon

[drools-user] Conflict Resolver

Hi,

 

I used to use Drools 2.0. I am now trying JBoss Rules 3.0.1 and I can’t find anymore where I could specify which Conflict Resolvers I want to use.

Could you please help me?

 

Thanks.

 

Best regards,

Jean-Pierre Grillon

 

Capgemini - Finance et Services

Tél : 01 49 00 38 84

 

This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

Sri Sankaran | 14 Jun 2006 05:44
Picon
Favicon
Gravatar

Re: [drools-user] ClassCastException

Well that much I too figured. *Where* is the question.

The generated class was generated by JBoss Rules not me.  I don't have any 
class casts anywhere in sight.

The problem seems to be related to the "or" clause in my rule since the two 
tests in my suite that exercise such a rule both fail with similar 
ClassCastExceptions.  Here's what I am trying to do (paraphrasing my rules 
for mass consumption):

English: If car's make is Honda or Toyota print a message saying "you have a 
Japanese car"
DRL:
rule "Japanese Car"
    when
        car: (Car(make == "Honda") or Car(make == "Toyota"))
    then
        System.out.println("you have a Japanese car")
end

Which, according to example 3.17

(http://labs.jboss.com/file-access/default/members/jbossrules/freezone/docs/3.0.1/html/ch03s05.html#d0e2033) 
is the proper syntax.  BTW, although not used in the aobve example, I *do* 
need the binding.

Any pointers would be appreciated.

Sri

Sri

"Mark Proctor" <mproctor <at> codehaus.org> wrote in message 
news:448F18A6.9050409 <at> codehaus.org...
> Yes its a generated class where you have written a wrong cast.
>
> Mark
> Sri Sankaran wrote:
>> A ClassCastException in my JUnit test has me stumped.  Hope you can help.
>>
>> The test fails right after a call to fireAllRules -- before I can break 
>> at an afterActivationFiredEvent with the following error:
>> etc. etc.
>>
>> java.lang.ClassCastException
>>
>>     at 
>> com.sas.mis.tides.notification.Rule_Deprecation_or_Deletion_0ConsequenceInvoker.evaluate(Rule_Deprecation_or_Deletion_0ConsequenceInvoker.java:22)
>>
>>     at org.drools.common.DefaultAgenda.fireActivation(Unknown Source)
>>
>>
>>
>> I don't know what is the file 
>> "Rule_Deprecation_or_Deletion_0ConsequenceInvoker.java".  It seems to be 
>> an auto-generated file to handle one of my rules namede "Deprecation or 
>> Deletion".
>>
>> Any thoughts? Suggestions?
>>
>> Sri
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
> 

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Gmane