Evaluate boolean expression using Drools' Decision Table

1,013 views
Skip to first unread message

Kashish Sharma

unread,
Aug 17, 2021, 3:19:37 AM8/17/21
to Drools Usage
Hey,

1. I have a boolean expression something like: a && b || c where a,b,c can either be true or false.
Is there a way to directly evaluate such expression in the decision tables?

Right now I am calling a java method to evaluate the expression when rule gets triggered which is using MVEL.
(MVEL.eval(expr)).equals(Boolean.TRUE)

2. Can below mentioned boolean expression be evaluated directly from decision tables, if not can someone suggest how to evaluate such cases:
a==1 && b==3 || c == 'val'?

Thanks and regards,
Kashish

Toshiya Kobayashi

unread,
Aug 17, 2021, 10:07:49 PM8/17/21
to Drools Usage
Hi Kashish,

Let me confirm some information regarding your question.

Firstly, which one do you mean by "decision tables"?


Secondly, you wrote 

> a && b || c where a,b,c can either be true or false.

Drools requires fact objects as inputs. So am I right to assume that you have a fact class like this?
```
public class MyFact {

    private boolean a;
    private boolean b;
    private boolean c;

    // getter/setter
    ...
}
```

Regards,
Toshiya


2021年8月17日火曜日 16:19:37 UTC+9 kas...@zapr.in:
Message has been deleted

Toshiya Kobayashi

unread,
Aug 23, 2021, 12:06:26 AM8/23/21
to Drools Usage
Hi Kashish,

I found your email reply but not in this google-group thread. Have you mistakenly deleted it?

~~~
We are using Excel spreadsheets.

Q. Drools requires fact objects as inputs. So am I right to assume that you have a fact class like this?
A. Yes, you can assume that.

Also, the expression can be a bit complex including braces, etc. e.g a && (b || c)
~~~

I wrote an example:


Sample1.xls demonstrates (a && b || c) case. Rule constraints are evaluated as boolean so you don't need to call MVEL.eval(). You just need to write 

~~~
  MyFact1(a && b || c)
~~~

In case of spreadsheet, as you see in Sample1.xls, simply put

~~~
a && b || c
~~~

in a cell to be replaced for "$param" placeholder. Btw, I think writing a DRL is simpler than a spreadsheet in this case.

Sample2.xls demonstrates (a==1 && b==3 || c == 'val') case. I assume that you will want to put values for 1, 3, val in spreadsheet cells. In this case, I use placeholders $1, $2, $3 so that they will be replaced with the cell values. You can add more rows as you like.

Also you will see SpreadsheetCompiler use in DecisionTableTest.java. It will help you to view the gererated DRLs from your spreadsheet.

Cheers,
Toshiya


2021年8月18日水曜日 11:07:49 UTC+9 Toshiya Kobayashi:
Reply all
Reply to author
Forward
0 new messages