Assignment 10: Eliza
Fall 2007, David Matuszek

Purposes of this assignment:

General idea of the assignment:

The original ELIZA program was published by Joseph Weizenbaum in 1966. It simulated a Rogerian therapist; that is, most of what it said was merely repeating (with appropriate substitutions) what it was told. Here is a bit of sample dialogue (from Rich & Knight, Artificial Intelligence, 1983):

Person: Men are all alike.
ELIZA: In what way?
Person: They're always bugging us about something or other.
ELIZA: Can you think of a specific example?
Person: Well, my boyfriend made me come here.
ELIZA: Your boyfriend made you come here.
Person: He says I'm depressed much of the time.
ELIZA: I am sorry to hear you are depressed.
Person: It's true. I am unhappy.
ELIZA: Do you think that coming here will help you not to be unhappy?
Person: I need some help, that much seems certain.
ELIZA: What would it mean to you if you got some help?
Person: Perhaps I could learn to get along with my mother.
ELIZA: Tell me more about your family.

Your assignment is to write a simple ELIZA-like program, with a GUI and with file input and output.

Details:

ELIZA worked by applying pattern-matching rules. It looked for a rule whose left side matched the last sentence entered by the user, then used the right side of that rule to generate a response. Some sample rules might be:

I remember #1 => What made you think of #1?
#1 loves #2 => How does that make you feel about #1?
mother => Tell me more about your family.

The conversation:

Write an ELIZA-like program (in a class named Eliza) that interactively "converses" with the user. Your program should have the following features:

Try to get capitalization and punctuation correct, but don't worry too much about it.

The GUI:

Your GUI (a class named ElizaGui) should have:

The program should quit when the user clicks the window's close button (use setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) or when the user types Goodbye into the input field.

The text UI:

In addition to the graphical user interface, you should have a text only user interface to your Eliza program. This program should begin by trying to read in a file of patterns with some predetermined name (such as patterns.txt). If the file is not found or cannot be read, the program asks the user for the name of a file to read; repeat until a file is successfully read or until the user types quit.

The text UI should behave just like the GUI, except that (1) the only way to quit is by telling Eliza Goodbye, and (2) you don't need to have a way to save the conversation on afile.

Note: To run the program, you will use one interface or the other. You never use both at once.

Why two user interfaces?

The text interface adds very little to the effort involved in writing this program, and should make it very clear why it is important to avoid input/output in the "model" (the part of the program that does the computational work).

It is not at all unusual to have classes that provide services to other classes, without making any assumptions about what those services will be used for.

JUnit testing:

What you need to test for this program is whether Eliza is responding correctly to various inputs; the rest is just I/O.

To do this testing, do not read in a file of patterns; that just makes testing impossible without knowing what is on the file. Instead, your patterns for testing should be built into your JUnit test class; the "real" patterns will be those on the input file.. You should try to test every "kind" of pattern that will be allowed on the input file.

Due date:

Thursday, November 29, before midnight. Turn in your program electronically, using Blackboard. (See my Instructions for Using Zip Files and Blackboard). Only assignments submitted via Blackboard will be accepted--do not send your program by email. The usual late penalty of 5 points per day (out of 100 points) will apply.