gpt4 book ai didi

剪辑 [EXPRNPSR3] 缺少人员的函数声明

转载 作者:行者123 更新时间:2023-12-01 04:37:55 28 4
gpt4 key购买 nike

; template person

(deftemplate person
(slot name (type STRING))
(slot gender (type SYMBOL)(allowed-symbols m f)); male, female
(slot birthyear (type INTEGER))
(slot birthPlace(type STRING))
(slot Fname (type STRING))
(slot Mname (type STRING))
(multislot siblingsName (type STRING))
(slot spouse (type STRING))
(slot height (type INTEGER))
(slot weight (type INTEGER))
(slot hairColor (type STRING))
(slot eyeColor (type STRING))
(multislot oddHabits (type STRING))
)

; menu

(defrule menu
(declare (salience 9000))
(initial-fact)
=>
(printout t crlf
"Menu : " crlf
" 1- Infer family relations " crlf
" 2- Add additional members " crlf
" 3- Modify properties of already existing members " crlf
" 4- List properties of a specific individual by name or reference. " crlf
" 5- Find for all individuals matching a certain property. " crlf
" 6- Find all individuals matching two properties. " crlf
" 7- Display family relations (same like 1) along with their height comparison." crlf
" 8- exit the program" crlf
"Choose 1 - 8 -> "
)
(assert (task type =(read)))
)

; exit

(defrule Exit
(task type 8)
=>
(exit)
)




(defrule AddMember
(task type 2)
=>
(printout t "Enter Name" crlf)
(bind ?name (read))
(printout t "Enter gender" crlf)
(bind ?G (read))
(printout t "Enter birth year" crlf)
(bind ?BY(read))
(printout t "Enter birth place" crlf)
(bind ?BP(read))
(printout t "Enter Father name " crlf)
(bind ?FN (read))
(printout t "Enter Mother name" crlf)
(bind ?MN(read))
(printout t "Enter siblings" crlf)
(bind ?SI(readline))
(printout t "Enter spouse" crlf)
(bind ?SP (read))
(printout t "Enter height" crlf)
(bind ?H (read))
(assert
(person
(name ?name)(gender ?G)(birthyear ?BY)(birthPlace ?BP)(Fname ?FN)(Mname ?MN)(siblingsName ?SI )(spouse ?SP) (height ?H))
)
)


(defrule Modify
(task type 3)
=>

(printout t " (a) to modify gender" crlf)
(printout t " (b) to modify Birth Year" crlf)
(printout t " (c) to modify Birth Place" crlf)
(printout t " (d) to modify Father Name" crlf)
(printout t " (e) to modify Mother Name" crlf)
(printout t " (f) to modify Spouse" crlf)
(printout t " (g) to modify height" crlf)
(printout t " (h) to modify weight" crlf)
(assert (task type =(read)))
)


(defrule ModifyGender
(task type a)
=>
(printout t "Enter the name of person that you want to modify" crlf)
(bind ?n (read))
(printout t " Enter new value" crlf)
(bind ?V (read))
?num <- (person (name ?n))
(printout t " num is " ?num " " crlf)

(modify ?num (gender ?V))
)

加载项目文件时出现错误:

[EXPRNPSR3] Missing function declaration for person.

错误:

(defrule MAIN::ModifyGender
(task type a)
=>
(printout t "Enter the name of person that you want to modify" crlf)
(bind ?n (read))
(printout t " Enter new value" crlf)
(bind ?V (read))
?num
<-

谁能帮帮我?

最佳答案

匹配事实的模式只允许出现在规则的条件部分,不能出现在规则的 Action 中。您可以使用多个规则来确定要更改的人并应用更改:

(defrule ModifyGender-ask 
?f <- (task type a)
=>
(retract ?f)
(printout t "Enter the name of person that you want to modify" crlf)
(bind ?n (read))
(printout t " Enter new value" crlf)
(bind ?V (read))
(assert (modify-gender ?n ?V)))

(defrule ModifyGender-apply
?f <- (modify-gender ?n ?v)
?num <- (person (name ?n))
=>
(retract ?f)
(modify ?num (gender ?v)))

(defrule ModifyGender-don't-apply
?f <- (modify-gender ?n ?v)
(not (person (name ?n)))
=>
(retract ?f))

或者您可以使用事实集查询功能从规则的 Action 中定位和更改人物:

(defrule ModifyGender 
?f <- (task type a)
=>
(retract ?f)
(printout t "Enter the name of person that you want to modify" crlf)
(bind ?n (read))
(printout t " Enter new value" crlf)
(bind ?V (read))
(if (any-factp ((?p person)) (eq ?p:name ?n))
then
(do-for-fact ((?p person)) (eq ?p:name ?n)
(modify ?p (gender ?V)))
else
(printout t "Person " ?n " does not exist." crlf)))

关于剪辑 [EXPRNPSR3] 缺少人员的函数声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26834152/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com