Getting Started With a Response Queue in Eliza
This help file gives an example of the development of a "response queue" for
Eliza. The type of statement that will build the queue is of the form
"I have ....."
and the responses from this queue will take the form
"Earlier you mentioned that you..."
Statements such as these will result in adding statements to a response
queue:
"I have a broken heart" --> adds (a broken heart) to the queue
"I have a sick dog" --> adds (a sick dog) to the queue
"I have a broken leg" --> adds (a broken leg) to the queue
For this example, the responses for each of the statements above would be:
"Earlier you mentioned that you have a broken heart"
"Earlier you mentioned that you have a sick dog"
"Earlier you mentioned that you have a broken leg"
Note that the statement, "I have a broken leg" is changed internally to
"You have a broken leg". This matches the code:
((setf b (match '(you have (* x)) s))
(print-q (append '(how long have you had) (val 'x b) )))
The variable "b" is assigned:
((X a broken heart) (:YES . :YES)) OR
((X a sick dog) (:YES . :YES)) OR
((X a broken leg) (:YES . :YES))
This statement will add the necessary phrase to a response queue:
(push (rest (assoc 'x b)) *have-queue*)
In this case, (defparameter *have-queue* nil) would be at the top of the
program. The section of code from eliza can be expanded:
((setf b (match '(you have (* x)) s))
(print-q (append '(how long have you had) (val 'x b) ))
(push (rest (assoc 'x b)) *have-queue*))
This function will print out a response phrase from the queue *have-queue*:
"Earlier you mentioned that you have a sick dog"
(defun printHaveQueue ()
(let ((phrase (first *have-queue*)))
(format t "EARLIER YOU MENTIONED THAT YOU HAVE ")
(printl (butlast phrase))
(format t "~a.~%" (first (last phrase)))
(setf *have-queue* (append (rest *have-queue*) (list phrase)))
)
)
The last setf adds the dequeued statement back on to the end of the queue.
THe function "random" can be used to alternate between a regular punt statement
and a statement from printHaveQueue()
(t
(if (= (random 2) 0)
(progn
(incf punt-count)
(print-s (punt punt-count))
)
(printHaveQueue)
)
)
In the code above, if the random number is 0, a punt is called. If the random
number is 1, then printHaveQueue() is called.
Create other queues to handle other patterns of input statements.
See the code inserted into the Eliza program here.