I only spent a day reading about Drools. The rules I presented looks simple but the idea was to know if the only solution is to extract all the required data and pass to the rules engine. Or the rules can be written in such a way that is can get the required data from the raw data.

 

Your and Wolfgang example shows that rules can be written over raw data as well as rules can talk to database. I will go through the documentation to grasp the power of drools.

 

Thanks

Bhushan

 

-----Original Message-----
From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Tuesday, May 19, 2009 8:48 PM
To: Rules Users List
Subject: Re: [rules-users] can drools support complex rules

 


     Your question is funny. First you ask if Drools is capable of managing complex rules and then you mention examples of extremely simple rules? :)

     Drools is FOL complete and so can represent any well formed First Order Logic expression. Anyway, I will use this message to advertise some of the temporal reasoning features that we have on Drools 5 for the benefit of anyone interested.
   
     There are several ways of authoring such rules, depending on how you model your problem domain. One possible way of doing them is:

#1:
rule "
If a customer login within 5 minutes from two different locations, mark the user invalid."
when
     $l1 : CustomerLogin( )
     $l2 : CustomerLogin( userId == l1.$id, location != $l1.id, timestamp after[0s, 5m] $l1.timestamp )
then
     // mark user as invalid
end

In the previous example I assumed both login objects would be in working memory, but you can easily query for the previous login in an external datasource, pulling the data from the previous login on-demand for the reasoning cycle.

#2:
rule "If the customer location is not on a list of valid locations, mark the user invalid"
when
      $l : CustomerLogin( location not memberOf $validLocations )
then
      // mark the user invalid
end
 
In the above rule, I assume the valid locations list is a global list, but you can as easily model locations as being facts on your working memory or a service end point that you can call to validate the location.

#3:
rule “Customer login from more than 5 locations in the last one month”
when
    $customer : Customer( $id : id )
    $locations : Set( size > 5 ) from accumulate(
                     CustomerLogin( customerId == $id, $loc : location ) over window:time( 30d ),
                     collectSet( $loc ) )
then
    // do something as the customer logged in from more than 5 locations in the last 30 days
end

In the previous rule I decided to use sliding windows, just to show how that feature can be used to simplify rules, but again, there are several ways of doing it.

I strongly recommend you read Drools manual.

http://www.jboss.org/drools/documentation.html

Cheers,
Edson


2009/5/19 Bhushan Bhangale <bhushan_bhangale@kaleconsultants.com>

Hi,

 

I recently came across Drools. I gone through the documentation and the examples provide are quite simple. I want to know if it can be really applied to complex real world problems.

 

Take for example,

 

If a customer login within 5 minutes from two different locations, mark the user invalid.

How can I write the above rule in drools? I have the data when the user last logged in and the data of current login. You can say two objects.

 

May be my understanding is wrong but looks like based on rule I have to pass all the required data. How can then at real time new rules can be added?

 

For example,

 

If the customer location is not on a list of valid locations, mark the user invalid.

 

For the above rule I need to pass a list of valid locations as well.

 

Now how about “Customer login from more than 5 locations in the last one month”?

 

Thanks

Mr. Bhangale Bhushan
Associate Manager
Kale Consultants Ltd.
bhushan_bhangale@kaleconsultants.com
tel: +91 (0)206 608 3777
http://www.kaleconsultants.com

 

 

 

 

 

Disclaimer: This email (including any attachments) is intended for the sole
use of the recipient/s and may contain material that is CONFIDENTIAL. Any
unauthorized disclosure / copying / distribution or forwarding of this message 
or part is STRICTLY PROHIBITED. If you have erroneously received this message,
please delete it immediately and notify the sender. No liability is assumed for
any errors and/or omissions in the contents of this message. Information in 
this message that does not relate to the official business of this Company
shall be understood as neither given nor endorsed by it. If verification is
required please request a hard-copy version. 
 
To know more about Kale Consultants, visit www.kaleconsultants.com 
 
----------
 
 

 


_______________________________________________
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




Disclaimer: This email (including any attachments) is intended for the sole
use of the recipient/s and may contain material that is CONFIDENTIAL. Any
unauthorized disclosure / copying / distribution or forwarding of this message 
or part is STRICTLY PROHIBITED. If you have erroneously received this message,
please delete it immediately and notify the sender. No liability is assumed for
any errors and/or omissions in the contents of this message. Information in 
this message that does not relate to the official business of this Company
shall be understood as neither given nor endorsed by it. If verification is
required please request a hard-copy version. 

To know more about Kale Consultants, visit www.kaleconsultants.com 

-=-=-=-=-=-=-=-=-=-