Drools 存在与 "normal" 模式
Drools Exists vs. "normal" pattern
我无法理解为什么 exists
关键字是必需的。
我有以下规则:
1)
rule "normal"
when
Bus( seats > 20 )
then
System.out.println("There is a 20+ bus);
end
2)
rule "with exists"
when
exists Bus( seats > 20 )
then
System.out.println("There is a 20+ bus existing...);
end
第一条规则的 LHS 与第二条规则有何不同?
谢谢!
exists
的 documentation 声明如下
The CE exists is first order logic's existential quantifier and checks
for the existence of something in the Working Memory. Think of
"exists" as meaning "there is at least one..". It is different from
just having the pattern on its own, which is more like saying "for
each one of...". If you use exists with a pattern, the rule will only
activate at most once, regardless of how much data there is in working
memory that matches the condition inside of the exists pattern. Since
only the existence matters, no bindings will be established.
因此,对于您的示例,第一条规则针对每辆超过 20 个座位的公共汽车触发,但第二条规则仅触发一次,即使有超过 20 个座位的公共汽车。
我无法理解为什么 exists
关键字是必需的。
我有以下规则:
1)
rule "normal"
when
Bus( seats > 20 )
then
System.out.println("There is a 20+ bus);
end
2)
rule "with exists"
when
exists Bus( seats > 20 )
then
System.out.println("There is a 20+ bus existing...);
end
第一条规则的 LHS 与第二条规则有何不同?
谢谢!
exists
的 documentation 声明如下
The CE exists is first order logic's existential quantifier and checks for the existence of something in the Working Memory. Think of "exists" as meaning "there is at least one..". It is different from just having the pattern on its own, which is more like saying "for each one of...". If you use exists with a pattern, the rule will only activate at most once, regardless of how much data there is in working memory that matches the condition inside of the exists pattern. Since only the existence matters, no bindings will be established.
因此,对于您的示例,第一条规则针对每辆超过 20 个座位的公共汽车触发,但第二条规则仅触发一次,即使有超过 20 个座位的公共汽车。