clips [EXPRNPSR3] Отсутствует объявление функции для человека

; 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] Отсутствует объявление функции для человека.

Ошибка:

(defrule MAIN :: ModifyGender
(тип задачи a)
=>
(распечатка t "Введите имя человека, которого вы хотите изменить" crlf)
(bind? n (читать))
(распечатка t "Введите новое значение" crlf)
(bind? V (чтение))
? num
‹-

Может кто-нибудь мне помочь?


person Nadine Salem    schedule 09.11.2014    source источник
comment
Нет необходимости добавлять начальный факт к правилу без других условий; он добавляется автоматически в версиях CLIPS до версии 6.3. Первоначальная функциональность была объявлена ​​устаревшей в версии 6.3; он по-прежнему подтверждается сбросом, но правила без условий больше не полагаются на него. В выпуске 6.4 исходный факт больше не утверждается, поэтому правила, которые явно соответствуют этому факту, больше не будут активироваться.   -  person Gary Riley    schedule 03.01.2019


Ответы (1)


Факты, совпадающие с образцами, разрешены только в условной части правила, но не в действиях правила. Вы можете использовать несколько правил, чтобы определить, кого изменить, и применить изменение:

(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))

Или вы можете использовать функции запроса набора фактов, чтобы найти и изменить человека в действиях правила:

(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)))
person Gary Riley    schedule 10.11.2014