Random sentence from book: Difference between revisions

Content added Content deleted
(→‎{{header|Raku}}: Add a Raku example)
(→‎{{header|Raku}}: Fixed to preserve commas)
Line 792:
<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]}++;
Line 810:
@sentence.push: weightedpick( %one{ @sentence[0] } );
@sentence.push: weightedpick( %two{ @sentence[*-2] }{ @sentence[*-1] } // %('.' => 1) )[0]
whileuntil @sentence[*-1] ~~ /\w/<. ! ?>;
@sentence.=squish;
shift @sentence;
Line 821:
say sentence() for ^10;</lang>
{{out|Sample output}}
<pre>To the inhabitants calling itself the Committee of Public Supply seized the opportunity of slightly shifting my position, which had caused a silent mass of smoke rose slanting and barred the face.
<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?
 
Why was I after the Martian within the case, but that these monsters.
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.
 
As if hell was built for rabbits!
Patrols of soldiers standing on the scullery in heart throbbing retreat.
 
Thenks and all that the Secret of Flying, was discovered.
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.
 
Or did a Martian standing sentinel I suppose the time we drew near the railway officials connected the breakdown with the butt.
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.
 
Flutter, flutter, went the bats, heeding it not been for the big table like end of it a great light was seen by the humblest things that God, in his jaws coming headlong towards me, and rapidly growing hotter.
Cried a boatman and Shut up!
 
Survivors there were no longer venturing into the side roads of the planet in view.
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.
 
Just as they began playing at touch in and out into the west, but nothing to me the landscape, weird and vague and strange and incomprehensible that for the wet.
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.
 
Just as they seem to remember talking, wanderingly, to myself for an accident, but the captain lay off the platforms, and my wife to their former stare, and his lower limbs lay limp and dead horses.
I’m selling my bit of the Black Smoke came by hearsay.
 
Entrails they had fought across to the post office a little one roomed squatter’s hut of wood, surrounded by a gradual development of brain and hands, the latter giving rise to the corner.</pre>
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}}==