【问题标题】:Clips OR Statement not firing剪辑或声明未触发
【发布时间】:2016-05-05 02:47:04
【问题描述】:

不确定为什么这不起作用。

(defrule contain-red?
(initial-fact)
=>
(bind ?reply (get-text-from-user "Does it contain x    (y/n?"))
(assert (existing-text ?reply )))

(defrule partOne
(existing-text "y")
 =>
(bind ?reply (get-text-from-user "give me a number"))
(assert (credit-value-bsc-first-result (explode$ ?reply ))))

(defrule partTwo
(existing-text "n")
=>
(bind ?reply (get-text-from-user "give me a number"))
(assert (credit-value-bsc-second-result (explode$ ?reply ))))

(defrule learn-about-120?
(credit-value-bsc-first-result ?n)
(credit-value-bsc-second-result ?x)
(test (or (<= ?n  20) (<= ?x 20)))
=>
(bind ?reply (get-text-from-user  "Reponse here)"))
(assert (learn-about-120-response ?reply )))

我可以让最终规则在不同的场景中使用 and 来工作。将其加载到 wxCLIPS 时不会出现错误,但是当我运行它并输入相关数据时,最终规则不会触发。

【问题讨论】:

  • 不需要在没有其他条件的情况下将初始事实添加到规则中;它会在 6.3 版之前的 CLIPS 版本中自动添加。最初的事实功能在 6.3 版本中已被弃用;它仍然由复位断言,但没有条件的规则不再依赖它。在 6.4 版本中,initial-fact 不再被断言,因此明确匹配该事实的规则将不再被激活。

标签: clips


【解决方案1】:

只有在 existing-text 为“y”时才会创建 credit-value-bc-first-result 事实。仅当现有文本为“n”时才创建事实 credit-value-bc-second-result。如果仅存在一个现有文本事实,则这些条件是互斥的。自从规则学习120?需要这两个事实它不会触发。

这样写规则可能就是你想要的:

(defrule learn-about-120?
   (or (credit-value-bsc-first-result ?n)
       (credit-value-bsc-second-result ?n))
   (test (<= ?n  20))
   =>
   (bind ?reply (get-text-from-user  "Reponse here)"))
   (assert (learn-about-120-response ?reply )))

【讨论】:

  • 谢谢!我感觉变量为空可能是个问题。
猜你喜欢
  • 1970-01-01
  • 2012-10-20
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多