hi, Ernest
I am writing some test rules for my project using the example of PC Repair Assistant
as you suggested and when I executed it, it gave this error message: Cannot Redefine
Deftemplate Main::answer... Could you please help me out? Thanks so much!
my code is as follows:
(deftemplate question
"Questions the applet may ask"
(slot text)
(slot type)
(multislot valid)
(slot ident))
(deftemplate answer
(slot ident)
(slot text))
(do-backward-chaining answer)
(defrule MAIN::birthday-woman-50
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text woman))
(answer (ident price) (text <50))
=>
(recommend-action "woman-50-birthday")
(halt))
(defrule MAIN::birthday-woman-100
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text woman))
(answer (ident price) (text 50-100))
=>
(recommend-action "woman-100-birthday")
(halt))
(defrule MAIN::birthday-woman-200
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text woman))
(answer (ident price) (text >100))
=>
(recommend-action "woman-200-birthday")
(halt))
(defrule MAIN::birthday-man-50
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text man))
(answer (ident price) (text <50))
=>
(recommend-action "man-50-birthday")
(halt))
(defrule MAIN::birthday-man-100
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text man))
(answer (ident price) (text 50-100))
=>
(recommend-action "man-100-birthday")
(halt))
(defrule MAIN::birthday-man-200
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text man))
(answer (ident price) (text >100))
=>
(recommend-action "man-200-birthday")
(halt))
(defrule MAIN::birthday-child-50
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text child))
(answer (ident price) (text <50))
=>
(recommend-action "child-50-birthday")
(halt))
(defrule MAIN::birthday-child-100
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text child))
(answer (ident price) (text 50-100))
=>
(recommend-action "child-100-birthday")
(halt))
(defrule MAIN::birthday-child-200
(declare (auto-focus TRUE))
(answer (ident reason) (text birthday))
(answer (ident reciever) (text child))
(answer (ident price) (text >100))
=>
(recommend-action "child-200-birthday")
(halt))
(defrule MAIN::anniversary-woman-50
(declare (auto-focus TRUE))
(answer (ident reason) (text anniversary))
(answer (ident reciever2) (text woman))
(answer (ident price) (text <50))
=>
(recommend-action "woman-50-anniversary")
(halt))
(defrule MAIN::anniversary-woman-100
(declare (auto-focus TRUE))
(answer (ident reason) (text anniversary))
(answer (ident reciever2) (text woman))
(answer (ident price) (text 50-100))
=>
(recommend-action "woman-100-anniversary")
(halt))
(defrule MAIN::anniversary-woman-200
(declare (auto-focus TRUE))
(answer (ident reason) (text anniversary))
(answer (ident reciever2) (text woman))
(answer (ident price) (text >100))
=>
(recommend-action "woman-200-anniversary")
(halt))
(defrule MAIN::anniversary-man-50
(declare (auto-focus TRUE))
(answer (ident reason) (text anniversary))
(answer (ident reciever2) (text man))
(answer (ident price) (text <50))
=>
(recommend-action "man-50-anniversary")
(halt))
(defrule MAIN::anniversary-man-100
(declare (auto-focus TRUE))
(answer (ident reason) (text anniversary))
(answer (ident reciever2) (text man))
(answer (ident price) (text 50-100))
=>
(recommend-action "man-100-anniversaryy")
(halt))
(defrule MAIN::anniversary-man-200
(declare (auto-focus TRUE))
(answer (ident reason) (text anniversary))
(answer (ident reciever2) (text man))
(answer (ident price) (text >100))
=>
(recommend-action "man-200-anniversary")
(halt))
(defrule MAIN::wedding-woman-50
(declare (auto-focus TRUE))
(answer (ident reason) (text wedding))
(answer (ident reciever2) (text woman))
(answer (ident price) (text <50))
=>
(recommend-action "woman-50-wedding")
(halt))
(defrule MAIN::wedding-woman-100
(declare (auto-focus TRUE))
(answer (ident reason) (text wedding))
(answer (ident reciever2) (text woman))
(answer (ident price) (text 50-100))
=>
(recommend-action "woman-100-wedding")
(halt))
(defrule MAIN::wedding-woman-200
(declare (auto-focus TRUE))
(answer (ident reason) (text wedding))
(answer (ident reciever2) (text woman))
(answer (ident price) (text >100))
=>
(recommend-action "woman-200-wedding")
(halt))
(defrule MAIN::wedding-man-50
(declare (auto-focus TRUE))
(answer (ident reason) (text wedding))
(answer (ident reciever2) (text man))
(answer (ident price) (text <50))
=>
(recommend-action "man-50-wedding")
(halt))
(defrule MAIN::wedding-man-100
(declare (auto-focus TRUE))
(answer (ident reason) (text wedding))
(answer (ident reciever2) (text man))
(answer (ident price) (text 50-100))
=>
(recommend-action "man-100-wedding")
(halt))
(defrule MAIN::wedding-man-200
(declare (auto-focus TRUE))
(answer (ident reason) (text wedding))
(answer (ident reciever2) (text man))
(answer (ident price) (text >100))
=>
(recommend-action "man-200-wedding")
(halt))
(defrule MAIN::holiday-valentine-50
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text valentine))
(answer (ident price) (text <50))
=>
(recommend-action "holiday-valentine-50")
(halt))
(defrule MAIN::holiday-valentine-100
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text valentine))
(answer (ident price) (text 50-100))
=>
(recommend-action "holiday-valentine-100")
(halt))
(defrule MAIN::holiday-valentine-200
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text valentine))
(answer (ident price) (text >100))
=>
(recommend-action "holiday-valentine-200")
(halt))
(defrule MAIN::holiday-mother's_day-50
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text mother's_day))
(answer (ident price) (text <50))
=>
(recommend-action "holiday-mother's_day-50")
(halt))
(defrule MAIN::holiday-mother's_day-100
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text mother's_day))
(answer (ident price) (text 50-100))
=>
(recommend-action "holiday-mother's_day-100")
(halt))
(defrule MAIN::holiday-mother's_day-200
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text mother's_day))
(answer (ident price) (text >100))
=>
(recommend-action "holiday-mother's_day-200")
(halt))
(defrule MAIN::holiday-father's_day-50
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text father's_day))
(answer (ident price) (text <50))
=>
(recommend-action "holiday-father's_day-50")
(halt))
(defrule MAIN::holiday-father's_day-100
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text father's_day))
(answer (ident price) (text 50-100))
=>
(recommend-action "holiday-father's_day-100")
(halt))
(defrule MAIN::holiday-father's_day-200
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text father's_day))
(answer (ident price) (text >100))
=>
(recommend-action "holiday-father's_day-200")
(halt))
(defrule MAIN::holiday-christmas-50
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text christmas))
(answer (ident price) (text <50))
=>
(recommend-action "holiday-christmas-50")
(halt))
(defrule MAIN::holiday-christmas-100
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text christmas))
(answer (ident price) (text 50-100))
=>
(recommend-action "holiday-christmas-100")
(halt))
(defrule MAIN::holiday-christmas-200
(declare (auto-focus TRUE))
(answer (ident reason) (text holiday))
(answer (ident holiday) (text christmas))
(answer (ident price) (text >100))
=>
(recommend-action "holiday-christmas-200")
(halt))
(deffacts MAIN::question-data
(question
(ident reason) (type multi) (valid birthday anniversary wedding holiday)
(text "What's this gift for, birthday, anniversary, wedding or holiday?"))
(question (ident receiver)
(type multi) (valid Woman Man Child)
(text "Who is the recievor of this gift?"))
(question (ident receiver2)
(type multi) (valid Woman Man)
(text "Who is the recievor of this gift?"))
(question
(ident price) (type multi) (valid <50 50-100 >100)
(text "What is the price range of this gift?"))
(question
(ident holiday) (type multi) (valid valentine mother's_day father's_day
christmas)
(text "Which holiday gift is it"))
(MAIN::ask gift) )
(deffunction recommend-action (?action)
"Give final instructions to the user"
(printout t "I recommend that you " ?action crlf))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmodule trigger)
(defrule trigger::supply-answers
(declare (auto-focus TRUE))
(MAIN::need-answer (ident ?id))
(not (MAIN::answer (ident ?id)))
(not (MAIN::ask ?))
=>
(assert (MAIN::ask ?id))
(return))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmodule ask)
(defrule ask::ask-question-by-id
"Ask a question and assert the answer"
(declare (auto-focus TRUE))
(MAIN::question (ident ?id) (text ?text)
(valid $?valid) (type ?type))
(not (MAIN::answer (ident ?id)))
?ask <- (MAIN::ask ?id)
=>
(retract ?ask)
(bind ?answer (ask-user ?text ?type ?valid))
(assert (answer (ident ?id) (text ?answer)))
(return))
(deffunction ask-user (?question ?type ?valid)
"Ask a question, and return the answer"
(bind ?answer "")
(while (not (is-of-type ?answer ?type ?valid)) do
(printout t ?question " ")
(if (eq ?type multi) then
(printout t crlf "Valid answers are ")
(foreach ?item ?valid
(printout t ?item " "))
(printout t ":"))
(bind ?answer (read)))
(return ?answer))
(deffunction is-of-type (?answer ?type ?valid)
"Check that the answer has the right form"
(if (eq ?type multi) then
(foreach ?item ?valid
(if (eq (sym-cat ?answer) (sym-cat ?item)) then
(return TRUE)))
(return FALSE))
(if (eq ?type number) then
(return (is-a-number ?answer)))
;; plain text
(return (> (str-length ?answer) 0)))
(deffunction is-a-number (?value)
"Return TRUE if ?value is a number"
(try
(integer ?value)
(return TRUE)
catch
(return FALSE)))
(reset)
(run)
!!!!
Best Regards,
Yingying Chen
2003-11-05
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------