Michael Neale <michael.neale <at> gmail.com> writes:

> 
> Hi Jayaram. its probably best to have your rules work off your object model,
> rather then "local" variables as you showed above. If you still need an init
> rule, you can have something with a high salience, and some dummy condition
> to make sure it always fires first.
> 
> Yeah there isn't a way to do "else" at the moment, but I can appreciate the
> need for it in certain cases. Its something that we will look at for version
> 3 for sure.
> 
> Michael.
> 
> On 3/14/06, Jayaram Sreevalsan <jayaramcs <at> gmail.com> wrote:
> >
> > Hello Mark
> >
> > Firstly I would like to appreciate the hard work done on Drools. It is a
> > wonderful project and we are seriously considering it as a possible
> > alternative to the commercial rule engine that we are using now.
> >
> > I have a few queries regarding Drools that I wish to get clarification on.
> >
> > 1) Is there a way in which we can invoke an initialize function to
> > initialize a few variables within the DRL file and use them in the rules.
> >
> > An example of what I expect is
> >
> > <java:functions>
> > int age;
> >
> > public void init(){
> > age = obj.getAge(); // obj is given as an application data
> > }
> >
> > </java:functions>
> >
> > <rule ....
> > <java:condition >age == 24 </java:condition >
> > .........
> > </rule>
> >
> >
> > the init() would be called automatically that would let us do any
> > initialization required.
> >
> > 2) We have a condition and a consequence which is fine. But business users
> > are of the expectation of seeing an If then Else Construct and so a
> > negative
> > consequence would also be required. It is possible to achieve a negative
> > rule by explicitly writing them as negative, but since rules are framed in
> > a
> > forward manner, it becomes a bit complex to deal with when rules are in
> > large numbers.
> >
> > An example of the above case would be
> >
> > <java:condition >age &gt; 25</java:condition >
> > <java:condition >sex == 'M'</java:condition >
> > <java:consequence>
> > </java:consequence>
> >
> > I wanted an error message in case it went wrong , which is not available
> > now.
> > --
> > Thanks and Regards
> > Jayaram C S
> >
> >
> 

Hello Michael 

We have an Object "ShoppingList" that contains a List of "Vegetables"
Each "Vegetable" has a "vitamin" attribute that stores the types of vitamins the
vegetable contains.

The Rule is to be applied on the "ShoppingList" -- The vegetables in the list
should contain all the vitamins for a balanced diet.  In case of deficiency
suggest appropriate vegetables to fulfill the deficiency.

Even though we can handle this rule in many ways, it would be better if we can
write a function to find out all the vitamins that are contained in the list of
vegetables chosen, as soon as the rule is invoked. Then apply that result to the
set of rules.

If we are to invoke a function for computation at each rule, then it will
degrade performance. A function that does initialization would be of great use
in such cases. 

Please advise on the strategy that can be adopted in such cases. 

You did mention about an “else” condition being made available in Drools 3.
Please let me know of the new syntax that might be used for the same. Also how
do we know which condition failed that resulted in the firing of the else
condition. 

 Thanks and Regards
 Jayaram C S

Reply via email to