In this step, we'll add the remaining complex patterns that resemble RememberPattern. That is,
patterns whose decomposition rules look like this:
<optional text before key phrase> <key phrase> <text after key phrase>If you refer to Eliza's script , you'll see these patterns are: IF, DREAMED, AM, ARE, YOUR, WAS, WERE, CAN, WHYBut there's a bit more happening. See the pre section in the script? These are pre-transforms, or transforms applied to the user's input before pattern matching is performed. This allows multiple keywords to be handled by the same pattern. For example: pre: how what pre: when whatcauses the presence of HOW and WHEN in the user's input to both be handled by the pattern that handles WHAT.
I don't agree with Eliza's script that says WERE should be handled by the WAS pattern. For
this reason, I've omitted it from the list of pre-transforms and have moved WERE's
decomp/reassembly rule from WasPattern to its own WerePattern.
Performing pre-transformsLet's extend StringTransformer to do a pre-transform.Simplifying existing patternsBecause we're transforming the user's input prior to finding a matching pattern, we can simplify some of our patterns to no longer consider multiple phrases. Specifically:
Adding the complex patternsNow add the complex patterns we identified above. When you're done, your project should look like this:Testing your changesLet's run Eliza to ensure our changes haven't broken anything. Give Eliza the following input:WHY CAN'T I BE RICH AND FAMOUS?If all goes well, this should match the WHY pattern, triggering its "* why can't I *" decomposition rule, producing: DO YOU THINK YOU SHOULD BE ABLE TO BE RICH AND FAMOUS?Instead, this happens:
WHY DID THIS HAPPEN? HOW WILL YOU FIX IT?
TO FIND THE PROBLEM, STEP THROUGH YOUR CODE IN THE DEBUGGER. IF YOU NEED HELP, LOOK AT THIS STEP'S SOLUTION. SPECIFICALLY, UNCOMMENT THE Debug.WriteLine() CALLS IN Eliza.FindMatchingPatternForInput(). Exhaustive testingAfter fixing the problem, proceed to test each complex pattern and verify that it cycles through each expected response. |