我的 Jess 代码中有一些规则,我想修改工作记忆中的两个事实。
已断言的事实是:(assert (analysis (reasons $?c) (total ?t))))
原因$?c
是一个多槽,如果在规则中需要,我想添加到这个多槽。
例如:如果用户喝了太多酒,我想要文本“你喝了太多酒,这是不安全的”。作为字段添加到 multislot (reasons $?c)
。我将如何完成这项任务。我做了很多研究并尝试了几种方法,但它们都无法正常工作。
也许不是最好的方法,但它很简单:
(defrule modify-something
?f <- (analysis (reasons $?c) (total ?t))))
=>
(modify ?f (reasons (create$ ?c "hey"))))
应采取一些预防措施,以免规则循环:
(defrule match
;; (declare (no-loop true))
?t <- (Thing (what ?x))
?b <- (Box (id ?id)(things $?things&:(not (member$ ?x $?things)) ))
=>
(printout t ?id " not contains " ?x crlf)
(modify ?b (things (list $?things ?x)))
)
要么使用 no-loop 子句,要么使用通常被认为更精明的方法,使用确保规则可能添加的项目不在列表中的约束;特别是当一个特定的“原因”可以通过多个规则添加时。