【发布时间】:2015-08-25 19:01:15
【问题描述】:
我正在尝试用 Drools 替换 Jess,作为我们项目中的反向链接规则引擎。我一直在寻找有关如何使用 Drools 完成反向链接的简单示例。有趣的是,每个站点上只有 1 个相同的 example(我不知道它是 BC,但我们暂时忘记它吧)。
Jess 中非常简单的 BC 示例:
//q is a fact template with a slot named 'n'
//when there's a q with n==8 print something
//I need a q with n==8 to fire a rule so I will insert it myself!
(deftemplate q (slot n))
(do-backward-chaining q)
(defrule printq (q (n 8)) => (printout t "n is eight! yeah!" crlf))
(defrule iNeedn8 (need-q (n 8)) => (assert (q (n 8))))
(reset)
(run 1)
//fires printq and prints to console...
Drools 中的等效项:
package com.example;
declare Q
n : int
end
rule "print q"
when
Q(n == 8)
then
System.out.println("n is eight by drools!");
end
//I'M LOST HERE! HELP!
如何使用 Drools 实现相同的行为?
【问题讨论】:
-
Drools BW 链接与 Jess 的 BW 链接不同,我认为两者都做不到 Prolog 能够做的事情。
-
我不能找到要在 Drools 中触发的规则缺少哪个事实 (Q(n==8)) 吗? (它们的功能不同,jess 在 BWC 中的能力更强?)
-
我同意@laune 的观点,这两个引擎实现 BWC 的方式完全不同,而且 afaik 在这个意义上都没有与 Prolog 相同的功能。但是,该功能正在开发中。它将在稳定后尽快正式记录。
-
@DavideSottara 这个“正式记录为稳定”听起来不错,但问题是:它会被记录吗?