(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>
答案 0 :(得分:1)
“CLIPS基本编程指南”中有一个有效CLIPS语法的BNF规范。规则的相关部分是:
<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部分(=&gt;之前的部分)由必须与事实/实例匹配的条件组成,以使规则适用。您可以根据规则的条件进行函数调用,但不能使用您尝试过的语法。此外,由于条件可以按非顺序次序激活,因此必须在规则的操作中指定必须顺序执行的过程代码(=>之后的部分)。
您可以通过一些更改使您的原始代码语法正确:
(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.