Drools DSL - 如何在规则中使用括号
Drools DSL - How to use parenthesis in rules
Drools 版本:6.3.0.Final
波乔:
public class Person {
private Integer age;
private Integer childrens;
private String name;
private String address;
(...)
}
DSL 文件:
[condition][]and=&&
[condition][]or=||
[condition][]is less than or equal to=<=
[condition][]is less than=<
[condition][]is greater than or equal to=>=
[condition][]is greater than=>
[condition][]is equal to===
[condition][]There is a [Pp]erson with=$person:Person()
[condition][].{field:\w*} {operator} {value:\d*}={field} {operator} {value}
(...)
DSRL 文件:
package <package>;
import <import class>.*
global org.slf4j.Logger logger;
expander <class>.dsl;
rule "R1"
when
There is a person with
.age is greater than 10 or .chidldrens is less than 2 and .name is equal to "<name>"
then
(...)
end
rule "R2"
when
There is a person with
(.age is greater than 10 or .childrens is less than 2) and .name is equal to "<name>"
then
(...)
end
DRL(来自 R1):
(...)
rule "R1"
when
$person:Person(age > 10 || childrens < 2 && name = "<name>")
then
(...)
end
(...)
DRL(来自R2):没有生成规则。
如果我删除括号,它可以正常工作,但如果有括号,DRL 文件将无法正确生成。所以只有 R2 规则有效,但我的目标是 R1 规则。
有什么想法吗?
应使用以下 DSL 定义:
[condition][]There is a Person with=Person()
[condition][]- :{field:\w*} {operator} {value:\d*}=
{field} {operator} {value}
[condition][]:{field:\w*} {operator} {value:\d*}=
{field} {operator} {value}
# operators as in the question
以及数码单反相机:
rule R1
when
There is a Person with
- :call_count is less than 10 or :name is equal to "Joe"
- :points is greater than 5
then
...
end
这导致
rule R1
when
Person(call_count < 10 || name == "Joe", points > 5)
then
...
end
6.3.0 DSL 扩展器中至少有两个错误。这曾经在 5.5 中有效,但在 DSL 解析中做了一些 "improvement"。您应该在 Drools 错误报告站点上提出一个 JIRA。 (但我认为 Drools 团队不会在 DSL 上花费任何时间或精力,在 6.x 开始工作时,DSL 已被降级为继子。
我想我找到了一个可能的解决方案 是:
DSL 文件(用这个新条件替换):
[condition][]There is a [Pp]erson that {constraints}=$person:Person({constraints})
[condition][]{field:\w*}\s+{operator}\s+{value:\s*}={field} {operator} {value}
DSRL(从第一行开始定义约束):
(...)
There is a person that ((age is greater than 10 or chidldrens is less than 2) and name is equal to "<name>")
(...)
DRL(生成):
(...)
$person:Person((age > 10 || childrens < 2) && name == "name")
(...)
使用这个新的 DSL 定义括号是受支持的,它按预期工作。你怎么看@laune?
Drools 版本:6.3.0.Final
波乔:
public class Person {
private Integer age;
private Integer childrens;
private String name;
private String address;
(...)
}
DSL 文件:
[condition][]and=&&
[condition][]or=||
[condition][]is less than or equal to=<=
[condition][]is less than=<
[condition][]is greater than or equal to=>=
[condition][]is greater than=>
[condition][]is equal to===
[condition][]There is a [Pp]erson with=$person:Person()
[condition][].{field:\w*} {operator} {value:\d*}={field} {operator} {value}
(...)
DSRL 文件:
package <package>;
import <import class>.*
global org.slf4j.Logger logger;
expander <class>.dsl;
rule "R1"
when
There is a person with
.age is greater than 10 or .chidldrens is less than 2 and .name is equal to "<name>"
then
(...)
end
rule "R2"
when
There is a person with
(.age is greater than 10 or .childrens is less than 2) and .name is equal to "<name>"
then
(...)
end
DRL(来自 R1):
(...)
rule "R1"
when
$person:Person(age > 10 || childrens < 2 && name = "<name>")
then
(...)
end
(...)
DRL(来自R2):没有生成规则。
如果我删除括号,它可以正常工作,但如果有括号,DRL 文件将无法正确生成。所以只有 R2 规则有效,但我的目标是 R1 规则。
有什么想法吗?
应使用以下 DSL 定义:
[condition][]There is a Person with=Person()
[condition][]- :{field:\w*} {operator} {value:\d*}=
{field} {operator} {value}
[condition][]:{field:\w*} {operator} {value:\d*}=
{field} {operator} {value}
# operators as in the question
以及数码单反相机:
rule R1
when
There is a Person with
- :call_count is less than 10 or :name is equal to "Joe"
- :points is greater than 5
then
...
end
这导致
rule R1
when
Person(call_count < 10 || name == "Joe", points > 5)
then
...
end
6.3.0 DSL 扩展器中至少有两个错误。这曾经在 5.5 中有效,但在 DSL 解析中做了一些 "improvement"。您应该在 Drools 错误报告站点上提出一个 JIRA。 (但我认为 Drools 团队不会在 DSL 上花费任何时间或精力,在 6.x 开始工作时,DSL 已被降级为继子。
我想我找到了一个可能的解决方案 是:
DSL 文件(用这个新条件替换):
[condition][]There is a [Pp]erson that {constraints}=$person:Person({constraints})
[condition][]{field:\w*}\s+{operator}\s+{value:\s*}={field} {operator} {value}
DSRL(从第一行开始定义约束):
(...)
There is a person that ((age is greater than 10 or chidldrens is less than 2) and name is equal to "<name>")
(...)
DRL(生成):
(...)
$person:Person((age > 10 || childrens < 2) && name == "name")
(...)
使用这个新的 DSL 定义括号是受支持的,它按预期工作。你怎么看@laune?