首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CLIPS和主要防御消息处理程序

CLIPS和主要防御消息处理程序
EN

Stack Overflow用户
提问于 2016-05-21 10:05:21
回答 1查看 489关注 0票数 0

我对剪辑和课程有很大的问题。我开发了一个小的安全评估剪辑,但是当问问题如果用户想要一个更好的解释,他可以点击一个按钮,他会收到解释。为此,我的系统有这样一个类:

代码语言:javascript
复制
(defclass QUESTION (is-a USER)
(role concrete)
(pattern-match reactive)
(slot id (type STRING))
(slot description (type STRING) (create-accessor read)))

一组这样的例子:

代码语言:javascript
复制
(definstances EXPLANATION
(E1 of QUESTION (id "GQ01")(description "Choose YES if you don't know ... ")))

要检索系统使用以下操作的描述:

代码语言:javascript
复制
(send (find-instance ((?f QUESTION)) (str-compare ?f:id ?id-question)) get-description)

问题是,在执行它时,我会收到以下消息:

代码语言:javascript
复制
[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,则系统将打印与实例相关的描述。

EN

回答 1

Stack Overflow用户

发布于 2016-05-21 16:49:09

函数查找-实例和查找-所有实例返回一个多字段值,如果找到一个实例,否则返回FALSE,因此您需要从多字段中提取实例值(使用nth$)并传递该值以发送而不是多字段。在CLIPS中,布尔值为false,布尔操作将任何非假值视为true。由于str-比较法的返回值是一个整数,如果要在查找实例调用中使用它来查询,则需要使用=或!=显式地将该值与0进行比较。除非您试图对字符串进行词汇排序,否则使用str比较没有多大意义,所以在本例中只需使用eq。

我还建议使用实例操作,而不是查找实例。如果没有找到匹配的问题实例,则需要显式测试nth$/find实例返回的有效值,否则发送的调用将导致错误。

代码语言:javascript
复制
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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37361478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档