Random sentence from book: Difference between revisions

→‎{{header|Raku}}: Add a Raku example
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(→‎{{header|Raku}}: Add a Raku example)
Line 786:
The ringing impact of trucks, the person or entity that provided you with the torrent to recover it.
</pre>
 
=={{header|Raku}}==
Started out as translation of [[Random_sentence_from_book#Perl|Perl]], but diverged.
 
<lang perl6>my $text = '36-0.txt'.IO.slurp.subst(/.+ '*** START OF THIS' .+? \n (.*?) 'End of the Project Gutenberg EBook' .*/, {$0} );
 
$text.=subst(/ <+punct-[.!?\’]> /, ' ', :g);
$text.=subst(/ (\s) '’' (\s) /, '', :g);
$text.=subst(/ (\w) '’' (\s) /, {$0~$1}, :g);
$text.=subst(/ (\s) '’' (\w) /, {$0~$1}, :g);
 
my (%one, %two);
 
for $text.comb(/[\w+(\’\w+)?]|<punct>/).rotor(3 => -2) {
%two{.[0]}{.[1]}{.[2]}++;
%one{.[0]}{.[1]}++;
}
 
sub weightedpick (%hash) { %hash.keys.map( { $_ xx %hash{$_} } ).pick }
 
sub sentence {
my @sentence = <. ! ?>.roll;
@sentence.push: weightedpick( %one{ @sentence[0] } );
@sentence.push: weightedpick( %two{ @sentence[*-2] }{ @sentence[*-1] } // %('.' => 1) )[0]
while @sentence[*-1] ~~ /\w/;
@sentence.=squish;
shift @sentence;
redo if @sentence < 7;
@sentence.push: '.' if @sentence[*-1] !~~ /<:punct>/;
@sentence[*-2] ~= @sentence.pop ~ "\n";
@sentence.join(' ').tc
}
 
say sentence() for ^10;</lang>
{{out|Sample output}}
<pre>Were the powder from the plan of action and drove a bargain for thirty six pounds for the inhabitants of the heat upon the edge the slightest projection of the steamboat with his wife and two boys and unemployed men had already discovered this on the latch nor how I had slept but little though my wife had succeeded in crawling unobserved by these monstrous machines into the midst of it a face wet as I clambered into the broad ditch by the work?
 
In the rest and selling his papers for a long while I left in the carts whipped stupidly at their horses and of men burned horribly about the sinking cloud bank the warships turned northward and then in a whisper.
 
Patrols of soldiers standing on the scullery in heart throbbing retreat.
 
Think of what is more wonderful to a place in a thing like an elephant’s trunk more than there’s war between man and jumped back.
 
Partly stunned he found that the tendency of natural selection all terrestrial plants have acquired a resisting power to no germs do we succumb without a goal six million people unarmed and unprovisioned driving headlong.
 
Cried a boatman and Shut up!
 
A boy came running towards Woking seemed to darken abruptly as it spread itself slowly over the country about London must inevitably have slain me in order as he says to see into the air through the iron gates of the few horses showed dismally.
 
One man’s hands pressed on the towing path licking off the Blackwater until five in the rain and darkness watching by the Black Smoke and there smoked the Heat Rays.
 
I’m selling my bit of the Black Smoke came by hearsay.
 
Oh one can’t always work he had spent a week or so under twenty four hours after the first glance it was sufficiently shallow for me to come down and saw a rush for it but my companion suddenly complained of faintness and thirst and we saw another newsvendor approaching and got over the district were pouring along the Strand to Trafalgar Square the paper fearing the worst will kill them all.</pre>
 
=={{header|Wren}}==
10,333

edits