in reply to Perl can do it, take 1 (sentence generation)
Here is my perl6 port of your code. I had to work around a thing with given/when...unless they fixed it and i didn't notice yet.
use v6; my %dict = ( sentence => [[qw/ noun_phrase verb_phrase /]], noun_phrase => [[qw/ Article Noun /]], verb_phrase => [[qw/ Verb noun_phrase /]], Article => [qw/ the a /], Noun => [qw/ man ball woman table/], Verb => [qw/ hit took saw liked /] ); sub generate ($phrase) { given $phrase { when .does(List) { return $phrase.map:{generate($_)} } if (defined %dict.{$_}) { return generate( %dict.{$_}.pick) } else { return [$phrase] } } } sub gen_sentence () { generate("sentence").join(" ").say }; gen_sentence for 1..5;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl can do it, take 1 (sentence generation)
by spurperl (Priest) on Jun 19, 2005 at 16:36 UTC | |
by eric256 (Parson) on Jun 19, 2005 at 18:25 UTC | |
by spurperl (Priest) on Jun 19, 2005 at 18:38 UTC | |
|
Re^2: Perl can do it, take 1 (sentence generation)
by wolv (Pilgrim) on Jun 23, 2005 at 20:02 UTC |