As people have said above, you'll make your life a lot easier if you can constrain the complexity of the sentences which you're trying to parse, and perhaps also limit the vocabulary which can be employed by the user. If you can end up with a grammar like (in pseudo-regex-code)

[VERB] the|a|some [ADJECTIVE]* [OBJECT]? \ [to|for|from|with INDIRECT-OBJECT]? [ADVERB]? "Create a small white mouse quickly." [V] [ADJ] [ADJ] [OBJ] [ADV] "Give some tasty peanuts to the mouse." [V] [ADJ] [OBJ] [I-OBJ] "Eat the mouse noisily." [V] [OBJ] [ADV]

You can parse quite an expressive range of sentences especially if you know what parts of speech (verbs, nouns, adverbs etc.) different tokens are. This is the Parse::RecDescent approach.

A deeper more "linguistic" approach might be to use something like a link parser, which is a package that analyses the structure of natural language sentences. There's several available free on the web, although I've never used one with Perl, only with Other Languages. There are lots of other free linguistic resources available on the web which you might find useful, including WordNet, which you can use to look up hyponyms, synonyms and hypernyms ....

.... but this is probably all a bit much for making a small mouse ...

ViceRaid


In reply to Re: Parsing english by ViceRaid
in thread Parsing english by wolis

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.