in reply to Checking Composed unique keys using hash tables
You might want to first analyze the input sentence as a pattern, and then keep a set of rules as to what to do when you have a certain pattern. The logic is the hard part but you can't ignore it. You might also start with more complex patterns and work towards simpler ones, so that if you have a really wierd one you can answer with the least common denominator, like "Huh?". What happens if I type "Do you know her name?" or "Her name was.. I forget?" or "Tell me the girl's name please."
You could use a regular expression to scan for supported nouns like "if $s =~ /name/ {...}" or you can analyze the sentence into a query which has a subject, verb, and object, then just look up the object and invert. The problem with your current setup is that you never really do any analysis, so you keep getting more and more complex keys. For example, it seems to me you should not have "her" included in part of a key. Do you intend to make a new key for every pronoun in the book? With this kind of a series of exploding ramifications, you can't win. Every time you want to take a new step your data structure will grow exponentially. That is the problem you sense at the end of your post ("how do I extract..").
One way you could simplify is to analyze the first line of your dialog as a "What-is-X" pattern: if $s =~ /what is (.+)$/i and you can divide $x into "her" and "name" or something more general if you like. You can store patterns in an array or hash and evaluate them in a loop. As long as your program actually understands what is being requested ("name") there is no need to go through another set of hashes. It would save time if you could split up into different hashes instead of composing, since you would have a factor fewer keys to make. Fill in the space with program logic instead..
Anyway, whatever strategy you use, if you provide some kind of reducing logic step you will be able to keep your data from exploding. Hashes can be really sexy but you need to put some smartness into them or they will just go wild all over you. (Hmm, I best stop here. :)
|
|---|