[Next] [Up] [Previous]
Next: Choices in Eliza Up: Inside Eliza Previous: Inside Eliza

Patterns

 

A pattern for Eliza is a list containing a mixture of words and wild cards. Wild cards are elements that can match any series of words, so a pattern is like a partly specified sentence in which some of the words are present and some are still to be filled in. We shall adopt the convention that lists of words and wild cards are enclosed in square brackets, and we will use = or == to denote a wild card in the list. The = (single equals) wild card stands for a single word, and the == (double equals) wild card stands for any number of words (including none at all). The pattern is matched against the list of words inputted by the user (after each occurrence of `you' has been changed to `i', etc.) -- for example

[you think you are unique in some way]
is changed to
[i think i am unique in some way] which matches the pattern
[== i am ==]

[anyone who wasn't a computer]
matches the pattern
[== computer ==]

[then you would't be talking to me]
is changed to
[then i wouldn't be talking to you] which does not match the pattern
[== talking with ==]

In order to match keywords or phrases in the input Eliza has a series of such patterns associated with standard responses:

PATTERN STANDARD RESPONSE
[== want ==] [beware of addictions]
[== need ==] [can you do without]
[== crave ==] [do you ever suffer withdrawal symptoms?]
[== mother ==] [tell me more about your family]
[== father ==] [do you approve of large families?]
[== sister ==] [family life is full of tensions]
[do you like your relatives?]

The program compares the input to each pattern in turn until a match is found. It then produces one of the standard responses. If there is more than one response available, then it picks one at random.

A pattern may contain variables to indicate pieces of data to be stored. For the examples here we shall just use two variables named X and Y. In a pattern, a single query followed by the variable name will match a single word, and two queries followed by a variable name will match any number of words (including zero). If a match succeeds, then the words matched will be stored as the value of the appropriate variable, so

[eliza is a very simple program]
matches the pattern
[??X is ??Y]

[eliza] is stored as the value of X and [a very simple program] is stored as the value of Y.

To construct a response, Eliza reassembles the fragments. We need one more piece of notation. Two up-arrows before a variable name instruct the program to insert the value of the variable into the newly created response list. Figure 2.1 shows the complete sequence.

  [IMAGE ]
Figure 2.1: The construction of a response.

Note that the program does nothing meaningful with the words `eliza' or `a very simple program'. They are simply stored temporarily with the names X and Y and then slotted into the output sentence.


[Next] [Up] [Previous]
Next: Choices in Eliza Up: Inside Eliza Previous: Inside Eliza

Cogsweb Project: luisgh@cogs.susx.ac.uk