Perl 5
OK, the guts of the program is just this:
use v5.14;
my %pad = (
...
);
sub pad { shift =~ s(\{(.+?)\}){pad($pad{$1}[rand(@{$pad{$1}})])}rogue }
say ucfirst pad '{START}';
It's basically a "madlib" engine. To actually generate interesting sentences, you need to populate %pad
with some data. Here's an example %pad
...
my %pad = (
START => ['{complex}.'],
complex => [
'{simple}',
'{simple}, and {simple}',
'{simple}, and {complex}',
'{simple}, but {simple}',
'{simple}, yet {simple}',
'even though everybody knows {simple}, {simple}',
'not only {simple}, but also {simple}',
],
simple => [
'{thing} {verb}s {thing}',
'{thing} {verb}s {adverb}',
'{thing} is {adjective}',
'{things} {verb} {thing}',
'{things} {verb} {adverb}',
'{things} are {adjective}',
'{thing} {past_verb} {thing}',
'{things} {past_verb} {thing}',
],
thing => [
'the {adjective} gorilla',
'the {adjective} mailbox',
'Archbishop Desmond Tutu',
'the beef salad sandwich',
'the {adjective} stegosaur',
'the summit of Mt Everest',
'Chuck Norris',
'the cast of television\'s "Glee"',
'a {adjective} chocolate cake',
],
things => [
'{adjective} shoes',
'spider webs',
'millions of {adjective} eels',
'{adjective} children',
'{adjective} monkeys',
'{things} and {things}',
'the British crown jewels',
],
verb => [
'love',
'hate',
'eat',
'drink',
'follow',
'worship',
'respect',
'reject',
'welcome',
'jump',
'resemble',
'grow',
'encourage',
'capture',
'fascinate',
],
past_verb => [ # too irregular to derive from {verb}
'loved',
'ate',
'followed',
'worshipped',
'welcomed',
'jumped',
'made love to',
'melted',
],
adverb => [
'greedily',
'punctually',
'noisily',
'gladly',
'regularly',
],
adjective => [
'enormous',
'tiny',
'haunted',
'ghostly',
'sparkling',
'highly-decorated',
'foul-smelling',
'{adjective} (yet {adjective})',
'expensive',
'yellow',
'green',
'lilac',
'tall',
'short',
],
);
Here's some samples of the wisdom I've discovered from that %pad
. These sentences have not been edited for length, punctuation, grammar, etc, though I have culled some uninteresting ones and rearranged the order in which the sentences appear - they are no longer in the order they were generated, but instead I'm trying to use them to tell a story: a story I hope you will find both touching and thought-provoking.
- Spider webs are short.
- Spider webs fascinate regularly.
- Short monkeys are sparkling, but spider webs drink greedily.
- Sparkling (yet foul-smelling) monkeys followed the tiny (yet sparkling) gorilla.
- The summit of Mt Everest welcomed the highly-decorated stegosaur.
- Not only the summit of Mt Everest is expensive, but also the cast of television's "Glee" followed the sparkling gorilla.
- The cast of television's "Glee" resembles the lilac mailbox.
- The expensive mailbox is tall, and the expensive stegosaur jumps Chuck Norris, yet green shoes jumped the beef salad sandwich.
- The beef salad sandwich loved Chuck Norris.
- Millions of sparkling eels are green (yet ghostly).
[Adjective] [pl. noun] [verb] [adjective] [pl. noun]
and pulls from a real dictionary (maybe using one of the Dictionary APIs available out there) to fill in the blanks? I'd write it myself if I had a few minutes to spare! :( After all...Lazy Developers Write Lousy Programs.
– Brian Lacy yesterday