Wednesday, 16 November 2011

Eliza lab

Today you'll experiment with using regular expressions to mimic Eliza's responses. Using this tool, type in search patterns to match the kinds of sentences that people often type as input to Eliza. Then in the replacement pattern box, write a pattern to produce an Eliza-like response. For example, the search pattern
  • I am (\b\w+\b)
with the replacement pattern
  • How long have you been $1?
will match the sentence
  • I am bored
typed in the input text box and produce
  • How long have you been bored?
in the output text box.
So, now you try it. Write a regular expression search pattern to match sentences of the form:
  • I am sick
  • I am tired
  • I am hungry
Does your search pattern match the following strings and produce the kind of response you would expect?
  • Today I am bored
  • I feel very happy
  • I feel awfully tired
If not, fix your search pattern so that the system generates sensible outputs for each of these. Now try these
  • I feel cold and I want a nap
  • I feel cold and I want a hot drink
  • I like food and drink
  • I like to sing and dance
What if you wanted to generate the response:
  • Have you always enjoyed eating and drinking
in response to the input:
  • I like to eat and drink
Would your search pattern also work for
  • I like to sing and dance
Now write a search pattern that will match sentences like:
  • I am tired and hungry
and produce the response:
  • What do you think makes you hungry and tired?
Now play with this version of Eliza. Find cases where it doesn't respond very naturally and try and write search and replacement patterns that solve the problems you encounter. (Note: they may not all be solvable just by this simple search and replace method.)

No comments:

Post a Comment