剪辑检查适当的defrule语法

时间:2015-01-13 13:45:15

标签: logic artificial-intelligence clips

我正在尝试制作一个程序,要求申请人无家可归,失业者没有等,并获得1级或2级福利支持作为答案,但我无法在Clips中加载。我收到以下错误

(defrule Claimant
(Claimant-is homeless)
(Claimant-is unemployed)
(Claimant-is nosavings)
(Claimant-is dependants)
(Claimant-is disabled))

(deftemplate Benefit
   (slot benefit))

(defrule Level1
   Claimant(homesless yes) (unemployed yes) (nosavings no) (dependants yes) (disabled yes))
   =>
   (assert (Benefit (benefit level1)))
   (printout t "You get level 1 benefit support" crlf))

(defrule Level2
   Claimant(homesless yes) (unemployed yes) (nosavings no) (dependants no) (disabled no))
   =>
   (assert (Benefit (benefit level2)))
   (printout t "You get level 2 benefit support" crlf))

错误

Defining defrule: Claimant 
[PRNTUTIL2] Syntax Error:  Check appropriate syntax for defrule.

ERROR:
(defrule MAIN::Claimant
   (Claimant-is homeless)
   (Claimant-is unemployed)
   (Claimant-is nosavings)
   (Claimant-is dependants)
   (Claimant-is disabled)
   )
Defining deftemplate: Benefit
Defining defrule: Level1 
[PRNTUTIL2] Syntax Error:  Check appropriate syntax for defrule.

ERROR:
(defrule MAIN::Level1
   Claimant
Defining defrule: Level2 
[PRNTUTIL2] Syntax Error:  Check appropriate syntax for defrule.

ERROR:
(defrule MAIN::Level2
   Claimant
FALSE
CLIPS> 

1 个答案:

答案 0 :(得分:1)

您的语法有几个必须纠正的问题。

设计也可以简化(但我不会谈论这方面)。

以下显示了带有更正的等效版本。

<强> homeless.clp

(deftemplate Claimant
  (slot homeless (type SYMBOL) (allowed-values yes no))
  (slot unemployed (type SYMBOL) (allowed-values yes no))
  (slot nosavings (type SYMBOL) (allowed-values yes no))
  (slot dependants (type SYMBOL) (allowed-values yes no))
  (slot disabled (type SYMBOL) (allowed-values yes no))
)

(deftemplate Benefit
   (slot benefit (type SYMBOL) (allowed-values level1 level2))
)

(defrule Level1
   (Claimant (homeless yes) (unemployed yes) (nosavings no)
             (dependants yes) (disabled yes))
   =>
   (assert (Benefit (benefit level1)))
   (printout t "You get level 1 benefit support" crlf)
)

(defrule Level2
   (Claimant (homeless yes) (unemployed yes) (nosavings no)
             (dependants no) (disabled no))
   =>
   (assert (Benefit (benefit level2)))
   (printout t "You get level 2 benefit support" crlf)
)

现在您可以使用

进行测试
(clear)

(load "homeless.clp")

(assert (Claimant (homeless yes) (unemployed yes) (nosavings no) (dependants no) (disabled no)))

(run) 

并获取

You get level 2 benefit support