CS 291 University of Puget Sound Spring, 2020
 
Programming Language Paradigms:
Explorations with Functional Problem Solving (supported by Scheme/Haskell)
and Declarative Prblem Solving (supported by Prolog)
 

A Simplified Eliza Program

Scheme Version

One of the early, well-known programs within the field of artificial intelligence was called Eliza, a program by Joseph Weizenbaum. The idea was to simulate conversation between a patient and psycho-therapist, based on a series of patterns and corresponding responses. Although the original program had an extensive sequence of patterns, this assignment focuses on the following five rules:

Pattern     Response Template
---1 my singleWord ---2 me ---3 tell me about your singleWord
---1 i am ---2 i am sorry to hear you are ---2
---1 am i ---2 do you believe you are ---2
---1 you ---2 me --- 3 why do you think i ---2 you
---1 in what way

In this table, the blank spaces in a pattern, denoted by subscripted dashes, can be filled in with any sequence of words. Similarly, singleWord represents exactly one word in a sentence.

Example 1: These patterns might generate the following "conversation," where the responses are indented and in italics:

Sample Dialogue:

well my friend made me come here
    tell me about your friend
he says i am depressed
    i am sorry to hear you are depressed
i think i need help
    in what way
i wonder if you would help me learning to program Scheme
    why do you think i would help you
when i registered for the course i wondered am i crazy
    do you believe you are crazy

Each of these statements and responses follows the template/response patterns given. For example, in the first statement:

well my friend made me come here

The presence of the word my near the start of the sentence with the word me later on corresponds to the first pattern, with the following matches:

Pattern Element     Words from this Sentence
---1 well
my my
singleWord friend
---2 made
me me
---3 come here

After identifying these pattern elements for the first pattern, the Eliza program uses the corresponding response template. In this case, the program prints "Tell me about your friend". The first four of these words come directly from the template. For the final word, singleWord in the template was matched with the word "friend" in the above analysis.

Example 2: Consider the statement:

My friend said i am nice.

Although this sentence starts with the word my, the word me does not appear later in the text, so the first pattern (my --- me) does not apply. Rather, the response should be based on the second pattern (i am --- ).

Historical Note

Although this approach may seem simple today, Joseph Weizenbaum used this approach as the basis for his widely heralded Eliza in 1966. In 1976, Weizenbaum noted he "was startled to see how quickly and how deeply people conversing with [ Eliza] became emotionally involved" in the conversation. People shared their hopes and secrets, and they became annoyed if other people looked over their shoulders or otherwise interrupted. Even when they knew Eliza was a program, they often talked as if it were a close personal friend.

Exercise

Write a Scheme-based program to solve this Eliza-type pattern-matching problem; that is, a user will type eliza as a procedure name, followed by string containing a sequence of words. The program then would respond with the responce indicated by the above.

For example, following the first pattern above, the command

   (eliza "well my friend made me come here")

would respond with the result:

"tell me about your friend"

Notes/Clarifications:

Some Grading Notes

Since every programming task should yield readable and carefully tested code, the grading of all programs for this course will begin with the following algorithm (expressed in C/Java format):

 if ( (no_comments)
     || (missing pre- or post-conditions)
     || (formatting_does_not_show_structure)
     || (long_procedures_not_divided_into_sections_with_clarifying_comments)
     || (no_evidence_of_compilation)
     || (no_test_plan,__no_listing_of_circumstances__OR__no_listing_of_test_cases)
     || (no_test_runs)
     || (no_commentary_on_correctness)
     || (no_signed_certification_regarding_sources_and_help)
     || (use of Bubble Sort or other non-approved sorting algorithm)
     return (no_grade);