I would like to implement simple rules based on the less and greater values in drools using decision table.
It is easy enough to implement the rules in drl, for example:
rules "less than"
when Example(value < 10)
then
System.out.println("Less than 10")
end
rules "equals"
when Example(value = 10)
then
System.out.println("Equals 10")
end
rules "greater than"
when Example(value > 10)
then
System.out.println("Greater than 10")
end
But how can I translate it into decision table in drools? All the examples I have seen so far is to have the comparison done in condition cell. Is it even possible to do the comparison in value cell?
All example I had seen are in format of:
CONDITION | ACTION
Example |
value |
-----------------------------------|-------------------------------------
10 | System.out.println("equals to 10")
But that only applies to 1 rule, and doing the following totally has different meaning:
CONDITION | CONDITION | CONDITION | ACTION
Example
value | value > $1 | value < $1 |
-----------+------------+------------+----------------
10 | 10 | 10 | ???
Is even possible to do the following?
CONDITION | ACTION
Example |
value |
-----------------------------------+----------------------------------------
10 | System.out.println("equals to 10")
> 10 | System.out.println("greater than 10")
< 10 | System.out.println("less than 10")
What is the right way to implement these rules?
I found out that I can achieve what I needed by putting just $param in the constraint field cell and put in the whole constraint in the value cells. So the decision table looks like this:
CONDITION | ACTION
Example |
$param | System.out.println("$param");
-------------------------------+-----------------------------------
value == 10 | equals to 10
value > 10 | greater than 10
value < 10 | less than 10
It is possible to give the part of the condition as a value. In the header you can give "value $param" to evaluate. (BTW to be able to enter values like == 10 you have to change the cell format to Text in Excel)
CONDITION | ACTION
Example |
value $param |
-----------------------------------+----------------------------------------
== 10 | System.out.println("equals to 10")
in (10, 11) | System.out.println("is 10 or 11")
> 10 | System.out.println("greater than 10")
< 10 | System.out.println("less than 10")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With