我想基于使用决策表的drools中越来越少的值来实现简单的规则.
在drl中实现规则很容易,例如:
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
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能将它翻译成drools的决策表呢?到目前为止我看到的所有例子都是在条件单元格中进行比较.甚至可以在价值单元格中进行比较吗?
我见过的所有例子都是以下格式:
CONDITION | ACTION
Example |
value |
-----------------------------------|-------------------------------------
10 | System.out.println("equals to 10")
Run Code Online (Sandbox Code Playgroud)
但这仅适用于1规则,并且完成以下操作具有不同的含义:
CONDITION | CONDITION | CONDITION | ACTION
Example
value | value > $1 | value < $1 |
-----------+------------+------------+----------------
10 | 10 | 10 | ???
Run Code Online (Sandbox Code Playgroud)
甚至有可能做到以下几点?
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")
Run Code Online (Sandbox Code Playgroud)
实施这些规则的正确方法是什么?
我发现通过在约束字段单元格中放入$ param并在值单元格中放入整个约束,我可以实现我所需要的.所以决策表看起来像这样:
CONDITION | ACTION
Example |
$param | System.out.println("$param");
-------------------------------+-----------------------------------
value == 10 | equals to 10
value > 10 | greater than 10
value < 10 | less than 10
Run Code Online (Sandbox Code Playgroud)
小智 5
可以将条件的一部分作为值.在标题中,您可以给出" value $ param "来评估.(BTW能够输入= = 10之类的值,您必须将单元格格式更改为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")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6294 次 |
最近记录: |