Now that we have everything in place to create complex patterns, let's start by creating
the REMEMBER pattern we looked at in the previous step. We'll place RememberPattern in a
folder that will hold all complex patterns, just as we did earlier for format-free patterns.
This is simply an aspect of code organization (keeping related classes in a folder),
and has no impact on how Eliza runs.
Creating RememberPatternThis is how the REMEMBER pattern is defined in Eliza's script.
key: remember 5
decomp: * i remember *
reasmb: Do you often think of (2)?
reasmb: Does thinking of (2) bring anything else to mind?
reasmb: What else do you recollect?
reasmb: Why do you recollect (2) just now?
reasmb: What in the present situation reminds you of (2)?
reasmb: What is the connection between me and (2)?
decomp: * do you remember *
reasmb: Did you think I would forget (2)?
reasmb: Why do you think I should recall (2) now?
reasmb: What about (2)?
reasmb: goto what // <-- Ignore this for now
reasmb: You mentioned (2)?
Our RememberPattern constructor will closely resemble this and will call on
ComplexPattern.Initialize() to initialize the class, much like format-free pattern
constructors called FormatFreePattern.Initialize().
TRY TO WRITE THE CONSTRUCTOR FOR RememberPattern. WHEN YOU'RE DONE, COMPARE YOUR
CODE TO THE SCREENSHOT BELOW.
Now that we've created RememberPattern, let's add it to Eliza's list of patterns.
This is done in
Eliza will use RememberPattern to generate a response if the user's input
contains the words REMEMBER or RECALL. Let's test this by running Eliza and
telling her:
I REMEMBER PLAYING IN A BAND WHEN I WAS A TEENAGER.
HOW WILL YOU FIX THIS?
Fixing the problemIf you've been writing code along with this step, you would have found that Eliza encountered a run-time error in the method FindMatchingPatternForInput(). This is because Eliza assumes that the matching pattern (if found) will always be of type FormatFreePattern. But Eliza's world now also includes classes derived from ComplexPattern. See the section "Allowing Eliza to consume ComplexPatterns" in the previous step for a hint as to how to fix the problem.Testing RememberPatternNow that we've fixed the crash, we're ready to test RememberPattern. Run Eliza and give it the same input as before.
Although this isn't how (most) humans respond, Eliza is doing exactly what we
told it do. Once we replace the stubbed methods in DecompReassemblyRule with real
code, RememberPattern will respond as described in
Eliza's script
.
We'll see how to do that in the next step!
|