Clips 检查适当的语法以进行 defrule
Clips Check appropriate syntax for defrule
我正在尝试制作一个程序,询问索赔人是否无家可归、失业没有财产等,并获得 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>
您的语法有几个必须更正的问题。
设计还可以简化(但我不会说这方面)。
以下显示了经过更正的等效版本。
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
我正在尝试制作一个程序,询问索赔人是否无家可归、失业没有财产等,并获得 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>
您的语法有几个必须更正的问题。
设计还可以简化(但我不会说这方面)。
以下显示了经过更正的等效版本。
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