some pointers for solution

21 messages Options
Embed this post
Permalink
1 2
Wishing Carebear

some pointers for solution

Reply Threaded More More options
Print post
Permalink
Hello:
There are n selection criteria from s1 .. sn for each item i1.. in. Each item can have a subset of criteria which applies to them.
 
The end user, can choose a subset of criteria like c1 and c5 and only the item that has c1 and c5 valid should be returned. For example: if item i1 and i2 have criterias valid for c1, c2, c5, c6, c8 since the request is only for criteria c1 and c5, i1 and i2 must be returned.
 
Is it possible to write a rule using drools for this requirement.
 
Thanks for your help and time,
cabear

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wolfgang Laun-2

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Another proposal, with perhaps more emphasize on "rulishness".

Given
   class Item  { T1 s1;... Tn sn;... }
let's add
   enum Criterium { C1, C2,... Cn; }
   class Request { EnumSet<Criterium> criteria; HashSet<Item> results; }

To launch a request, insert a Request object with an appropriate setting for criteria. Then, match all Item facts against rules, one for each Ci:

rule "Check C1"
when
    $request : Request( criteria contains Criterium.C1 )
    $item : Item( s1 <op> <value> )     # the constraint defining "valid"
then
    $request.getResults().add( $item );   # no modify!
end

//...same for C2 ... Cn

rule "Return results"
salience -100
when
    $request : Request()
then
    ... send $request.getResults() back to User
    retract( $request );
end

You could have two rules here, one testing for success (getResults().size() == getCriteria().size()), the other one firing for failure, but it might be preferable to handle it in the presentation layer.

Although I've used similar approaches, the code here is just off the cuff.
-W

2009/11/8 Wishing Carebear <[hidden email]>
Hello:
There are n selection criteria from s1 .. sn for each item i1.. in. Each item can have a subset of criteria which applies to them.
 
The end user, can choose a subset of criteria like c1 and c5 and only the item that has c1 and c5 valid should be returned. For example: if item i1 and i2 have criterias valid for c1, c2, c5, c6, c8 since the request is only for criteria c1 and c5, i1 and i2 must be returned.
 
Is it possible to write a rule using drools for this requirement.
 
Thanks for your help and time,
cabear

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Thanks Greg\Barton. I will try it out and get back to you.
 
Regards,
cabear

2009/11/8 Wolfgang Laun <[hidden email]>
Another proposal, with perhaps more emphasize on "rulishness".

Given
   class Item  { T1 s1;... Tn sn;... }
let's add
   enum Criterium { C1, C2,... Cn; }
   class Request { EnumSet<Criterium> criteria; HashSet<Item> results; }

To launch a request, insert a Request object with an appropriate setting for criteria. Then, match all Item facts against rules, one for each Ci:

rule "Check C1"
when
    $request : Request( criteria contains Criterium.C1 )
    $item : Item( s1 <op> <value> )     # the constraint defining "valid"
then
    $request.getResults().add( $item );   # no modify!
end

//...same for C2 ... Cn

rule "Return results"
salience -100
when
    $request : Request()
then
    ... send $request.getResults() back to User
    retract( $request );
end

You could have two rules here, one testing for success (getResults().size() == getCriteria().size()), the other one firing for failure, but it might be preferable to handle it in the presentation layer.

Although I've used similar approaches, the code here is just off the cuff.
-W

2009/11/8 Wishing Carebear <[hidden email]>
Hello:
There are n selection criteria from s1 .. sn for each item i1.. in. Each item can have a subset of criteria which applies to them.
 
The end user, can choose a subset of criteria like c1 and c5 and only the item that has c1 and c5 valid should be returned. For example: if item i1 and i2 have criterias valid for c1, c2, c5, c6, c8 since the request is only for criteria c1 and c5, i1 and i2 must be returned.
 
Is it possible to write a rule using drools for this requirement.
 
Thanks for your help and time,
cabear

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
In reply to this post by Wolfgang Laun-2
Hi Wolfgang:
Thanks for your help.
Is it possible to explain little bit more on the Item class and rule C1.
 
Not able to comprehend the complete solution.
 
Thanks,
cabear

2009/11/8 Wolfgang Laun <[hidden email]>
Another proposal, with perhaps more emphasize on "rulishness".

Given
   class Item  { T1 s1;... Tn sn;... }
let's add
   enum Criterium { C1, C2,... Cn; }
   class Request { EnumSet<Criterium> criteria; HashSet<Item> results; }

To launch a request, insert a Request object with an appropriate setting for criteria. Then, match all Item facts against rules, one for each Ci:

rule "Check C1"
when
    $request : Request( criteria contains Criterium.C1 )
    $item : Item( s1 <op> <value> )     # the constraint defining "valid"
then
    $request.getResults().add( $item );   # no modify!
end

//...same for C2 ... Cn

rule "Return results"
salience -100
when
    $request : Request()
then
    ... send $request.getResults() back to User
    retract( $request );
end

You could have two rules here, one testing for success (getResults().size() == getCriteria().size()), the other one firing for failure, but it might be preferable to handle it in the presentation layer.

Although I've used similar approaches, the code here is just off the cuff.
-W

2009/11/8 Wishing Carebear <[hidden email]>
Hello:
There are n selection criteria from s1 .. sn for each item i1.. in. Each item can have a subset of criteria which applies to them.
 
The end user, can choose a subset of criteria like c1 and c5 and only the item that has c1 and c5 valid should be returned. For example: if item i1 and i2 have criterias valid for c1, c2, c5, c6, c8 since the request is only for criteria c1 and c5, i1 and i2 must be returned.
 
Is it possible to write a rule using drools for this requirement.
 
Thanks for your help and time,
cabear

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Greg Barton

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
In reply to this post by Wishing Carebear
Yep.  See attached project.  It actually simplifies the java a bit, as now there doesn't need to be any trickery in the contains method for Query.  The rule now uses a from clause to get the Criteria directly from the Query:

rule "Match"
  when
    d : Data()
    q : Query( size <= d.size )
      $total : Number( intValue == q.size )
        from accumulate( Criteria( this memberOf d ) from q, count(1) )
  then
    System.out.println("Match: " + d + " and " + q) ;
end

Try the other methods, though. (The eval 'hack' I included before, and Wolfgang's method.)  All of these approaches should have different performance behavior, and I honestly don't know which one is fastest.

--- On Sun, 11/8/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 8:02 PM
> Yes Edson, I tried with count and sum.
> Both seems to be working fine.
>  
> But with the test case, the Criteria for query also
> needs to be inserted in addition to the query and data
> objects like shown below:
>  
> Query query = new Query(1);
> query.add(new
> Criteria(query, "c2", "bas"));
> ksession.insert(query);
> for(Criteria c :
> query) {
> ksession.insert(c);
> }
>  
>  
> Is it possible to avoid them.
>  
> Thanks,
> cabear
>
>
>
> 2009/11/8 Edson Tirelli <[hidden email]>
>
>
>    Why not use count() accumulate function? ;)
>
>
> from accumulate( Criteria( this memberOf d, this memberOf q
> ),
>                           
> count(1) )
>
>    Edson
>
>
>
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> In this case
> the accumulate clause is maintaining a counter (total)
> that's incremented whenever a Criteria is detected that
> is contained in both the Data and Query object matched in
> the rule.  So:
>
>
> # Find Criteria that are contained in both the Data and
> Query
>
> from accumulate( Criteria( this memberOf d, this
> memberOf q ),
> # Initialize the counter to 0
>  init( int total = 0; ),
> # Increment when the above condition is  matched
>  action( total ++; ),
> # Decrement if a matched Criteria now fails to match
>
>  reverse( total --; ),
> # return the total when all known Criteria are matched
>  result( total ) )
>
>
> --- On Sun, 11/8/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: Re: [rules-users] some pointers for
> solution
> > To: "Rules Users List" <[hidden email]>
> > Date: Sunday, November 8, 2009, 11:39 AM
>
>
>
>
> > Hi Greg:
> > I'm trying to understand your first
> > solution.
> >  
> > Ran the project and it works fine. If possible could
> > you explain me little bit on :
> >
> > from accumulate( Criteria( this memberOf d,
>
> > this memberOf q ),
> > init( int total = 0; ),
> > action( total ++; ),
> > reverse( total --; ),
> > result( total ) )
> >  
> >  
> > Thanks,
> > cabear
> >
> >
> > 2009/11/8 Greg Barton <[hidden email]>
>
> >
> > There are a couple of
> > ways to do this.  I'm sure there's a bit more
> clean
> > way than the example I'm providing, but this
> should get
> > you in the right direction.  It's not 100%
> rules,
>
> > because it involves a bit of java collections
> trickery. (See
> > attached project,
> collection_DroolsCriteriaMatch.tar.gz)
> >
> >
> > The heart of it is a single rule:
> >
> > rule "Match"
>
> >  when
> >    d : Data()
> >    q : Query( size <= d.size )
> >    Number( intValue == q.size )
> >    from accumulate(
> >      Criteria( this memberOf d, this memberOf q ),
> >
> >      init( int total = 0; ),
>
> >      action( total ++; ),
> >      reverse( total --; ),
> >      result( total )
> >    )
> >  then
> >    System.out.println("Match: " + d +
> "
> > and " + q) ;
> > end
>
> >
> > The Data object holds data to be queried, Query
> objects are
> > asserted to match the Data, and Criteria objects can
> be
> > contained in either. (With the aforementioned
> collections
> > trickery that if a Criteria is contained in a Query it
> can
>
> > be found in a Data object, but the reverse isn't
> true.
> >  See the Query.contains(Object) method for how
> that's
> > implemented.)
> >
> >
> > So the rule above basically says "There's a
> Data
>
> > object, and all of the Query objects Criteria are
> contained
> > in the Data object."
> >
> > There's an alternate way of doing this using eval
> and a
> > bit more java fu.  See the
> eval_DroolsCriteriaMatch.tar.gz
>
> > project attached.  This one's probably not
> optimal,
> > though, as it's basically a brute force check of
> all
> > Data objects against the asserted Query.
> >
> >
> > I tried for a while to get a solution working with
>
> > different criteria types from both Data and Query
> objects
> > being asserted into working memory, but I couldn't
> get
> > the accumulate syntax right.  Anyone know of a way to
> do
> > that? (I figure that would get a "pure
> rules"
>
> > solution.)
> >
> >
> > --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> > wrote:
> >
> > > From: Wishing Carebear <[hidden email]>
>
> >
> > > Subject: [rules-users] some pointers for
> solution
> > > To: [hidden email]
> > > Date: Saturday, November 7, 2009, 10:19 PM
>
> >
> >
> >
> > > Hello:
> > > There are n selection criteria from s1 .. sn for
> each
> > > item i1.. in. Each item can have a subset of
> criteria
> > which
> > > applies to them.
>
> > >  
> > > The end user, can choose a subset of criteria
> like c1
> >
> > > and c5 and only the item that has c1 and c5
> valid
> > should be
> > > returned. For example: if item i1 and i2 have
>
> > criterias
> > > valid for c1, c2, c5, c6, c8 since the request is
> only
> > for
> > > criteria c1 and c5, i1 and i2 must be returned.
> >
> > >
> > >  
> > > Is it possible to write a rule using drools for
> this
>
> > > requirement.
> > >  
> > > Thanks for your help and time,
> > > cabear
> > >
> > > -----Inline Attachment Follows-----
> >
> > >
> > > _______________________________________________
>
> > > rules-users mailing list
> > > [hidden email]
> > > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
> > >
> >
> >
> >      
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
>
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> >
> >
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> --
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss by Red Hat @ www.jboss.com
>
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>

   

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users

collection_DroolsCriteriaMatch.tar.gz (7K) Download Attachment
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Thanks Greg. I really appreciate your help.
 
Will try it and update you.
 
Regards,
cabear

2009/11/8 Greg Barton <[hidden email]>
Yep.  See attached project.  It actually simplifies the java a bit, as now there doesn't need to be any trickery in the contains method for Query.  The rule now uses a from clause to get the Criteria directly from the Query:

rule "Match"
 when
   d : Data()
   q : Query( size <= d.size )
     $total : Number( intValue == q.size )
       from accumulate( Criteria( this memberOf d ) from q, count(1) )
 then
   System.out.println("Match: " + d + " and " + q) ;
end

Try the other methods, though. (The eval 'hack' I included before, and Wolfgang's method.)  All of these approaches should have different performance behavior, and I honestly don't know which one is fastest.

--- On Sun, 11/8/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 8:02 PM
> Yes Edson, I tried with count and sum.
> Both seems to be working fine.
>  
> But with the test case, the Criteria for query also
> needs to be inserted in addition to the query and data
> objects like shown below:
>  
> Query query = new Query(1);
> query.add(new
> Criteria(query, "c2", "bas"));
> ksession.insert(query);
> for(Criteria c :
> query) {
> ksession.insert(c);
> }
>  
>  
> Is it possible to avoid them.
>  
> Thanks,
> cabear
>
>
>
> 2009/11/8 Edson Tirelli <[hidden email]>
>
>
>    Why not use count() accumulate function? ;)
>
>
> from accumulate( Criteria( this memberOf d, this memberOf q
> ),

>                           
> count(1) )
>
>    Edson
>
>
>
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> In this case
> the accumulate clause is maintaining a counter (total)
> that's incremented whenever a Criteria is detected that
> is contained in both the Data and Query object matched in
> the rule.  So:
>
>
> # Find Criteria that are contained in both the Data and
> Query
>
> from accumulate( Criteria( this memberOf d, this
> memberOf q ),
> # Initialize the counter to 0
>  init( int total = 0; ),
> # Increment when the above condition is  matched
>  action( total ++; ),
> # Decrement if a matched Criteria now fails to match
>
>  reverse( total --; ),
> # return the total when all known Criteria are matched
>  result( total ) )
>
>
> --- On Sun, 11/8/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: Re: [rules-users] some pointers for
> solution
> > To: "Rules Users List" <[hidden email]>
> > Date: Sunday, November 8, 2009, 11:39 AM
>
>
>
>
> > Hi Greg:
> > I'm trying to understand your first
> > solution.
> >  
> > Ran the project and it works fine. If possible could
> > you explain me little bit on :
> >
> > from accumulate( Criteria( this memberOf d,
>
> > this memberOf q ),
> > init( int total = 0; ),
> > action( total ++; ),
> > reverse( total --; ),
> > result( total ) )
> >  
> >  
> > Thanks,
> > cabear
> >
> >
> > 2009/11/8 Greg Barton <[hidden email]>
>
> >
> > There are a couple of
> > ways to do this.  I'm sure there's a bit more
> clean
> > way than the example I'm providing, but this
> should get
> > you in the right direction.  It's not 100%
> rules,
>
> > because it involves a bit of java collections
> trickery. (See
> > attached project,
> collection_DroolsCriteriaMatch.tar.gz)
> >
> >
> > The heart of it is a single rule:
> >
> > rule "Match"
>
> >  when
> >    d : Data()
> >    q : Query( size <= d.size )
> >    Number( intValue == q.size )
> >    from accumulate(
> >      Criteria( this memberOf d, this memberOf q ),
> >
> >      init( int total = 0; ),
>
> >      action( total ++; ),
> >      reverse( total --; ),
> >      result( total )
> >    )
> >  then
> >    System.out.println("Match: " + d +
> "
> > and " + q) ;
> > end
>
> >
> > The Data object holds data to be queried, Query
> objects are
> > asserted to match the Data, and Criteria objects can
> be
> > contained in either. (With the aforementioned
> collections
> > trickery that if a Criteria is contained in a Query it
> can
>
> > be found in a Data object, but the reverse isn't
> true.
> >  See the Query.contains(Object) method for how
> that's
> > implemented.)
> >
> >
> > So the rule above basically says "There's a
> Data
>
> > object, and all of the Query objects Criteria are
> contained
> > in the Data object."
> >
> > There's an alternate way of doing this using eval
> and a
> > bit more java fu.  See the
> eval_DroolsCriteriaMatch.tar.gz
>
> > project attached.  This one's probably not
> optimal,
> > though, as it's basically a brute force check of
> all
> > Data objects against the asserted Query.
> >
> >
> > I tried for a while to get a solution working with
>
> > different criteria types from both Data and Query
> objects
> > being asserted into working memory, but I couldn't
> get
> > the accumulate syntax right.  Anyone know of a way to
> do
> > that? (I figure that would get a "pure
> rules"
>
> > solution.)
> >
> >
> > --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> > wrote:
> >
> > > From: Wishing Carebear <[hidden email]>
>
> >
> > > Subject: [rules-users] some pointers for
> solution
> > > To: [hidden email]
> > > Date: Saturday, November 7, 2009, 10:19 PM
>
> >
> >
> >
> > > Hello:
> > > There are n selection criteria from s1 .. sn for
> each
> > > item i1.. in. Each item can have a subset of
> criteria
> > which
> > > applies to them.
>
> > >  
> > > The end user, can choose a subset of criteria
> like c1
> >
> > > and c5 and only the item that has c1 and c5
> valid
> > should be
> > > returned. For example: if item i1 and i2 have
>
> > criterias
> > > valid for c1, c2, c5, c6, c8 since the request is
> only
> > for
> > > criteria c1 and c5, i1 and i2 must be returned.
> >
> > >
> > >  
> > > Is it possible to write a rule using drools for
> this
>
> > > requirement.
> > >  
> > > Thanks for your help and time,
> > > cabear
> > >
> > > -----Inline Attachment Follows-----
> >
> > >
> > > _______________________________________________
>
> > > rules-users mailing list
> > > [hidden email]
> > > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
> > >
> >
> >
> >      
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
>
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> >
> >
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> --
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss by Red Hat @ www.jboss.com
>
>
> _______________________________________________
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
In reply to this post by Greg Barton
Also I hope modifying the statement:

q : Query( size <= d.size )

to

q : Query( )


should be fine.
 

 
2009/11/8 Greg Barton <[hidden email]>
Yep.  See attached project.  It actually simplifies the java a bit, as now there doesn't need to be any trickery in the contains method for Query.  The rule now uses a from clause to get the Criteria directly from the Query:

rule "Match"
 when
   d : Data()
   q : Query( size <= d.size )
     $total : Number( intValue == q.size )
       from accumulate( Criteria( this memberOf d ) from q, count(1) )
 then
   System.out.println("Match: " + d + " and " + q) ;
end

Try the other methods, though. (The eval 'hack' I included before, and Wolfgang's method.)  All of these approaches should have different performance behavior, and I honestly don't know which one is fastest.

--- On Sun, 11/8/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 8:02 PM
> Yes Edson, I tried with count and sum.
> Both seems to be working fine.
>  
> But with the test case, the Criteria for query also
> needs to be inserted in addition to the query and data
> objects like shown below:
>  
> Query query = new Query(1);
> query.add(new
> Criteria(query, "c2", "bas"));
> ksession.insert(query);
> for(Criteria c :
> query) {
> ksession.insert(c);
> }
>  
>  
> Is it possible to avoid them.
>  
> Thanks,
> cabear
>
>
>
> 2009/11/8 Edson Tirelli <[hidden email]>
>
>
>    Why not use count() accumulate function? ;)
>
>
> from accumulate( Criteria( this memberOf d, this memberOf q
> ),

>                           
> count(1) )
>
>    Edson
>
>
>
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> In this case
> the accumulate clause is maintaining a counter (total)
> that's incremented whenever a Criteria is detected that
> is contained in both the Data and Query object matched in
> the rule.  So:
>
>
> # Find Criteria that are contained in both the Data and
> Query
>
> from accumulate( Criteria( this memberOf d, this
> memberOf q ),
> # Initialize the counter to 0
>  init( int total = 0; ),
> # Increment when the above condition is  matched
>  action( total ++; ),
> # Decrement if a matched Criteria now fails to match
>
>  reverse( total --; ),
> # return the total when all known Criteria are matched
>  result( total ) )
>
>
> --- On Sun, 11/8/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: Re: [rules-users] some pointers for
> solution
> > To: "Rules Users List" <[hidden email]>
> > Date: Sunday, November 8, 2009, 11:39 AM
>
>
>
>
> > Hi Greg:
> > I'm trying to understand your first
> > solution.
> >  
> > Ran the project and it works fine. If possible could
> > you explain me little bit on :
> >
> > from accumulate( Criteria( this memberOf d,
>
> > this memberOf q ),
> > init( int total = 0; ),
> > action( total ++; ),
> > reverse( total --; ),
> > result( total ) )
> >  
> >  
> > Thanks,
> > cabear
> >
> >
> > 2009/11/8 Greg Barton <[hidden email]>
>
> >
> > There are a couple of
> > ways to do this.  I'm sure there's a bit more
> clean
> > way than the example I'm providing, but this
> should get
> > you in the right direction.  It's not 100%
> rules,
>
> > because it involves a bit of java collections
> trickery. (See
> > attached project,
> collection_DroolsCriteriaMatch.tar.gz)
> >
> >
> > The heart of it is a single rule:
> >
> > rule "Match"
>
> >  when
> >    d : Data()
> >    q : Query( size <= d.size )
> >    Number( intValue == q.size )
> >    from accumulate(
> >      Criteria( this memberOf d, this memberOf q ),
> >
> >      init( int total = 0; ),
>
> >      action( total ++; ),
> >      reverse( total --; ),
> >      result( total )
> >    )
> >  then
> >    System.out.println("Match: " + d +
> "
> > and " + q) ;
> > end
>
> >
> > The Data object holds data to be queried, Query
> objects are
> > asserted to match the Data, and Criteria objects can
> be
> > contained in either. (With the aforementioned
> collections
> > trickery that if a Criteria is contained in a Query it
> can
>
> > be found in a Data object, but the reverse isn't
> true.
> >  See the Query.contains(Object) method for how
> that's
> > implemented.)
> >
> >
> > So the rule above basically says "There's a
> Data
>
> > object, and all of the Query objects Criteria are
> contained
> > in the Data object."
> >
> > There's an alternate way of doing this using eval
> and a
> > bit more java fu.  See the
> eval_DroolsCriteriaMatch.tar.gz
>
> > project attached.  This one's probably not
> optimal,
> > though, as it's basically a brute force check of
> all
> > Data objects against the asserted Query.
> >
> >
> > I tried for a while to get a solution working with
>
> > different criteria types from both Data and Query
> objects
> > being asserted into working memory, but I couldn't
> get
> > the accumulate syntax right.  Anyone know of a way to
> do
> > that? (I figure that would get a "pure
> rules"
>
> > solution.)
> >
> >
> > --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> > wrote:
> >
> > > From: Wishing Carebear <[hidden email]>
>
> >
> > > Subject: [rules-users] some pointers for
> solution
> > > To: [hidden email]
> > > Date: Saturday, November 7, 2009, 10:19 PM
>
> >
> >
> >
> > > Hello:
> > > There are n selection criteria from s1 .. sn for
> each
> > > item i1.. in. Each item can have a subset of
> criteria
> > which
> > > applies to them.
>
> > >  
> > > The end user, can choose a subset of criteria
> like c1
> >
> > > and c5 and only the item that has c1 and c5
> valid
> > should be
> > > returned. For example: if item i1 and i2 have
>
> > criterias
> > > valid for c1, c2, c5, c6, c8 since the request is
> only
> > for
> > > criteria c1 and c5, i1 and i2 must be returned.
> >
> > >
> > >  
> > > Is it possible to write a rule using drools for
> this
>
> > > requirement.
> > >  
> > > Thanks for your help and time,
> > > cabear
> > >
> > > -----Inline Attachment Follows-----
> >
> > >
> > > _______________________________________________
>
> > > rules-users mailing list
> > > [hidden email]
> > > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
> > >
> >
> >
> >      
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
>
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> >
> >
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> --
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss by Red Hat @ www.jboss.com
>
>
> _______________________________________________
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Greg Barton

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Yeah,  That condition is just an optimization that prevents comparison of a Query against a Data that has less Criteria than the Query, which by definition cannot then be satisfied.  It's not logically necessary, but a pretty easy optimization.

--- On Sun, 11/8/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 10:33 PM
> Also I hope modifying the
> statement:
> q : Query( size <= d.size )
> to
> q : Query( )
>
> should be fine.
>  
>
>  
> 2009/11/8 Greg Barton <[hidden email]>
>
> Yep.  See attached
> project.  It actually simplifies the java a bit, as now
> there doesn't need to be any trickery in the contains
> method for Query.  The rule now uses a from clause to get
> the Criteria directly from the Query:
>
>
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>      $total : Number( intValue == q.size )
>        from accumulate( Criteria( this memberOf d )
> from q, count(1) )
>
>
>  then
>    System.out.println("Match: " + d + "
> and " + q) ;
> end
>
> Try the other methods, though. (The eval
> 'hack' I included before, and Wolfgang's
> method.)  All of these approaches should have different
> performance behavior, and I honestly don't know which
> one is fastest.
>
>
>
> --- On Sun, 11/8/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: Re: [rules-users] some pointers for solution
> > To: "Rules Users List" <[hidden email]>
> > Date: Sunday, November 8, 2009, 8:02 PM
>
>
> > Yes Edson, I tried with count and
> sum.
> > Both seems to be working fine.
> >  
> > But with the test case, the Criteria for query also
> > needs to be inserted in addition to the query and
> data
>
> > objects like shown below:
> >  
> > Query query = new Query(1);
> > query.add(new
> > Criteria(query, "c2", "bas"));
> > ksession.insert(query);
> > for(Criteria c :
> > query) {
>
> > ksession.insert(c);
> > }
> >  
> >  
> > Is it possible to avoid them.
> >  
> > Thanks,
> > cabear
> >
> >
> >
>
>
>
> > 2009/11/8 Edson Tirelli <[hidden email]>
> >
> >
> >    Why not use count() accumulate function? ;)
> >
> >
> > from accumulate( Criteria( this memberOf d, this
> memberOf q
>
> > ),
> >                           
> > count(1) )
> >
> >    Edson
> >
> >
> >
> >
> >
> > 2009/11/8 Greg Barton <[hidden email]>
>
> >
> > In this case
> > the accumulate clause is maintaining a counter
> (total)
> > that's incremented whenever a Criteria is detected
> that
> > is contained in both the Data and Query object matched
> in
>
> > the rule.  So:
> >
> >
> > # Find Criteria that are contained in both the Data
> and
> > Query
> >
> > from accumulate( Criteria( this memberOf d, this
> > memberOf q ),
> > # Initialize the counter to 0
>
> >  init( int total = 0; ),
> > # Increment when the above condition is  matched
> >  action( total ++; ),
> > # Decrement if a matched Criteria now fails to match
> >
> >  reverse( total --; ),
> > # return the total when all known Criteria are
> matched
>
> >  result( total ) )
> >
> >
> > --- On Sun, 11/8/09, Wishing Carebear <[hidden email]>
> > wrote:
> >
> > > From: Wishing Carebear <[hidden email]>
>
> >
> > > Subject: Re: [rules-users] some pointers for
> > solution
> > > To: "Rules Users List" <[hidden email]>
> > > Date: Sunday, November 8, 2009, 11:39 AM
>
> >
> >
> >
> >
> > > Hi Greg:
> > > I'm trying to understand your first
> > > solution.
> > >  
> > > Ran the project and it works fine. If possible
> could
> > > you explain me little bit on :
>
> > >
> > > from accumulate( Criteria( this memberOf d,
> >
> > > this memberOf q ),
> > > init( int total = 0; ),
> > > action( total ++; ),
> > > reverse( total --; ),
> > > result( total ) )
>
> > >  
> > >  
> > > Thanks,
> > > cabear
> > >
> > >
>
>
>
> > > 2009/11/8 Greg Barton <[hidden email]>
> >
> > >
> > > There are a couple of
> > > ways to do this.  I'm sure there's a bit
> more
>
> > clean
> > > way than the example I'm providing, but this
> > should get
> > > you in the right direction.  It's not 100%
> > rules,
> >
> > > because it involves a bit of java collections
>
> > trickery. (See
> > > attached project,
> > collection_DroolsCriteriaMatch.tar.gz)
> > >
> > >
> > > The heart of it is a single rule:
> > >
> > > rule "Match"
>
> >
> > >  when
> > >    d : Data()
> > >    q : Query( size <= d.size )
> > >    Number( intValue == q.size )
> > >    from accumulate(
> > >      Criteria( this memberOf d, this memberOf
> q ),
>
> > >
> > >      init( int total = 0; ),
> >
> > >      action( total ++; ),
> > >      reverse( total --; ),
> > >      result( total )
> > >    )
> > >  then
> > >    System.out.println("Match: " + d
> +
>
> > "
> > > and " + q) ;
> > > end
> >
> > >
> > > The Data object holds data to be queried, Query
> > objects are
> > > asserted to match the Data, and Criteria objects
> can
>
> > be
> > > contained in either. (With the aforementioned
> > collections
> > > trickery that if a Criteria is contained in a
> Query it
> > can
> >
> > > be found in a Data object, but the reverse
> isn't
>
> > true.
> > >  See the Query.contains(Object) method for how
> > that's
> > > implemented.)
> > >
> > >
> > > So the rule above basically says
> "There's a
> > Data
>
> >
> > > object, and all of the Query objects Criteria
> are
> > contained
> > > in the Data object."
> > >
> > > There's an alternate way of doing this using
> eval
> > and a
>
> > > bit more java fu.  See the
> > eval_DroolsCriteriaMatch.tar.gz
> >
> > > project attached.  This one's probably not
> > optimal,
> > > though, as it's basically a brute force check
> of
>
> > all
> > > Data objects against the asserted Query.
> > >
> > >
> > > I tried for a while to get a solution working
> with
> >
> > > different criteria types from both Data and
> Query
>
> > objects
> > > being asserted into working memory, but I
> couldn't
> > get
> > > the accumulate syntax right.  Anyone know of a
> way to
> > do
> > > that? (I figure that would get a "pure
>
> > rules"
> >
> > > solution.)
> > >
> > >
> > > --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> > > wrote:
>
> > >
> > > > From: Wishing Carebear <[hidden email]>
> >
> > >
> > > > Subject: [rules-users] some pointers for
> > solution
>
> > > > To: [hidden email]
> > > > Date: Saturday, November 7, 2009, 10:19 PM
> >
> > >
> > >
> > >
>
> > > > Hello:
> > > > There are n selection criteria from s1 .. sn
> for
> > each
> > > > item i1.. in. Each item can have a subset
> of
> > criteria
> > > which
>
> > > > applies to them.
> >
> > > >  
> > > > The end user, can choose a subset of
> criteria
> > like c1
> > >
> > > > and c5 and only the item that has c1 and c5
> > valid
>
> > > should be
> > > > returned. For example: if item i1 and i2
> have
> >
> > > criterias
> > > > valid for c1, c2, c5, c6, c8 since the
> request is
> > only
> > > for
> > > > criteria c1 and c5, i1 and i2 must be
> returned.
>
> > >
> > > >
> > > >  
> > > > Is it possible to write a rule using drools
> for
> > this
> >
> > > > requirement.
> > > >  
> > > > Thanks for your help and time,
>
> > > > cabear
> > > >
> > > > -----Inline Attachment Follows-----
>
> > >
> > > >
> > > >
> _______________________________________________
> >
> > > > rules-users mailing list
> > > > [hidden email]
>
> > > > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> > >
> > > >
> > >
> > >
> > >      
>
> > > _______________________________________________
> > > rules-users mailing list
> > > [hidden email]
> >
> > > https://lists.jboss.org/mailman/listinfo/rules-users
>
> > >
> > >
> > >
> > >
> > >
> > > -----Inline Attachment Follows-----
>
> >
> > >
> > > _______________________________________________
> > > rules-users mailing list
> > > [hidden email]
>
> > > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> > >
> >
> >
> >
> >
> > _______________________________________________
>
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
> >
> >
> >
>
> > --
> >  Edson Tirelli
> >  JBoss Drools Core Development
> >  JBoss by Red Hat @ www.jboss.com
> >
> >
> > _______________________________________________
>
>
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
> >
> >
> >
> >
> > -----Inline Attachment Follows-----
>
>
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>      
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Greg Barton

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
In reply to this post by Wishing Carebear
There are a couple of ways to do this.  I'm sure there's a bit more clean way than the example I'm providing, but this should get you in the right direction.  It's not 100% rules, because it involves a bit of java collections trickery. (See attached project, collection_DroolsCriteriaMatch.tar.gz)

The heart of it is a single rule:

rule "Match"
  when
    d : Data()
    q : Query( size <= d.size )
    Number( intValue == q.size )
    from accumulate(
      Criteria( this memberOf d, this memberOf q ),
      init( int total = 0; ),
      action( total ++; ),
      reverse( total --; ),
      result( total )
    )
  then
    System.out.println("Match: " + d + " and " + q) ;
end

The Data object holds data to be queried, Query objects are asserted to match the Data, and Criteria objects can be contained in either. (With the aforementioned collections trickery that if a Criteria is contained in a Query it can be found in a Data object, but the reverse isn't true.  See the Query.contains(Object) method for how that's implemented.)

So the rule above basically says "There's a Data object, and all of the Query objects Criteria are contained in the Data object."

There's an alternate way of doing this using eval and a bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz project attached.  This one's probably not optimal, though, as it's basically a brute force check of all Data objects against the asserted Query.

I tried for a while to get a solution working with different criteria types from both Data and Query objects being asserted into working memory, but I couldn't get the accumulate syntax right.  Anyone know of a way to do that? (I figure that would get a "pure rules" solution.)

--- On Sat, 11/7/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: [rules-users] some pointers for solution
> To: [hidden email]
> Date: Saturday, November 7, 2009, 10:19 PM
> Hello:
> There are n selection criteria from s1 .. sn for each
> item i1.. in. Each item can have a subset of criteria which
> applies to them.
>  
> The end user, can choose a subset of criteria like c1
> and c5 and only the item that has c1 and c5 valid should be
> returned. For example: if item i1 and i2 have criterias
> valid for c1, c2, c5, c6, c8 since the request is only for
> criteria c1 and c5, i1 and i2 must be returned.
>
>  
> Is it possible to write a rule using drools for this
> requirement.
>  
> Thanks for your help and time,
> cabear
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>




_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users

collection_DroolsCriteriaMatch.tar.gz (7K) Download Attachment
eval_DroolsCriteriaMatch.tar.gz (6K) Download Attachment
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Hi Greg:
I'm trying to understand your first solution.
 
Ran the project and it works fine. If possible could you explain me little bit on :

from accumulate( Criteria( this memberOf d, this memberOf q ),

init( int total = 0; ),

action( total ++; ),

reverse( total --; ),

result( total ) )

 
 
Thanks,
cabear

2009/11/8 Greg Barton <[hidden email]>
There are a couple of ways to do this.  I'm sure there's a bit more clean way than the example I'm providing, but this should get you in the right direction.  It's not 100% rules, because it involves a bit of java collections trickery. (See attached project, collection_DroolsCriteriaMatch.tar.gz)

The heart of it is a single rule:

rule "Match"
 when
   d : Data()
   q : Query( size <= d.size )
   Number( intValue == q.size )
   from accumulate(
     Criteria( this memberOf d, this memberOf q ),
     init( int total = 0; ),
     action( total ++; ),
     reverse( total --; ),
     result( total )
   )
 then
   System.out.println("Match: " + d + " and " + q) ;
end

The Data object holds data to be queried, Query objects are asserted to match the Data, and Criteria objects can be contained in either. (With the aforementioned collections trickery that if a Criteria is contained in a Query it can be found in a Data object, but the reverse isn't true.  See the Query.contains(Object) method for how that's implemented.)

So the rule above basically says "There's a Data object, and all of the Query objects Criteria are contained in the Data object."

There's an alternate way of doing this using eval and a bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz project attached.  This one's probably not optimal, though, as it's basically a brute force check of all Data objects against the asserted Query.

I tried for a while to get a solution working with different criteria types from both Data and Query objects being asserted into working memory, but I couldn't get the accumulate syntax right.  Anyone know of a way to do that? (I figure that would get a "pure rules" solution.)

--- On Sat, 11/7/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: [rules-users] some pointers for solution
> To: [hidden email]
> Date: Saturday, November 7, 2009, 10:19 PM
> Hello:
> There are n selection criteria from s1 .. sn for each
> item i1.. in. Each item can have a subset of criteria which
> applies to them.
>  
> The end user, can choose a subset of criteria like c1
> and c5 and only the item that has c1 and c5 valid should be
> returned. For example: if item i1 and i2 have criterias
> valid for c1, c2, c5, c6, c8 since the request is only for
> criteria c1 and c5, i1 and i2 must be returned.
>
>  
> Is it possible to write a rule using drools for this
> requirement.
>  
> Thanks for your help and time,
> cabear
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Greg Barton

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
In this case the accumulate clause is maintaining a counter (total) that's incremented whenever a Criteria is detected that is contained in both the Data and Query object matched in the rule.  So:

# Find Criteria that are contained in both the Data and Query
from accumulate( Criteria( this memberOf d, this memberOf q ),
# Initialize the counter to 0
  init( int total = 0; ),
# Increment when the above condition is  matched
  action( total ++; ),
# Decrement if a matched Criteria now fails to match
  reverse( total --; ),
# return the total when all known Criteria are matched
  result( total ) )

--- On Sun, 11/8/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 11:39 AM
> Hi Greg:
> I'm trying to understand your first
> solution.
>  
> Ran the project and it works fine. If possible could
> you explain me little bit on :
>
> from accumulate( Criteria( this memberOf d,
> this memberOf q ),
> init( int total = 0; ),
> action( total ++; ),
> reverse( total --; ),
> result( total ) )
>  
>  
> Thanks,
> cabear
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> There are a couple of
> ways to do this.  I'm sure there's a bit more clean
> way than the example I'm providing, but this should get
> you in the right direction.  It's not 100% rules,
> because it involves a bit of java collections trickery. (See
> attached project, collection_DroolsCriteriaMatch.tar.gz)
>
>
> The heart of it is a single rule:
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>    Number( intValue == q.size )
>    from accumulate(
>      Criteria( this memberOf d, this memberOf q ),
>
>      init( int total = 0; ),
>      action( total ++; ),
>      reverse( total --; ),
>      result( total )
>    )
>  then
>    System.out.println("Match: " + d + "
> and " + q) ;
> end
>
> The Data object holds data to be queried, Query objects are
> asserted to match the Data, and Criteria objects can be
> contained in either. (With the aforementioned collections
> trickery that if a Criteria is contained in a Query it can
> be found in a Data object, but the reverse isn't true.
>  See the Query.contains(Object) method for how that's
> implemented.)
>
>
> So the rule above basically says "There's a Data
> object, and all of the Query objects Criteria are contained
> in the Data object."
>
> There's an alternate way of doing this using eval and a
> bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz
> project attached.  This one's probably not optimal,
> though, as it's basically a brute force check of all
> Data objects against the asserted Query.
>
>
> I tried for a while to get a solution working with
> different criteria types from both Data and Query objects
> being asserted into working memory, but I couldn't get
> the accumulate syntax right.  Anyone know of a way to do
> that? (I figure that would get a "pure rules"
> solution.)
>
>
> --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: [rules-users] some pointers for solution
> > To: [hidden email]
> > Date: Saturday, November 7, 2009, 10:19 PM
>
>
>
> > Hello:
> > There are n selection criteria from s1 .. sn for each
> > item i1.. in. Each item can have a subset of criteria
> which
> > applies to them.
> >  
> > The end user, can choose a subset of criteria like c1
>
> > and c5 and only the item that has c1 and c5 valid
> should be
> > returned. For example: if item i1 and i2 have
> criterias
> > valid for c1, c2, c5, c6, c8 since the request is only
> for
> > criteria c1 and c5, i1 and i2 must be returned.
>
> >
> >  
> > Is it possible to write a rule using drools for this
> > requirement.
> >  
> > Thanks for your help and time,
> > cabear
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>      
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Thanks Greg,
 
Regards,
cabear

On Sun, Nov 8, 2009 at 11:00 AM, Greg Barton <[hidden email]> wrote:
In this case the accumulate clause is maintaining a counter (total) that's incremented whenever a Criteria is detected that is contained in both the Data and Query object matched in the rule.  So:

# Find Criteria that are contained in both the Data and Query
from accumulate( Criteria( this memberOf d, this memberOf q ),
# Initialize the counter to 0
 init( int total = 0; ),
# Increment when the above condition is  matched
 action( total ++; ),
# Decrement if a matched Criteria now fails to match
 reverse( total --; ),
# return the total when all known Criteria are matched
 result( total ) )

--- On Sun, 11/8/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 11:39 AM
> Hi Greg:
> I'm trying to understand your first
> solution.
>  
> Ran the project and it works fine. If possible could
> you explain me little bit on :
>
> from accumulate( Criteria( this memberOf d,
> this memberOf q ),

> init( int total = 0; ),
> action( total ++; ),
> reverse( total --; ),
> result( total ) )
>  
>  
> Thanks,
> cabear
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> There are a couple of
> ways to do this.  I'm sure there's a bit more clean
> way than the example I'm providing, but this should get
> you in the right direction.  It's not 100% rules,
> because it involves a bit of java collections trickery. (See
> attached project, collection_DroolsCriteriaMatch.tar.gz)
>
>
> The heart of it is a single rule:
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>    Number( intValue == q.size )
>    from accumulate(
>      Criteria( this memberOf d, this memberOf q ),
>
>      init( int total = 0; ),
>      action( total ++; ),
>      reverse( total --; ),
>      result( total )
>    )
>  then
>    System.out.println("Match: " + d + "
> and " + q) ;
> end
>
> The Data object holds data to be queried, Query objects are
> asserted to match the Data, and Criteria objects can be
> contained in either. (With the aforementioned collections
> trickery that if a Criteria is contained in a Query it can
> be found in a Data object, but the reverse isn't true.
>  See the Query.contains(Object) method for how that's
> implemented.)
>
>
> So the rule above basically says "There's a Data
> object, and all of the Query objects Criteria are contained
> in the Data object."
>
> There's an alternate way of doing this using eval and a
> bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz
> project attached.  This one's probably not optimal,
> though, as it's basically a brute force check of all
> Data objects against the asserted Query.
>
>
> I tried for a while to get a solution working with
> different criteria types from both Data and Query objects
> being asserted into working memory, but I couldn't get
> the accumulate syntax right.  Anyone know of a way to do
> that? (I figure that would get a "pure rules"
> solution.)
>
>
> --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: [rules-users] some pointers for solution
> > To: [hidden email]
> > Date: Saturday, November 7, 2009, 10:19 PM
>
>
>
> > Hello:
> > There are n selection criteria from s1 .. sn for each
> > item i1.. in. Each item can have a subset of criteria
> which
> > applies to them.
> >  
> > The end user, can choose a subset of criteria like c1
>
> > and c5 and only the item that has c1 and c5 valid
> should be
> > returned. For example: if item i1 and i2 have
> criterias
> > valid for c1, c2, c5, c6, c8 since the request is only
> for
> > criteria c1 and c5, i1 and i2 must be returned.
>
> >
> >  
> > Is it possible to write a rule using drools for this
> > requirement.
> >  
> > Thanks for your help and time,
> > cabear
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>      
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>




_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Edson Tirelli-4

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
In reply to this post by Greg Barton

   Why not use count() accumulate function? ;)

from accumulate( Criteria( this memberOf d, this memberOf q ),
                           count(1) )

   Edson

2009/11/8 Greg Barton <[hidden email]>
In this case the accumulate clause is maintaining a counter (total) that's incremented whenever a Criteria is detected that is contained in both the Data and Query object matched in the rule.  So:

# Find Criteria that are contained in both the Data and Query
from accumulate( Criteria( this memberOf d, this memberOf q ),
# Initialize the counter to 0
 init( int total = 0; ),
# Increment when the above condition is  matched
 action( total ++; ),
# Decrement if a matched Criteria now fails to match
 reverse( total --; ),
# return the total when all known Criteria are matched
 result( total ) )

--- On Sun, 11/8/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 11:39 AM
> Hi Greg:
> I'm trying to understand your first
> solution.
>  
> Ran the project and it works fine. If possible could
> you explain me little bit on :
>
> from accumulate( Criteria( this memberOf d,
> this memberOf q ),
> init( int total = 0; ),
> action( total ++; ),
> reverse( total --; ),
> result( total ) )
>  
>  
> Thanks,
> cabear
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> There are a couple of
> ways to do this.  I'm sure there's a bit more clean
> way than the example I'm providing, but this should get
> you in the right direction.  It's not 100% rules,
> because it involves a bit of java collections trickery. (See
> attached project, collection_DroolsCriteriaMatch.tar.gz)
>
>
> The heart of it is a single rule:
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>    Number( intValue == q.size )
>    from accumulate(
>      Criteria( this memberOf d, this memberOf q ),
>
>      init( int total = 0; ),
>      action( total ++; ),
>      reverse( total --; ),
>      result( total )
>    )
>  then
>    System.out.println("Match: " + d + "
> and " + q) ;
> end
>
> The Data object holds data to be queried, Query objects are
> asserted to match the Data, and Criteria objects can be
> contained in either. (With the aforementioned collections
> trickery that if a Criteria is contained in a Query it can
> be found in a Data object, but the reverse isn't true.
>  See the Query.contains(Object) method for how that's
> implemented.)
>
>
> So the rule above basically says "There's a Data
> object, and all of the Query objects Criteria are contained
> in the Data object."
>
> There's an alternate way of doing this using eval and a
> bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz
> project attached.  This one's probably not optimal,
> though, as it's basically a brute force check of all
> Data objects against the asserted Query.
>
>
> I tried for a while to get a solution working with
> different criteria types from both Data and Query objects
> being asserted into working memory, but I couldn't get
> the accumulate syntax right.  Anyone know of a way to do
> that? (I figure that would get a "pure rules"
> solution.)
>
>
> --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: [rules-users] some pointers for solution
> > To: [hidden email]
> > Date: Saturday, November 7, 2009, 10:19 PM
>
>
>
> > Hello:
> > There are n selection criteria from s1 .. sn for each
> > item i1.. in. Each item can have a subset of criteria
> which
> > applies to them.
> >  
> > The end user, can choose a subset of criteria like c1
>
> > and c5 and only the item that has c1 and c5 valid
> should be
> > returned. For example: if item i1 and i2 have
> criterias
> > valid for c1, c2, c5, c6, c8 since the request is only
> for
> > criteria c1 and c5, i1 and i2 must be returned.
>
> >
> >  
> > Is it possible to write a rule using drools for this
> > requirement.
> >  
> > Thanks for your help and time,
> > cabear
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>      
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>




_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Greg Barton

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Because I keep forgetting the convenience functions exist. :P

--- On Sun, 11/8/09, Edson Tirelli <[hidden email]> wrote:

> From: Edson Tirelli <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 4:41 PM
>
>    Why not use count() accumulate function? ;)
>
> from accumulate( Criteria( this memberOf d, this memberOf q
> ),
>                           
> count(1) )
>
>    Edson
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> In this case the accumulate clause
> is maintaining a counter (total) that's incremented
> whenever a Criteria is detected that is contained in both
> the Data and Query object matched in the rule.  So:
>
>
>
>
> # Find Criteria that are contained in both the Data and
> Query
>
> from accumulate( Criteria( this memberOf d,
> this memberOf q ),
>
> # Initialize the counter to 0
>
>   init( int total = 0; ),
>
> # Increment when the above condition is  matched
>
>   action( total ++; ),
>
> # Decrement if a matched Criteria now fails to match
>
>   reverse( total --; ),
>
> # return the total when all known Criteria are matched
>
>   result( total ) )
>
>
>
> --- On Sun, 11/8/09, Wishing Carebear <[hidden email]>
> wrote:
>
>
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: Re: [rules-users] some pointers for
> solution
>
> > To: "Rules Users List" <[hidden email]>
>
> > Date: Sunday, November 8, 2009, 11:39 AM
>
> > Hi Greg:
>
> > I'm trying to understand your first
>
> > solution.
>
> >  
>
> > Ran the project and it works fine. If possible could
>
> > you explain me little bit on :
>
> >
>
> > from accumulate( Criteria( this memberOf d,
>
> > this memberOf q ),
>
> > init( int total = 0; ),
>
> > action( total ++; ),
>
> > reverse( total --; ),
>
> > result( total ) )
>
> >  
>
> >  
>
> > Thanks,
>
> > cabear
>
> >
>
> >
>
> > 2009/11/8 Greg Barton <[hidden email]>
>
> >
>
> > There are a couple of
>
> > ways to do this.  I'm sure there's a bit more
> clean
>
> > way than the example I'm providing, but this
> should get
>
> > you in the right direction.  It's not 100%
> rules,
>
> > because it involves a bit of java collections
> trickery. (See
>
> > attached project,
> collection_DroolsCriteriaMatch.tar.gz)
>
> >
>
> >
>
> > The heart of it is a single rule:
>
> >
>
> > rule "Match"
>
> >  when
>
> >    d : Data()
>
> >    q : Query( size <= d.size )
>
> >    Number( intValue == q.size )
>
> >    from accumulate(
>
> >      Criteria( this memberOf d, this memberOf q ),
>
> >
>
> >      init( int total = 0; ),
>
> >      action( total ++; ),
>
> >      reverse( total --; ),
>
> >      result( total )
>
> >    )
>
> >  then
>
> >    System.out.println("Match: " + d +
> "
>
> > and " + q) ;
>
> > end
>
> >
>
> > The Data object holds data to be queried, Query
> objects are
>
> > asserted to match the Data, and Criteria objects can
> be
>
> > contained in either. (With the aforementioned
> collections
>
> > trickery that if a Criteria is contained in a Query it
> can
>
> > be found in a Data object, but the reverse isn't
> true.
>
> >  See the Query.contains(Object) method for how
> that's
>
> > implemented.)
>
> >
>
> >
>
> > So the rule above basically says "There's a
> Data
>
> > object, and all of the Query objects Criteria are
> contained
>
> > in the Data object."
>
> >
>
> > There's an alternate way of doing this using eval
> and a
>
> > bit more java fu.  See the
> eval_DroolsCriteriaMatch.tar.gz
>
> > project attached.  This one's probably not
> optimal,
>
> > though, as it's basically a brute force check of
> all
>
> > Data objects against the asserted Query.
>
> >
>
> >
>
> > I tried for a while to get a solution working with
>
> > different criteria types from both Data and Query
> objects
>
> > being asserted into working memory, but I couldn't
> get
>
> > the accumulate syntax right.  Anyone know of a way to
> do
>
> > that? (I figure that would get a "pure
> rules"
>
> > solution.)
>
> >
>
> >
>
> > --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
>
> > wrote:
>
> >
>
> > > From: Wishing Carebear <[hidden email]>
>
> >
>
> > > Subject: [rules-users] some pointers for
> solution
>
> > > To: [hidden email]
>
> > > Date: Saturday, November 7, 2009, 10:19 PM
>
> >
>
> >
>
> >
>
> > > Hello:
>
> > > There are n selection criteria from s1 .. sn for
> each
>
> > > item i1.. in. Each item can have a subset of
> criteria
>
> > which
>
> > > applies to them.
>
> > >  
>
> > > The end user, can choose a subset of criteria
> like c1
>
> >
>
> > > and c5 and only the item that has c1 and c5
> valid
>
> > should be
>
> > > returned. For example: if item i1 and i2 have
>
> > criterias
>
> > > valid for c1, c2, c5, c6, c8 since the request is
> only
>
> > for
>
> > > criteria c1 and c5, i1 and i2 must be returned.
>
> >
>
> > >
>
> > >  
>
> > > Is it possible to write a rule using drools for
> this
>
> > > requirement.
>
> > >  
>
> > > Thanks for your help and time,
>
> > > cabear
>
> > >
>
> > > -----Inline Attachment Follows-----
>
> >
>
> > >
>
> > > _______________________________________________
>
> > > rules-users mailing list
>
> > > [hidden email]
>
> > > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
> > >
>
> >
>
> >
>
> >      
>
> > _______________________________________________
>
> > rules-users mailing list
>
> > [hidden email]
>
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
> >
>
> >
>
> >
>
> >
>
> > -----Inline Attachment Follows-----
>
> >
>
> > _______________________________________________
>
> > rules-users mailing list
>
> > [hidden email]
>
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>
>
>
>
>
>
>
> _______________________________________________
>
> rules-users mailing list
>
> [hidden email]
>
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> --
>   Edson Tirelli
>   JBoss Drools Core Development
>   JBoss by Red Hat @ www.jboss.com
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
In reply to this post by Edson Tirelli-4
Yes Edson, I tried with count and sum. Both seems to be working fine.
 
But with the test case, the Criteria for query also needs to be inserted in addition to the query and data objects like shown below:
 

Query query =

new Query(1);

query.add(

new Criteria(query, "c2", "bas"));

ksession.insert(query);

for(Criteria c : query) {

ksession.insert(c);

}

 
 
Is it possible to avoid them.
 
Thanks,
cabear


2009/11/8 Edson Tirelli <[hidden email]>

   Why not use count() accumulate function? ;)


from accumulate( Criteria( this memberOf d, this memberOf q ),
                           count(1) )

   Edson


2009/11/8 Greg Barton <[hidden email]>
In this case the accumulate clause is maintaining a counter (total) that's incremented whenever a Criteria is detected that is contained in both the Data and Query object matched in the rule.  So:

# Find Criteria that are contained in both the Data and Query
from accumulate( Criteria( this memberOf d, this memberOf q ),
# Initialize the counter to 0
 init( int total = 0; ),
# Increment when the above condition is  matched
 action( total ++; ),
# Decrement if a matched Criteria now fails to match
 reverse( total --; ),
# return the total when all known Criteria are matched
 result( total ) )

--- On Sun, 11/8/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Sunday, November 8, 2009, 11:39 AM
> Hi Greg:
> I'm trying to understand your first
> solution.
>  
> Ran the project and it works fine. If possible could
> you explain me little bit on :
>
> from accumulate( Criteria( this memberOf d,
> this memberOf q ),

> init( int total = 0; ),
> action( total ++; ),
> reverse( total --; ),
> result( total ) )
>  
>  
> Thanks,
> cabear
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> There are a couple of
> ways to do this.  I'm sure there's a bit more clean
> way than the example I'm providing, but this should get
> you in the right direction.  It's not 100% rules,
> because it involves a bit of java collections trickery. (See
> attached project, collection_DroolsCriteriaMatch.tar.gz)
>
>
> The heart of it is a single rule:
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>    Number( intValue == q.size )
>    from accumulate(
>      Criteria( this memberOf d, this memberOf q ),
>
>      init( int total = 0; ),
>      action( total ++; ),
>      reverse( total --; ),
>      result( total )
>    )
>  then
>    System.out.println("Match: " + d + "
> and " + q) ;
> end
>
> The Data object holds data to be queried, Query objects are
> asserted to match the Data, and Criteria objects can be
> contained in either. (With the aforementioned collections
> trickery that if a Criteria is contained in a Query it can
> be found in a Data object, but the reverse isn't true.
>  See the Query.contains(Object) method for how that's
> implemented.)
>
>
> So the rule above basically says "There's a Data
> object, and all of the Query objects Criteria are contained
> in the Data object."
>
> There's an alternate way of doing this using eval and a
> bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz
> project attached.  This one's probably not optimal,
> though, as it's basically a brute force check of all
> Data objects against the asserted Query.
>
>
> I tried for a while to get a solution working with
> different criteria types from both Data and Query objects
> being asserted into working memory, but I couldn't get
> the accumulate syntax right.  Anyone know of a way to do
> that? (I figure that would get a "pure rules"
> solution.)
>
>
> --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: [rules-users] some pointers for solution
> > To: [hidden email]
> > Date: Saturday, November 7, 2009, 10:19 PM
>
>
>
> > Hello:
> > There are n selection criteria from s1 .. sn for each
> > item i1.. in. Each item can have a subset of criteria
> which
> > applies to them.
> >  
> > The end user, can choose a subset of criteria like c1
>
> > and c5 and only the item that has c1 and c5 valid
> should be
> > returned. For example: if item i1 and i2 have
> criterias
> > valid for c1, c2, c5, c6, c8 since the request is only
> for
> > criteria c1 and c5, i1 and i2 must be returned.
>
> >
> >  
> > Is it possible to write a rule using drools for this
> > requirement.
> >  
> > Thanks for your help and time,
> > cabear
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>      
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>




_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
In reply to this post by Greg Barton
Hi Greg:
Is it possible to use decision table to populate the Data object that contains the criteria list information.
 
Thanks,
Ravi

2009/11/8 Greg Barton <[hidden email]>
There are a couple of ways to do this.  I'm sure there's a bit more clean way than the example I'm providing, but this should get you in the right direction.  It's not 100% rules, because it involves a bit of java collections trickery. (See attached project, collection_DroolsCriteriaMatch.tar.gz)

The heart of it is a single rule:

rule "Match"
 when
   d : Data()
   q : Query( size <= d.size )
   Number( intValue == q.size )
   from accumulate(
     Criteria( this memberOf d, this memberOf q ),
     init( int total = 0; ),
     action( total ++; ),
     reverse( total --; ),
     result( total )
   )
 then
   System.out.println("Match: " + d + " and " + q) ;
end

The Data object holds data to be queried, Query objects are asserted to match the Data, and Criteria objects can be contained in either. (With the aforementioned collections trickery that if a Criteria is contained in a Query it can be found in a Data object, but the reverse isn't true.  See the Query.contains(Object) method for how that's implemented.)

So the rule above basically says "There's a Data object, and all of the Query objects Criteria are contained in the Data object."

There's an alternate way of doing this using eval and a bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz project attached.  This one's probably not optimal, though, as it's basically a brute force check of all Data objects against the asserted Query.

I tried for a while to get a solution working with different criteria types from both Data and Query objects being asserted into working memory, but I couldn't get the accumulate syntax right.  Anyone know of a way to do that? (I figure that would get a "pure rules" solution.)

--- On Sat, 11/7/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: [rules-users] some pointers for solution
> To: [hidden email]
> Date: Saturday, November 7, 2009, 10:19 PM
> Hello:
> There are n selection criteria from s1 .. sn for each
> item i1.. in. Each item can have a subset of criteria which
> applies to them.
>  
> The end user, can choose a subset of criteria like c1
> and c5 and only the item that has c1 and c5 valid should be
> returned. For example: if item i1 and i2 have criterias
> valid for c1, c2, c5, c6, c8 since the request is only for
> criteria c1 and c5, i1 and i2 must be returned.
>
>  
> Is it possible to write a rule using drools for this
> requirement.
>  
> Thanks for your help and time,
> cabear
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Greg Barton

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Funny you should bring that up, I was just having this debate with a co-worker. :)

A decision table is a means for defining rules, not working memory objects.  So no, out of the box a decision table as it's defined in drools (and other rule management systems) would not serve that purpose.  However, there's no reason why you couldn't parse a spreadsheet (or other tabular data format) to generate Data objects.

Now, are you sure it's Data objects you want to generate?  I'm guessing from how your question was phrased that it's Query objects you'd like to generate.  In that case the answer to the question is still no, but...if you use Wolfgang's approach to solve the problem (i.e. defining the queries in the rules themselves, and not in a working memory object) then using a decision table is appropriate.  In fact, it's probably the best way to define the rules. (It's most compact and readable when you have many rules with a repetitive structure.)

--- On Wed, 11/11/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Wednesday, November 11, 2009, 3:38 PM
> Hi Greg:
> Is it possible to use decision table to populate the
> Data object that contains the criteria list
> information.
>  
> Thanks,
> Ravi
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> There
> are a couple of ways to do this.  I'm sure there's
> a bit more clean way than the example I'm providing, but
> this should get you in the right direction.  It's not
> 100% rules, because it involves a bit of java collections
> trickery. (See attached project,
> collection_DroolsCriteriaMatch.tar.gz)
>
>
> The heart of it is a single rule:
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>    Number( intValue == q.size )
>    from accumulate(
>      Criteria( this memberOf d, this memberOf q ),
>
>      init( int total = 0; ),
>      action( total ++; ),
>      reverse( total --; ),
>      result( total )
>    )
>  then
>    System.out.println("Match: " + d + "
> and " + q) ;
> end
>
> The Data object holds data to be queried, Query objects are
> asserted to match the Data, and Criteria objects can be
> contained in either. (With the aforementioned collections
> trickery that if a Criteria is contained in a Query it can
> be found in a Data object, but the reverse isn't true.
>  See the Query.contains(Object) method for how that's
> implemented.)
>
>
> So the rule above basically says "There's a Data
> object, and all of the Query objects Criteria are contained
> in the Data object."
>
> There's an alternate way of doing this using eval and a
> bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz
> project attached.  This one's probably not optimal,
> though, as it's basically a brute force check of all
> Data objects against the asserted Query.
>
>
> I tried for a while to get a solution working with
> different criteria types from both Data and Query objects
> being asserted into working memory, but I couldn't get
> the accumulate syntax right.  Anyone know of a way to do
> that? (I figure that would get a "pure rules"
> solution.)
>
>
> --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: [rules-users] some pointers for solution
> > To: [hidden email]
> > Date: Saturday, November 7, 2009, 10:19 PM
>
>
>
> > Hello:
> > There are n selection criteria from s1 .. sn for each
> > item i1.. in. Each item can have a subset of criteria
> which
> > applies to them.
> >  
> > The end user, can choose a subset of criteria like c1
>
> > and c5 and only the item that has c1 and c5 valid
> should be
> > returned. For example: if item i1 and i2 have
> criterias
> > valid for c1, c2, c5, c6, c8 since the request is only
> for
> > criteria c1 and c5, i1 and i2 must be returned.
>
> >
> >  
> > Is it possible to write a rule using drools for this
> > requirement.
> >  
> > Thanks for your help and time,
> > cabear
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>      
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Thanks for your reply Greg.
 
Actually I have 2 requirements:
 
1) Define the data objects in the rule itself so that the business user can define\modify the data objects
2) have a rule that can evalaute the data objects against the criteria the user requests..
 
It is my bad I started with the 2nd requirement :(
 
Regards,
cabear
On Wed, Nov 11, 2009 at 1:50 PM, Greg Barton <[hidden email]> wrote:
Funny you should bring that up, I was just having this debate with a co-worker. :)

A decision table is a means for defining rules, not working memory objects.  So no, out of the box a decision table as it's defined in drools (and other rule management systems) would not serve that purpose.  However, there's no reason why you couldn't parse a spreadsheet (or other tabular data format) to generate Data objects.

Now, are you sure it's Data objects you want to generate?  I'm guessing from how your question was phrased that it's Query objects you'd like to generate.  In that case the answer to the question is still no, but...if you use Wolfgang's approach to solve the problem (i.e. defining the queries in the rules themselves, and not in a working memory object) then using a decision table is appropriate.  In fact, it's probably the best way to define the rules. (It's most compact and readable when you have many rules with a repetitive structure.)

--- On Wed, 11/11/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Wednesday, November 11, 2009, 3:38 PM
> Hi Greg:
> Is it possible to use decision table to populate the
> Data object that contains the criteria list
> information.
>  
> Thanks,
> Ravi
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> There
> are a couple of ways to do this.  I'm sure there's
> a bit more clean way than the example I'm providing, but
> this should get you in the right direction.  It's not
> 100% rules, because it involves a bit of java collections
> trickery. (See attached project,
> collection_DroolsCriteriaMatch.tar.gz)
>
>
> The heart of it is a single rule:
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>    Number( intValue == q.size )
>    from accumulate(
>      Criteria( this memberOf d, this memberOf q ),
>
>      init( int total = 0; ),
>      action( total ++; ),
>      reverse( total --; ),
>      result( total )
>    )
>  then
>    System.out.println("Match: " + d + "
> and " + q) ;
> end
>
> The Data object holds data to be queried, Query objects are
> asserted to match the Data, and Criteria objects can be
> contained in either. (With the aforementioned collections
> trickery that if a Criteria is contained in a Query it can
> be found in a Data object, but the reverse isn't true.
>  See the Query.contains(Object) method for how that's
> implemented.)
>
>
> So the rule above basically says "There's a Data
> object, and all of the Query objects Criteria are contained
> in the Data object."
>
> There's an alternate way of doing this using eval and a
> bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz
> project attached.  This one's probably not optimal,
> though, as it's basically a brute force check of all
> Data objects against the asserted Query.
>
>
> I tried for a while to get a solution working with
> different criteria types from both Data and Query objects
> being asserted into working memory, but I couldn't get
> the accumulate syntax right.  Anyone know of a way to do
> that? (I figure that would get a "pure rules"
> solution.)
>
>
> --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: [rules-users] some pointers for solution
> > To: [hidden email]
> > Date: Saturday, November 7, 2009, 10:19 PM
>
>
>
> > Hello:
> > There are n selection criteria from s1 .. sn for each
> > item i1.. in. Each item can have a subset of criteria
> which
> > applies to them.
> >  
> > The end user, can choose a subset of criteria like c1
>
> > and c5 and only the item that has c1 and c5 valid
> should be
> > returned. For example: if item i1 and i2 have
> criterias
> > valid for c1, c2, c5, c6, c8 since the request is only
> for
> > criteria c1 and c5, i1 and i2 must be returned.
>
> >
> >  
> > Is it possible to write a rule using drools for this
> > requirement.
> >  
> > Thanks for your help and time,
> > cabear
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>      
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>




_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Wishing Carebear

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
Hi Greg:
Looks like Excel may hep to pppulate the data objects but running into only problem. Don't know how to insert and update the dataobject in the same excel file.
 
In other words, want to write the following rule in Excel:
 
if
    eval(true)
then
     Data d = new Data();
     d.setAttr1("attr1");
     d.setAttr2("attr1");
     insert(d);
 
Thanks,
cabear

On Wed, Nov 11, 2009 at 3:42 PM, Wishing Carebear <[hidden email]> wrote:
Thanks for your reply Greg.
 
Actually I have 2 requirements:
 
1) Define the data objects in the rule itself so that the business user can define\modify the data objects
2) have a rule that can evalaute the data objects against the criteria the user requests..
 
It is my bad I started with the 2nd requirement :(
 
Regards,
cabear
On Wed, Nov 11, 2009 at 1:50 PM, Greg Barton <[hidden email]> wrote:
Funny you should bring that up, I was just having this debate with a co-worker. :)

A decision table is a means for defining rules, not working memory objects.  So no, out of the box a decision table as it's defined in drools (and other rule management systems) would not serve that purpose.  However, there's no reason why you couldn't parse a spreadsheet (or other tabular data format) to generate Data objects.

Now, are you sure it's Data objects you want to generate?  I'm guessing from how your question was phrased that it's Query objects you'd like to generate.  In that case the answer to the question is still no, but...if you use Wolfgang's approach to solve the problem (i.e. defining the queries in the rules themselves, and not in a working memory object) then using a decision table is appropriate.  In fact, it's probably the best way to define the rules. (It's most compact and readable when you have many rules with a repetitive structure.)

--- On Wed, 11/11/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Wednesday, November 11, 2009, 3:38 PM
> Hi Greg:
> Is it possible to use decision table to populate the
> Data object that contains the criteria list
> information.
>  
> Thanks,
> Ravi
>
>
> 2009/11/8 Greg Barton <[hidden email]>
>
> There
> are a couple of ways to do this.  I'm sure there's
> a bit more clean way than the example I'm providing, but
> this should get you in the right direction.  It's not
> 100% rules, because it involves a bit of java collections
> trickery. (See attached project,
> collection_DroolsCriteriaMatch.tar.gz)
>
>
> The heart of it is a single rule:
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>    Number( intValue == q.size )
>    from accumulate(
>      Criteria( this memberOf d, this memberOf q ),
>
>      init( int total = 0; ),
>      action( total ++; ),
>      reverse( total --; ),
>      result( total )
>    )
>  then
>    System.out.println("Match: " + d + "
> and " + q) ;
> end
>
> The Data object holds data to be queried, Query objects are
> asserted to match the Data, and Criteria objects can be
> contained in either. (With the aforementioned collections
> trickery that if a Criteria is contained in a Query it can
> be found in a Data object, but the reverse isn't true.
>  See the Query.contains(Object) method for how that's
> implemented.)
>
>
> So the rule above basically says "There's a Data
> object, and all of the Query objects Criteria are contained
> in the Data object."
>
> There's an alternate way of doing this using eval and a
> bit more java fu.  See the eval_DroolsCriteriaMatch.tar.gz
> project attached.  This one's probably not optimal,
> though, as it's basically a brute force check of all
> Data objects against the asserted Query.
>
>
> I tried for a while to get a solution working with
> different criteria types from both Data and Query objects
> being asserted into working memory, but I couldn't get
> the accumulate syntax right.  Anyone know of a way to do
> that? (I figure that would get a "pure rules"
> solution.)
>
>
> --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: [rules-users] some pointers for solution
> > To: [hidden email]
> > Date: Saturday, November 7, 2009, 10:19 PM
>
>
>
> > Hello:
> > There are n selection criteria from s1 .. sn for each
> > item i1.. in. Each item can have a subset of criteria
> which
> > applies to them.
> >  
> > The end user, can choose a subset of criteria like c1
>
> > and c5 and only the item that has c1 and c5 valid
> should be
> > returned. For example: if item i1 and i2 have
> criterias
> > valid for c1, c2, c5, c6, c8 since the request is only
> for
> > criteria c1 and c5, i1 and i2 must be returned.
>
> >
> >  
> > Is it possible to write a rule using drools for this
> > requirement.
> >  
> > Thanks for your help and time,
> > cabear
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>      
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>




_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Greg Barton

Re: some pointers for solution

Reply Threaded More More options
Print post
Permalink
It should be possible to define rules in a decision table that have "true" as their condition, though since I don't use decision tables I can't say for sure.  Then in the action just insert the data.

--- On Thu, 11/12/09, Wishing Carebear <[hidden email]> wrote:

> From: Wishing Carebear <[hidden email]>
> Subject: Re: [rules-users] some pointers for solution
> To: "Rules Users List" <[hidden email]>
> Date: Thursday, November 12, 2009, 12:05 AM
> Hi Greg:
> Looks like Excel may hep to pppulate the data objects
> but running into only problem. Don't know how to insert
> and update the dataobject in the same excel file.
>  
> In other words, want to write the following rule in
> Excel:
>  
> if
>     eval(true)
> then
>      Data d = new Data();
>      d.setAttr1("attr1");
>      d.setAttr2("attr1");
>      insert(d);
>  
> Thanks,
> cabear
>
>
> On Wed, Nov 11, 2009 at 3:42 PM,
> Wishing Carebear <[hidden email]>
> wrote:
>
>
> Thanks for your reply Greg.
>  
> Actually I have 2 requirements:
>  
> 1) Define the data objects in the rule itself so that
> the business user can define\modify the data
> objects
> 2) have a rule that can evalaute the data objects
> against the criteria the user requests..
>  
> It is my bad I started with the 2nd requirement
> :(
>  
> Regards,
> cabear
>
>
>
>
> On Wed, Nov 11, 2009 at 1:50 PM,
> Greg Barton <[hidden email]>
> wrote:
>
> Funny you should bring
> that up, I was just having this debate with a co-worker. :)
>
> A decision table is a means for defining rules, not working
> memory objects.  So no, out of the box a decision table as
> it's defined in drools (and other rule management
> systems) would not serve that purpose.  However,
> there's no reason why you couldn't parse a
> spreadsheet (or other tabular data format) to generate Data
> objects.
>
>
> Now, are you sure it's Data objects you want to
> generate?  I'm guessing from how your question was
> phrased that it's Query objects you'd like to
> generate.  In that case the answer to the question is still
> no, but...if you use Wolfgang's approach to solve the
> problem (i.e. defining the queries in the rules themselves,
> and not in a working memory object) then using a decision
> table is appropriate.  In fact, it's probably the best
> way to define the rules. (It's most compact and readable
> when you have many rules with a repetitive structure.)
>
>
>
> --- On Wed, 11/11/09, Wishing Carebear <[hidden email]>
> wrote:
>
> > From: Wishing Carebear <[hidden email]>
>
> > Subject: Re: [rules-users] some pointers for
> solution
> > To: "Rules Users List" <[hidden email]>
> > Date: Wednesday, November 11, 2009, 3:38 PM
>
>
>
>
> > Hi Greg:
> > Is it possible to use decision table to populate the
> > Data object that contains the criteria list
> > information.
> >  
> > Thanks,
> > Ravi
> >
> >
> > 2009/11/8 Greg Barton <[hidden email]>
>
> >
> > There
> > are a couple of ways to do this.  I'm sure
> there's
> > a bit more clean way than the example I'm
> providing, but
> > this should get you in the right direction.  It's
> not
>
> > 100% rules, because it involves a bit of java
> collections
> > trickery. (See attached project,
> > collection_DroolsCriteriaMatch.tar.gz)
> >
> >
> > The heart of it is a single rule:
> >
> > rule "Match"
>
> >  when
> >    d : Data()
> >    q : Query( size <= d.size )
> >    Number( intValue == q.size )
> >    from accumulate(
> >      Criteria( this memberOf d, this memberOf q ),
> >
> >      init( int total = 0; ),
>
> >      action( total ++; ),
> >      reverse( total --; ),
> >      result( total )
> >    )
> >  then
> >    System.out.println("Match: " + d +
> "
> > and " + q) ;
> > end
>
> >
> > The Data object holds data to be queried, Query
> objects are
> > asserted to match the Data, and Criteria objects can
> be
> > contained in either. (With the aforementioned
> collections
> > trickery that if a Criteria is contained in a Query it
> can
>
> > be found in a Data object, but the reverse isn't
> true.
> >  See the Query.contains(Object) method for how
> that's
> > implemented.)
> >
> >
> > So the rule above basically says "There's a
> Data
>
> > object, and all of the Query objects Criteria are
> contained
> > in the Data object."
> >
> > There's an alternate way of doing this using eval
> and a
> > bit more java fu.  See the
> eval_DroolsCriteriaMatch.tar.gz
>
> > project attached.  This one's probably not
> optimal,
> > though, as it's basically a brute force check of
> all
> > Data objects against the asserted Query.
> >
> >
> > I tried for a while to get a solution working with
>
> > different criteria types from both Data and Query
> objects
> > being asserted into working memory, but I couldn't
> get
> > the accumulate syntax right.  Anyone know of a way to
> do
> > that? (I figure that would get a "pure
> rules"
>
> > solution.)
> >
> >
> > --- On Sat, 11/7/09, Wishing Carebear <[hidden email]>
> > wrote:
> >
> > > From: Wishing Carebear <[hidden email]>
>
> >
> > > Subject: [rules-users] some pointers for
> solution
> > > To: [hidden email]
> > > Date: Saturday, November 7, 2009, 10:19 PM
>
> >
> >
> >
> > > Hello:
> > > There are n selection criteria from s1 .. sn for
> each
> > > item i1.. in. Each item can have a subset of
> criteria
> > which
> > > applies to them.
>
> > >  
> > > The end user, can choose a subset of criteria
> like c1
> >
> > > and c5 and only the item that has c1 and c5
> valid
> > should be
> > > returned. For example: if item i1 and i2 have
>
> > criterias
> > > valid for c1, c2, c5, c6, c8 since the request is
> only
> > for
> > > criteria c1 and c5, i1 and i2 must be returned.
> >
> > >
> > >  
> > > Is it possible to write a rule using drools for
> this
>
> > > requirement.
> > >  
> > > Thanks for your help and time,
> > > cabear
> > >
> > > -----Inline Attachment Follows-----
> >
> > >
> > > _______________________________________________
>
> > > rules-users mailing list
> > > [hidden email]
> > > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
> > >
> >
> >
> >      
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
>
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> >
> >
> >
> > -----Inline Attachment Follows-----
>
> >
> > _______________________________________________
> > rules-users mailing list
> > [hidden email]
> > https://lists.jboss.org/mailman/listinfo/rules-users
>
> >
>
>
>
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>


     

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
1 2