如何在 Clips 规则引擎中调试 "Check appropriate syntax for defrule"?
How to debug "Check appropriate syntax for defrule" in Clips rule engine?
(deftemplate illness
(slot sickness)
(multislot keywords))
(deffacts qestion-refrences
(illness (sickness stunted-Groth)(keywords stunted groth))
(illness (sickness pale-Yellow) (keywords pale yellow))
(illness (sickness reddish-Brown)(keywords reddish brown))
(illness (sickness stunted-Root)(keywords stunted root)))
(deffunction askquestion (?question)
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer)))
?answer)
(defrule determineSickness
(bind ?f (askquestion "whot Does the plant seem to have ? "))
(illness (keywords ?kw) (sickness ?sk))
(while (not (subsetp ?kw ?f ))
(bind ?f (askquestion "whot Does the plant seem to have ? ")))
=>
(assert ?sk))
我想做的是简单地询问用户他们的工厂出了什么问题,并使用关键字来识别问题,然后断言问题。但是我不断收到以下错误。
Defining defrule: determineSickness
[PRNTUTIL2] Syntax Error: Check appropriate syntax for defrule.
ERROR:
(defrule MAIN::determineSickness
(bind ?f (
FALSE
CLIPS>
CLIPS 基本编程指南中有有效 CLIPS 语法的 BNF 规范。 defrules 的相关部分是:
<defrule-construct> ::=
(defrule <rule-name> [<comment>]
[<declaration>]
<conditional-element>*
=>
<action>*)
<action> ::= <expression>
<expression> ::= <constant> | <variable> | <function-call>
<function-call> ::= (<function-name> <expression>*)
<conditional-element> ::=
<pattern-CE> |
<assigned-pattern-CE> |
<not-CE> |
<and-CE> |
<or-CE> |
<logical-CE> |
<test-CE> |
<exists-CE> |
<forall-CE>
规则的 when 部分(=> 之前的部分)包含必须由 facts/instances 匹配的条件,以便规则适用。您可以根据规则的条件进行函数调用,但不能使用您尝试过的语法。此外,由于条件可以按非顺序的顺序激活,因此需要在规则的动作中指定必须顺序执行的过程代码(=>之后的部分)。
您可以通过一些更改使您的原始代码在语法上正确:
(defrule determineSickness
(illness (keywords $?kw) (sickness ?sk))
=>
(bind ?f (askquestion "whot Does the plant seem to have ? "))
(while (not (member$ ?f ?kw))
(bind ?f (askquestion "whot Does the plant seem to have ? ")))
(assert (diagnosis ?sk)))
您的规则在语义上仍然不正确。这是他们目前所做的:
For every illness, ask the user to specify one of the symptoms for that illness.
这是他们需要做的:
For every symptom specified by the user, find every illness having that symptom.
(deftemplate illness
(slot sickness)
(multislot keywords))
(deffacts qestion-refrences
(illness (sickness stunted-Groth)(keywords stunted groth))
(illness (sickness pale-Yellow) (keywords pale yellow))
(illness (sickness reddish-Brown)(keywords reddish brown))
(illness (sickness stunted-Root)(keywords stunted root)))
(deffunction askquestion (?question)
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer)))
?answer)
(defrule determineSickness
(bind ?f (askquestion "whot Does the plant seem to have ? "))
(illness (keywords ?kw) (sickness ?sk))
(while (not (subsetp ?kw ?f ))
(bind ?f (askquestion "whot Does the plant seem to have ? ")))
=>
(assert ?sk))
我想做的是简单地询问用户他们的工厂出了什么问题,并使用关键字来识别问题,然后断言问题。但是我不断收到以下错误。
Defining defrule: determineSickness
[PRNTUTIL2] Syntax Error: Check appropriate syntax for defrule.
ERROR:
(defrule MAIN::determineSickness
(bind ?f (
FALSE
CLIPS>
CLIPS 基本编程指南中有有效 CLIPS 语法的 BNF 规范。 defrules 的相关部分是:
<defrule-construct> ::=
(defrule <rule-name> [<comment>]
[<declaration>]
<conditional-element>*
=>
<action>*)
<action> ::= <expression>
<expression> ::= <constant> | <variable> | <function-call>
<function-call> ::= (<function-name> <expression>*)
<conditional-element> ::=
<pattern-CE> |
<assigned-pattern-CE> |
<not-CE> |
<and-CE> |
<or-CE> |
<logical-CE> |
<test-CE> |
<exists-CE> |
<forall-CE>
规则的 when 部分(=> 之前的部分)包含必须由 facts/instances 匹配的条件,以便规则适用。您可以根据规则的条件进行函数调用,但不能使用您尝试过的语法。此外,由于条件可以按非顺序的顺序激活,因此需要在规则的动作中指定必须顺序执行的过程代码(=>之后的部分)。
您可以通过一些更改使您的原始代码在语法上正确:
(defrule determineSickness
(illness (keywords $?kw) (sickness ?sk))
=>
(bind ?f (askquestion "whot Does the plant seem to have ? "))
(while (not (member$ ?f ?kw))
(bind ?f (askquestion "whot Does the plant seem to have ? ")))
(assert (diagnosis ?sk)))
您的规则在语义上仍然不正确。这是他们目前所做的:
For every illness, ask the user to specify one of the symptoms for that illness.
这是他们需要做的:
For every symptom specified by the user, find every illness having that symptom.