【问题标题】:CLIPS and primary defmessage-handlersCLIPS 和主要的 defmessage-handlers
【发布时间】:2016-05-22 00:49:09
【问题描述】:

我对 CLIPS 和类有一个大问题。 我在 CLIPS 中开发了一个小型安全评估,但是在询问用户是否需要更好的解释时,他可以单击一个按钮,他会收到解释。 为此,我的系统有一个这样的类:

(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-question 等于实例集的 id of an instance,系统将打印与该实例关联的描述。

【问题讨论】:

    标签: clips expert-system


    【解决方案1】:

    函数 find-instance 和 find-all-instances 在找到实例时返回多字段值,否则返回 FALSE,因此您需要从多字段中提取实例值(使用 nth$)并传递发送而不是多字段。同样在 CLIPS 中,布尔 false 值是符号 FALSE,布尔运算将任何非 FALSE 值视为 true。由于 str-compare 的返回值是一个整数,因此如果要在 find-instance 调用中将其用于查询,则需要使用 = 或 != 显式将该值与 0 进行比较。除非您尝试对字符串进行词法排序,否则使用 str-compare 没有多大意义,因此在这种情况下只需使用 eq。

    我还建议使用 do-for-instance 而不是 find-instance。在没有找到匹配的 QUESTION 实例的情况下,您需要显式测试 nth$/find-instance 返回一个有效值,否则调用 send 将导致错误。

    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>
    

    【讨论】:

      猜你喜欢
      • 2016-08-12
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多