Now we're going to start having some fun. We'll add a couple more patterns that behave
similar to the BECAUSE pattern. That is, they'll check for the presence of a specific
phrase, and if present, respond with a random lifelike response.
Let's choose the YES and NO patterns.
-
YES will respond with one of these 4 responses:
- YOU SEEM QUITE POSITIVE.
- ARE YOU SURE?
- I SEE.
- OK.
-
NO will respond with one of these 3 responses:
- YOU'RE BEING A BIT NEGATIVE.
- ARE YOU SAYING NO JUST TO BE NEGATIVE?
- WHY NOT?
IS THERE ANYTHING YOU'D LIKE TO IMPROVE IN YOUR CODE?
COMPARE YOUR Pattern.cs and Eliza.cs WITH THE FILES IN THE SOLUTION.
Using the new patterns
Now that you've made Pattern able to respond to user input that contains
YES and NO, we can construct patterns of these types by doing:
Pattern becausePattern = new Pattern("BECAUSE");
Pattern yesPattern = new Pattern("YES");
Pattern noPattern = new Pattern("NO");
To test if the user's input matches any of these patterns, we simply call the pattern's
MatchesInput() method, and if it does, we call the pattern's GenerateResponse() method.
MODIFY Eliza.cs TO USE THE THREE PATTERNS WE'VE CREATED.
Strike up a conversation with Eliza!
WELCOME! PLEASE TELL ME YOUR PROBLEM.
> I think I'm overweight because I eat too much.
DON'T ANY OTHER REASONS COME TO MIND?
> No, not at all.
YOU'RE BEING A BIT NEGATIVE.
> No, I'm not!
WHY NOT?
> Because I'm not a negative person.
IS THAT THE REAL REASON?
> Yes, of course.
I SEE.
> Do you, really?
PLEASE GO ON.
> No.
WHY NOT?
> Bye.
GOODBYE! IT WAS NICE TALKING WITH YOU.
While this is considerably more interesting than our first version Eliza that simply
echoed the user's input, we've only just begun to scratch the surface!
|