CIS 700 Assignment 3: Eliza
Summer II 2010, David Matuszek

# Purpose of this assignment

• To give you more practice with Scala
• To try to get you thinking in functional terms
• To get you started with Scalatest (see below)

# Background

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, 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.
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 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. A sample rule might be something like:
`I remember \$1 => What makes you think of \$1? `.

# The assignment

Write an Eliza-like program that interactively "converses" with the user. Your program should have the following features:

1. It should read in a list of rules from a file (you supply the list of rules)--name it `rules.txt`. The above example hints at a suggested format, but you can use whatever format you like for the rules. Provide a `readme.txt` file that explains the format and its intended interpretation.
2. It should do simple pattern matching and substitution: "I remember the first day of school" => "Why do you remember the first day of school just now?"
3. The pattern matching should include pronoun substitution: "My boyfriend made me come here" => "Your boyfriend made you come here." Note that pronoun substitution should occur in addition to any other pattern matching and substitution.
4. It should recognize certain keywords and respond to those. For example: "I think I'm in love" => "Love isn't always a simple thing."
5. It should provide general-purpose responses if no other patterns match, for example: "Tell me more about that." There should be more than one such response, selected randomly.
6. Remember some topics that were discussed earlier, and incorporate them into your general-purpose responses: "Tell me more about your trip to Brazil."

Your program is expected to work; please don't turn in one that doesn't. The penalty for late programs is 10% per day 5% per day, but it's much more severe if your program doesn't work.

Every method should have Scaladoc comments. Be sure to use the `@author` tag in the comment for your `Eliza` object, so we know who you are.

## Special rules

• The base score for a properly working, properly formatted, and properly commented program will be 80 points.
• You will gain 1 point for each function defined with `def`, up to a maximum of 10 points.
• You will gain 2 points for each appropriate use of `=>`, up to a maximum of 20 points. (That includes its use in `match` statements.)
• You will gain 2 points for each use of `map`, `filter`, `flatMap`, `foreach`, `forall`, `exists`, `find`, and `span`, up to a maximum of 20 points. (Note: When you use these with `=>`, you get credit for both.)
• You will lose 15 points for every one of the above that isn't actually useful in the program, but is just there for no apparent reason other than to get extra points. Plus, we will get annoyed at you.
• You will lose 3 points for each occurrence of one of the keywords `var` and `while` and 10 points for each occurrence of `null`. (This is to get you to use `for`, `List`, and maybe `Some`). You will be allowed one "free" use of `null`, so that you can use a file chooser to read the `rules.txt` file.

As before, the reasons for these rules are twofold: (1) They are intended to get you thinking functionally, and (2) It is easy to write a program to count these keywords.

# Scalatest

Since I was unable to get Scalatest working earlier, this section is extra credit (up to 20 points). Scalatest will be required on the next Scala assignment. Here's what you need:

• Java 5 or 6 (presumably you already have that)
• An up-to-date version of Scala. Scalatest and scala-2.8.0.final are compatible; earlier versions of Scala may or may not work (you can try yours and see). I found upgrading with the IzPack installer very easy.
• Some version of `ant`. The latest is 1.8.1; I have 1.7.1 and it works fine. It's also very easy to install; I did a Google search for `how to install ant` and picked the instructions that seemed most appropriate.
• The very nice package put together for us by Yuvi: `Eliza.zip`. Download and unzip this, read the `README.rst`, and try it out. Look at the sample program in `src/Eliza.scala` and the sample test in `test/ElizaTest.scala`. (Note: May be slow to download.)

This seems like a lot, but it's really not. The Scala and ant installers work very well, and Yuvi's made it easy for us. Using ant is slow, though, so I'm still looking for a way to use Scalatest from jEdit or some other IDE.

# Due date

Zip your complete program, and submit it via Blackboard before midnight, Sunday July 25.

• Your `.scala` source file or files.
• Your `.class` binary files.
• Your `rules.txt` and `readme.txt` files.
• A transcript (name it `example.txt`) showing a complete sample interaction with your program.
• Your folder of documentation created by `scaladoc`.