Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Natural Language Sentence Production

by Anonymous Monk
on Sep 22, 2005 at 21:10 UTC ( [id://494301]=note: print w/replies, xml ) Need Help??


in reply to Natural Language Sentence Production

I know there are natural language parsing modules on CPAN, but I want to do the opposite
The easiest solution? Guess and check. Generate a sentence of random words and reject those which don't pass muster accoring to you CPAN parsing modules.

Replies are listed 'Best First'.
Re^2: Natural Language Sentence Production
by tomazos (Deacon) on Sep 23, 2005 at 00:59 UTC
    The easiest solution? Guess and check. Generate a sentence of random words and reject those which don't pass mu

    Sounds like a bogosort to me.

    To sort a deck of cards:

    1. Shuffle deck randomly.
    2. If not sorted, go to 1.

    Efficiency in the order of O(lots and lots and lots and....) -Andrew.


    Andrew Tomazos  |  andrew@tomazos.com  |  www.tomazos.com

      Close, but not quite. It depends on the ratio of "sensible" vs. "nonsensical" phrases, which in turn depends on how much leeway you're willing to give the program. If you want to mimic a rational human, then yes, you're right. But if you're willing to take something less stringent - say, your average irrational person, or worse, a suit - then you might be able to pull it off this way.

      I did something like this with a music-composing program. I randomly generated tones, intervals, and durations, and filtered out the obvious dissonances and silly combinations. What was left was OK - not exactly music, but close to Musak. It would have passed muster in an elevator, but not at a concert.

Re^2: Natural Language Sentence Production
by Anonymous Monk on Sep 22, 2005 at 21:25 UTC
    Er. That probably could have been more clear. Don't generate a long random sentance and then check it, build it up a piece at a time.
    while(...) { my @sentence = (); for (1..$random_sentence_length) { do { $next_word = random_word_generator(); } while(not grammar_correct(@sentance, $next_word); push @sentance, $next_word; } print @sentance; }
Re^2: Natural Language Sentence Production
by Excalibor (Pilgrim) on Sep 23, 2005 at 08:19 UTC

    Check out Dave "Pragmatic" Thomas's blog entry Kata14 where you'll be challenged to generate sensical text by using "trigrams"...

    I've tried his solution, and with a varied enough text base to feed it, it generates some impressive texts with so little effort... I guess you can improve it to check longer strings as well, but you'd end up with a Markov Chain (de|re)generator, which could be interesting on itself, but...

    (suggestion: the Gutenberg Project is a great place to get good base texts for feeding the database :-)

    Link: PragDave's Kata Fourteen

    Good luck,

    --
    our $Perl6 is Fantastic;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://494301]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found