[rules-users] Convert logic to DRL rules

Bill Zhang billzhang2006 at gmail.com
Mon Feb 19 10:41:38 EST 2007


Hi Vlad,

Thank you for the help.

Unfortunately I can not change the Object Model as these POJOs are not
used only by myself.

Bill Y.

On 2/19/07, Olenin, Vladimir (MOH) <Vladimir.Olenin at moh.gov.on.ca> wrote:
> I guess if you modify the business objects a bit (in quite weird way - I
> think it would be rather a shortcut than a solution) you can implement this
> kind of logic: you need to swap property (zipcode, age, etc) and 'property
> ownner' (Person) objects, so that you'll have:
>
> Person (id)
> ZipCode (id, code)
> Age (id, age)
> Etc
>
> In this case you should be able to write:
>
> Rule X
> When
>        $p: Person($id: id)
>        (
>                ZipCode(id == $id, code == "23456")
>           or ZipCode(id == $id, code == "68590")
>        )
>        And
>        (
>                Age(id == $id, age < 25)
>           Or Age(id == $id, age > 34)
>        )
> Then
>        // do smth using $p
> End
>
>
> Or smth along those lines... Would that work?.....
>
>
> Vlad
>
>
> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org
> [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Bill Zhang
> Sent: 19 February 2007 09:14
> To: Rules Users List
> Subject: Re: [rules-users] Convert logic to DRL rules
>
> Hi Alex,
>
> Thank you for confirming this. Writing such a builder may take us a
> lot of time because our business user is used to free style
> Pascal-like authoring using quite complex logic. For example,
>
> IF
> (
>  (
>  (Person.Age > 35 OR Person.Age < 25) AND
>  (Person.ZipCode =23546 or Person.ZipCode = 68590)
>  )
>  and
>  (
>  (Person.LastOrderPrice > 300 OR
>  (Person.TotalOrderNumber > 2)
>  )
> )
> OR
> (
>  (
>  (Person.LastOrderCategory in ("098", "109") ) AND
>  (Person.ZipCode =74567 or Person.ZipCode = 23765)
>  )
>  and
>  (
>  (Person.LastOrderPrice > 1000 OR
>  (Person.TotalOrderNumber > 1)
>  )
> )
> ...
>
> THEN Person.Status = "KT";
>
> Before I set out to write the builder, I would like to know whether
> the new syntax can handle the above logic? Also, where can I find
> document for the new syntax?
>
> I am also trying to find some existing open source Java library to
> "flatten out" these complex logic - to break these complex logic to
> atomic ones that can be handled by Drools. Do you have any
> recommendation?
>
> Thanks a lot for your help.
>
> Bill Y.
>
>
>
>
> On 2/19/07, Alexander Varakin <avarakin at optonline.net> wrote:
> > We built a Rule Builder which creates drl with all possible
> > combinations. In any case, drl syntax is not exactly business user
> > friendly, so having such builder is not a bad idea.
> > Simple Rule Builder can be implemented as an Excel spreadsheet, which
> > can be easily parsed using POI library and then drl file produced.
> >
> > Steven Williams wrote:
> > > Hi Bill,
> > >
> > > To implement your rules in 3.0.5 you would need to implement a rule
> > > for  each combination of age and zipCode.
> > >
> > > $a : Person(age > 35 zipCode == 23546)
> > > then
> > > $a.setStatus("KT");
> > >
> > > $a : Person(age < 25, zipCode == 23546 )
> > > then
> > > $a.setStatus("KT");
> > >
> > > $a : Person(age > 35, zipCode == 68590)
> > > then
> > > $a.setStatus("KT");
> > >
> > > etc..
> > >
> > > Steve
> > >
> > > On 2/19/07, *Bill Zhang* <billzhang2006 at gmail.com
> > > <mailto:billzhang2006 at gmail.com>> wrote:
> > >
> > >     So Alex, if I only want to use the old syntax that is in production,
> > >     there is no way to implement my seemingly simple logic conditioning?
> > >
> > >     Thanks for your help.
> > >
> > >     On 2/18/07, Alexander Varakin < avarakin at optonline.net
> > >     <mailto:avarakin at optonline.net>> wrote:
> > >     > As far as I know this syntax is new and is available in SVN
> > >     only, you
> > >     > will have to wait till 3.1 is released or take source from SVN
> > >     and build it.
> > >     >
> > >     > Bill Zhang wrote:
> > >     > > Hi Steven,
> > >     > >
> > >     > > Thank you very much for your help. Really appreciate.
> > >     > >
> > >     > > I still got the same error, Unexpected token '|'. I did not
> > >     see "|" in
> > >     > > the document, only saw "||", which is supposed to be used with
> > >     > > columns.
> > >     > >
> > >     > > Ye
> > >     > >
> > >     > > On 2/18/07, Steven Williams < stevenw at objectconsulting.com.au
> > >     <mailto:stevenw at objectconsulting.com.au>> wrote:
> > >     > >> Hi Bill,
> > >     > >>
> > >     > >> I think it should be:
> > >     > >>
> > >     > >> $a : Person(age > 35 | < 25, zipCode == 23546 | == 68590)
> > >     > >>
> > >     > >> Edson, Mark or Michael can probably confirm or correct the
> > >     above syntax.
> > >     > >>
> > >     > >> Make sure you are running of the latest trunk.
> > >     > >>
> > >     > >> cheers
> > >     > >> Steve
> > >     > >>
> > >     > >>
> > >     > >> On 2/18/07, Bill Zhang <billzhang2006 at gmail.com
> > >     <mailto:billzhang2006 at gmail.com>> wrote:
> > >     > >> >
> > >     > >> > I tried:
> > >     > >> >
> > >     > >> > $a : Person(age > 35 || age < 25, zipCode == 23546 || ==
> 68590)
> > >     > >> >
> > >     > >> > Errors:
> > >     > >> > org.drools.rule.InvalidRulePackage : unknown:39:30
> > >     > >> Unexpected token '||'
> > >     > >> > unknown:39:40 mismatched token:
> > >     > >> [@246,1040:1041='<=',<47>,39:40];
> > >     > >> > expecting type '('
> > >     > >> > unknown:39:92 mismatched token:
> > >     > >> [@258,1092:1092='<',<46>,39:92];
> > >     > >> > expecting type '('
> > >     > >> >
> > >     > >> > I also tried
> > >     > >> >
> > >     > >> > $a : Person(age > 35 | age < 25, zipCode == 23546 | == 68590)
> > >     > >> >
> > >     > >> > Pretty much the same error.
> > >     > >> >
> > >     > >> > Based on the document, "||" is only valid for columns...
> > >     > >> >
> > >     > >> >
> > >     > >> > On 2/17/07, Bill Zhang <billzhang2006 at gmail.com
> > >     <mailto:billzhang2006 at gmail.com>> wrote:
> > >     > >> > > Thank you Steve. But I got syntax error using the
> following.
> > >     > >> > >
> > >     > >> > > On 2/17/07, Steven Williams
> > >     <stevenw at objectconsulting.com.au
> > >     <mailto:stevenw at objectconsulting.com.au>> wrote:
> > >     > >> > > > In trunk I think you can use connective constraints:
> > >     > >> > > >
> > >     > >> > > > $a : Person(age > 35 | < 25, zipCode == 23546 | == 68590)
> > >     > >> > > > then
> > >     > >> > > > $a.setStatus("KT");
> > >     > >> > > >
> > >     > >> > > >
> > >     > >> > > >
> > >     > >> > > >
> > >     > >> > > > On 2/18/07, Bill Zhang < billzhang2006 at gmail.com
> > >     <mailto:billzhang2006 at gmail.com>> wrote:
> > >     > >> > > > >
> > >     > >> > > > > Hello,
> > >     > >> > > > >
> > >     > >> > > > > I am a new Drools user trying to convert the
> > >     following simple
> > >     > >> logic
> > >     > >> into
> > >     > >> > > > DRL:
> > >     > >> > > > >
> > >     > >> > > > > IF (Person.Age > 35 OR Person.Age < 25) AND
> > >     (Person.ZipCode =
> > >     > >> 23546
> > >     > >> or
> > >     > >> > > > > Person.ZipCode = 68590)
> > >     > >> > > > > THEN
> > >     > >> > > > > Person.Status = "KT";
> > >     > >> > > > >
> > >     > >> > > > > I found that it is not easy to convert the above
> > >     logic into
> > >     > >> ONE DRL
> > >     > >> rule.
> > >     > >> > > > >
> > >     > >> > > > > I tried something like this
> > >     > >> > > > >
> > >     > >> > > > > when
> > >     > >> > > > > $a: Person(age>35) or Person (age<25)
> > >     > >> > > > > $b: Person(Zipcode==23456) or Person (ZipCode == 68590)
> > >     > >> > > > > $c: $a and $b
> > >     > >> > > > > Then
> > >     > >> > > > > $c.setStatus("KT")
> > >     > >> > > > >
> > >     > >> > > > > But looks like I can not use
> > >     > >> > > > > $c: $a and $b
> > >     > >> > > > > becaue in Drools, you can only bind variable to
> > >     column, not
> > >     > >> to other
> > >     > >> > > > varaibles.
> > >     > >> > > > >
> > >     > >> > > > > Please advise how to do this. I would imagine this
> > >     should be
> > >     > >> quite
> > >     > >> > > > > simple, maybe I missed something quite obvious.
> > >     > >> > > > >
> > >     > >> > > > > I know that I can write custom Java method to do
> > >     this, but if
> > >     > >> I do
> > >     > >> > > > > that, I suppose I lose the power of RETEOO pattern
> > >     matching
> > >     > >> (pattern
> > >     > >> > > > resuing,
> > >     > >> > > > > etc.). So I prefer not to do that.
> > >     > >> > > > >
> > >     > >> > > > > I also understand I can break the above logic into 4
> > >     rules
> > >     > >> and that
> > >     > >> > > > > would be quite easy, but our business user is not used
> to
> > >     > >> think in
> > >     > >> > > > > that way. Also, we have more complex logic than the
> > >     above. So
> > >     > >> what I
> > >     > >> > > > > want is to see if there is a way to convert this
> > >     > >> > > > > kind of logic in ONE DRL rule.
> > >     > >> > > > >
> > >     > >> > > > > Thanks in advance.
> > >     > >> > > > >
> > >     > >> > > > > Bill
> > >     > >> > > > > _______________________________________________
> > >     > >> > > > > rules-users mailing list
> > >     > >> > > > > rules-users at lists.jboss.org
> > >     <mailto:rules-users at lists.jboss.org>
> > >     > >> > > > >
> > >     > >> https://lists.jboss.org/mailman/listinfo/rules-users
> > >     > >> > > > >
> > >     > >> > > >
> > >     > >> > > >
> > >     > >> > > >
> > >     > >> > > > --
> > >     > >> > > > Steven Williams
> > >     > >> > > >
> > >     > >> > > > Supervising Consultant
> > >     > >> > > >
> > >     > >> > > > Object Consulting
> > >     > >> > > > Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501
> > >     > >> > > > stevenw at objectconsulting.com.au
> > >     <mailto:stevenw at objectconsulting.com.au>
> > >     > >> > > > www.objectconsulting.com.au
> > >     <http://www.objectconsulting.com.au>
> > >     > >> > > >
> > >     > >> > > > consulting | development | training | support
> > >     > >> > > > our experience makes the difference
> > >     > >> > > > _______________________________________________
> > >     > >> > > > rules-users mailing list
> > >     > >> > > > rules-users at lists.jboss.org
> > >     <mailto:rules-users at lists.jboss.org>
> > >     > >> > > > https://lists.jboss.org/mailman/listinfo/rules-users
> > >     > >> > > >
> > >     > >> > > >
> > >     > >> > >
> > >     > >> > _______________________________________________
> > >     > >> > rules-users mailing list
> > >     > >> > rules-users at lists.jboss.org
> > >     <mailto:rules-users at lists.jboss.org>
> > >     > >> > https://lists.jboss.org/mailman/listinfo/rules-users
> > >     > >> >
> > >     > >>
> > >     > >>
> > >     > >>
> > >     > >> --
> > >     > >> Steven Williams
> > >     > >>
> > >     > >> Supervising Consultant
> > >     > >>
> > >     > >> Object Consulting
> > >     > >> Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501
> > >     > >> stevenw at objectconsulting.com.au
> > >     <mailto:stevenw at objectconsulting.com.au>
> > >     > >> www.objectconsulting.com.au
> <http://www.objectconsulting.com.au>
> > >     > >>
> > >     > >> consulting | development | training | support
> > >     > >> our experience makes the difference
> > >     > >> _______________________________________________
> > >     > >> rules-users mailing list
> > >     > >> rules-users at lists.jboss.org
> <mailto:rules-users at lists.jboss.org>
> > >     > >> https://lists.jboss.org/mailman/listinfo/rules-users
> > >     > >>
> > >     > >>
> > >     > > _______________________________________________
> > >     > > rules-users mailing list
> > >     > > rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
> > >     > > https://lists.jboss.org/mailman/listinfo/rules-users
> > >     <https://lists.jboss.org/mailman/listinfo/rules-users>
> > >     > >
> > >     >
> > >     > _______________________________________________
> > >     > rules-users mailing list
> > >     > rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
> > >     > https://lists.jboss.org/mailman/listinfo/rules-users
> > >     >
> > >     _______________________________________________
> > >     rules-users mailing list
> > >     rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
> > >     https://lists.jboss.org/mailman/listinfo/rules-users
> > >
> > >
> > >
> > >
> > > --
> > > Steven Williams
> > >
> > > Supervising Consultant
> > >
> > > Object Consulting
> > > Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501
> > > stevenw at objectconsulting.com.au <mailto:stevenw at objectconsulting.com.au>
> > > www.objectconsulting.com.au <http://www.objectconsulting.com.au>
> > >
> > > consulting | development | training | support
> > > our experience makes the difference
> > > ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > rules-users mailing list
> > > rules-users at lists.jboss.org
> > > https://lists.jboss.org/mailman/listinfo/rules-users
> > >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



More information about the rules-users mailing list