[rules-users] explanation on drl usage

Edson Tirelli tirelli at post.com
Fri Apr 6 15:03:37 EDT 2007


   Hi there,

   Best to understand your needs before suggesting, but working simply on
syntax, if you are using trunk, you can do this:

rule "findRelevantResult"
       when
               $resultat : Resultat( ( results.size() > 0 ) )
       then
       end

rule "testPsaId"
       when
               $prestation : Prestation(id == "psaId")
               $prestationFacturable : PrestationFacturable
(prestation==$prestation, $resultat : resultat)
               $result : Result ( doubleValue < 12 )
               Resultat ( this == $resultat , results contains $result )
               Utilisateur ( ( age < 55 || sex != HumanSexType.MALE) )
       then
       end

   Ok, now I made things confuse right? :) Next step for us to get rid of
the double "(" when using only a single predicate.
   Anyone willing to help document and explain the above?

   []s
   Edson

2007/4/6, JLL <jll at labocollard.be>:
>
>
> Hi all,
>
> i'm quiet new in drools (a french speaking so i appologise for my english
> mistakes) and i'm surprise by the folowing problem
> in drools example i found this code ...
>
> Example 3.14. Return Value operator
>
> Person( girlAge : age, sex == "F" )
> Person( age == ( new Integer(girlAge.intValue() + 2) ), sex == 'M' )
>
> This let me think that i can use method of an assigned variable in the
> equality test
>
> this my rule file
>
> package be.labocollard.server.rules ;
>
> import java.lang.Integer;
> import java.lang.Double;
>
> import be.labocollard.server.types.HumanSexType;
> import be.labocollard.server.entities.Result;
> import be.labocollard.server.entities.Resultat;
> import be.labocollard.server.entities.Prestation;
> import be.labocollard.server.entities.PrestationFacturable;
> import be.labocollard.server.entities.Utilisateur;
>
> rule "asserteResultatAndPrestation"
>         when
>                 PrestationFacturable ( $resultat : resultat , $prestation
> : prestation)
>         then
>                 assert ( $resultat );
>                 assert ($prestation);
>         end
>
> rule "findRelevantResult"
>         when
>                 $resultat : Resultat()
>                 eval($resultat.getResults().size()>0)
>         then
>                 assert($resultat.getResults().iterator().next());
>         end
>
> rule "testPsaId"
>         when
>                 $prestation : Prestation(id == "psaId")
>                 $prestationFacturable : PrestationFacturable
> (prestation==$prestation,
> $resultat : resultat)
>                 $result : Result (doubleValue < (new Double(12)))
>
>                 Resultat (id == $resultat.getId(), results contains
> $result )
> >>> this sentence makes problem ...
> >>> and i would like to avoid eval
> >>>             #eval ($resultat.getId()==id &&
> $resultat.getResults().contains($result) )
>
>                 Utilisateur (age < (new Integer(55))) || Utilisateur (sex
> !=
> HumanSexType.MALE)
>         then
>                 retract($prestationFacturable);
>         end
>
> Is there a drools guru to explain my misunderstanding ????
>
> thanks a lot
>
> and thanks to drools developpers for those wonderfull tools
>
> JLL
> --
> View this message in context:
> http://www.nabble.com/explanation-on-drl-usage-tf3535518.html#a9868635
> Sent from the drools - user mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3124-6000
  Mobile: +55 11 9218-4151
  JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070406/c3876f40/attachment.html 


More information about the rules-users mailing list