Okay, I figured out what you are doing, though the abbreviations are beyond me (what does VBZ stand for, I give up! :) It took a while to realize the your slashes are not delimiters, so "What" is the WP, "is" is the VBZ, and "her name" is the NP, and "(CI)" must be the exclamation I guess.

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. :)


In reply to Re: Checking Composed unique keys using hash tables by mattr
in thread Checking Composed unique keys using hash tables by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.