我对剪辑和课程有很大的问题。我开发了一个小的安全评估剪辑,但是当问问题如果用户想要一个更好的解释,他可以点击一个按钮,他会收到解释。为此,我的系统有这样一个类:
(defclass QUESTION (is-a USER)
(role concrete)
(pattern-match reactive)
(slot id (type STRING))
(slot description (type STRING) (create-accessor read)))一组这样的例子:
(definstances EXPLANATION
(E1 of QUESTION (id "GQ01")(description "Choose YES if you don't know ... ")))要检索系统使用以下操作的描述:
(send (find-instance ((?f QUESTION)) (str-compare ?f:id ?id-question)) get-description)问题是,在执行它时,我会收到以下消息:
[MSGFUN1] No applicable primary message-handlers found for get-description.
[PRCCODE4] Execution halted during the actions of deffunction explain-question.
[PRCCODE4] Execution halted during the actions of deffunction yes-or-no-p.
[PRCCODE4] Execution halted during the actions of defrule ask-for-component-needed.我该怎么解决呢?如果?id问题等于实例的id,则系统将打印与实例相关的描述。
发布于 2016-05-21 16:49:09
函数查找-实例和查找-所有实例返回一个多字段值,如果找到一个实例,否则返回FALSE,因此您需要从多字段中提取实例值(使用nth$)并传递该值以发送而不是多字段。在CLIPS中,布尔值为false,布尔操作将任何非假值视为true。由于str-比较法的返回值是一个整数,如果要在查找实例调用中使用它来查询,则需要使用=或!=显式地将该值与0进行比较。除非您试图对字符串进行词汇排序,否则使用str比较没有多大意义,所以在本例中只需使用eq。
我还建议使用实例操作,而不是查找实例。如果没有找到匹配的问题实例,则需要显式测试nth$/find实例返回的有效值,否则发送的调用将导致错误。
CLIPS> (clear)
CLIPS>
(defclass QUESTION (is-a USER)
(role concrete)
(slot id (type STRING))
(slot description (type STRING)))
CLIPS>
(definstances EXPLANATION
(E1 of QUESTION (id "GQ01")
(description "Choose YES if you don't know ... ")))
CLIPS> (reset)
CLIPS> (bind ?id-question "GQ01")
"GQ01"
CLIPS> (send (find-instance ((?f QUESTION)) (str-compare ?f:id ?id-question)) get-description)
[MSGFUN1] No applicable primary message-handlers found for get-description.
FALSE
CLIPS> (find-instance ((?f QUESTION)) (eq ?f:id ?id-question))
([E1])
CLIPS> (send (nth$ 1 (find-instance ((?f QUESTION)) (eq ?f:id ?id-question))) get-description)
"Choose YES if you don't know ... "
CLIPS> (do-for-instance ((?f QUESTION)) (eq ?f:id ?id-question) ?f:description)
"Choose YES if you don't know ... "
CLIPS> (bind ?id-question "GQ03")
"GQ03"
CLIPS> (send (nth$ 1 (find-instance ((?f QUESTION)) (eq ?f:id ?id-question))) get-description)
[MSGFUN1] No applicable primary message-handlers found for get-description.
FALSE
CLIPS> (do-for-instance ((?f QUESTION)) (eq ?f:id ?id-question) ?f:description)
FALSE
CLIPS>https://stackoverflow.com/questions/37361478
复制相似问题