In this version of Eliza, we'll concentrate on solving the 2 hard problems
we conveniently stubbed earlier:
Pattern FindMatchingPatternForInput (string input) { // Stubbed for now. We'll figure out what it does later. // For now just return a Pattern. return new Pattern(); } string GenerateResponseForPattern (Pattern pattern, string input) { // Stubbed for now. return string.Format("You said \"{0}\".", input); }Both these problems have to do with a central theme: a "pattern". Rather than writing code, let's first think about what a pattern looks like (i.e. how it's described) and how it behaves. In C#:
Properties and methods of a real-world objectIf you tried to come up with a representation of a car (instead of a pattern), you'd probably come up with this object definition:
TO HELP DEFINE THE Pattern CLASS, WALK AWAY FROM YOUR COMPUTER AND THINK ABOUT WHAT A PATTERN DOES. MAKE SOME NOTES ON A PIECE OF PAPER. WHEN YOU'RE DONE, COME BACK AND COMPARE YOUR NOTES WITH THE ANALYSIS BELOW. Properties and methods of a patternClearly a pattern is something we try to match the user's input to. If the user input matches a pattern, we ask the pattern to generate an appropriate response. For example, let's consider a pattern that checks if the user's input contains the word "BECAUSE". If it does, the pattern should respond with one of the following human-like replies:
string PhraseToMatch { get; set; }and the following methods: bool MatchesInput (string input) { // To be written... } string GenerateResponse() { // To be written... } First version of the Pattern classLooks like we're ready to write (at least the first version of) the Pattern class in C#. Take a stab at this. Feel free to leave out the hard part (the internals of the methods) by stubbing them for now. We're not being lazy - we're just delaying writing the details of the methods until we've broken them down into a few simpler methods. Good old stepwise refinement!
|