4

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 ルールです。

何か案が?

4

2 に答える 2

3

私は可能な解決策の魔女を見つけたと思います:

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さんはどう思いますか?

于 2015-12-17T14:10:15.833 に答える