Our version of ELIZA, although simplified, retains many features of the original. After the program has printed its opening gambit,
GOOD DAY WHAT IS YOUR PROBLEM?
it operates in a cycle, repeatedly carrying out the following actions:
When the program gets input from the user, it converts all the characters typed by the user into lowercase, and then in printing its response it converts lowercase characters into uppercase ones. So, in showing the internal workings of the Eliza program, we shall use all lowercase characters. Generally, the program just responds to its most recent input, but occasionally, not on every cycle, it stores the input so that it can reproduce it later prefaced by EARLIER YOU SAID. (It actually stores the input after it has been transformed to change the `point of view'; see below.) This crude form of memory is only a minor complication, though it does add appreciably to the program's effect.
It is the middle part of the cycle, generating an appropriate response, that is interesting. This has the following sequence of actions:
you understand me
would be changed to
i understand you
One problem with this very simple approach is that `you' can be the subject or the object of a sentence (i.e., it may come before or after the verb). Just slavishly changing `you' to `i' would result in
i understand you
being changed to
you understand i
The program therefore uses another simple trick to deal with this: if the transformed sentence ends in `i', then the `i' is changed to `me'. This is far from foolproof, as the earlier dialogue showed:
If I could explain to you I could explain anything to anyone
IF YOU COULD EXPLAIN TO I YOU COULD EXPLAIN ANYTHING TO ANYONE
Further tricks like this (called `kludges' in computer jargon) would not solve the central problem, which is that Eliza is not founded on any principled representation of the form and content of English.
With the input in its new form, the program then searches for a keyword on a particular topic, or a suitable pattern to match the transformed input, by means of pattern matching. Pattern matching underlies most of Eliza's apparent cleverness, and computer languages that have access to a pattern matching mechanism can easily be programmed to emulate Eliza.