Drools 存在与 "normal"模式

标签 drools

我在理解 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 与第二条规则有何不同?

谢谢!

最佳答案

documentationexists声明如下

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 个座位的巴士。

关于Drools 存在与 "normal"模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32416411/

相关文章:

eclipse - 在 Eclipse 中安装 Drools Planner

drools - 如何通过 JBOSS Drools 从 List<String> 获取字符串

java - 我如何使用 tomcat7 部署 kie-drools-wb 6.2.0?

java - 如何调用Drools excel决策表函数

java - 使用 Drools Expert 开发专家系统的想法

drools - 使用规则引擎背后的推理

java - 使用 Drools 以结构松散的 JSON 实体形式处理事实的优雅方法?

Drools : Tool for generating . drl 文件或基于 XML 的规则内容

java - Spring Boot JPA .save() 更新所有记录

java - 通过 tomcat 部署 Drools 失败