Markov chain text generator: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: added the REXX computer programming language.) |
(→{{header|REXX}}: optimized the building of the prefix table.) |
||
Line 916: | Line 916: | ||
sw = linesize() - 1 /*get usable linesize (screen width). */ |
sw = linesize() - 1 /*get usable linesize (screen width). */ |
||
$= space( linein(iFID) ) /*elide any superfluous whitespace in $*/ |
$= space( linein(iFID) ) /*elide any superfluous whitespace in $*/ |
||
$$= $ /*save a copy after $ is destructed. */ |
|||
say words($) ' words read from input file: ' iFID |
say words($) ' words read from input file: ' iFID |
||
call gTab /*generate the Markov chain text table.*/ |
call gTab /*generate the Markov chain text table.*/ |
||
Line 925: | Line 926: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
gTab: @.=; do j=1 for words($)-ord /*keep processing until words exhausted*/ |
gTab: @.=; do j=1 for words($)-ord /*keep processing until words exhausted*/ |
||
p= subword($, |
p= subword($, 1, ord) /*obtain appropriate number of words. */ |
||
parse var $ . $ /*delete first word, no longer needed. */ |
|||
@.p= @.p word($, ord) /*build prefix & 1 (of sev.?) suffixes.*/ |
|||
end /*j*/ |
end /*j*/ |
||
#= j-1 /*define the number of prefixes. */ |
#= j-1 /*define the number of prefixes. */ |
||
Line 932: | Line 934: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
gTxt: mc=; do until words(mc)>=fin /*build Markov chain text until enough.*/ |
gTxt: mc=; do until words(mc)>=fin /*build Markov chain text until enough.*/ |
||
y= subword($, rand(#), ord) |
y= subword($$, rand(#), ord) /*obtain appropriate number of words. */ |
||
s= @.y; w= words(s) /*get a suffix for a word set; # wprds.*/ |
s= @.y; w= words(s) /*get a suffix for a word set; # wprds.*/ |
||
if w>1 then s= word(s, rand(w)) /*pick random word in the set of words.*/ |
if w>1 then s= word(s, rand(w)) /*pick random word in the set of words.*/ |
||
Line 947: | Line 949: | ||
end /*k*/ |
end /*k*/ |
||
if g\=='' then say g /*There any residual? Then display it.*/ |
if g\=='' then say g /*There any residual? Then display it.*/ |
||
return /* [ |
return /* [↑] limits G to terminal width.*/</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
════════════════════════════════════════════════════════Markov chain text════════════════════════════════════════════════════════ |
════════════════════════════════════════════════════════Markov chain text════════════════════════════════════════════════════════ |
||
great Head? That was fell out of the the Caterpillar. 'Well, I've her crows and her us, he said, built eyes so often with quiet |
|||
took Toto in her but her eyes were puzzled her very much to be ashamed of a Woodman, and made idea what you're talking know. So, |
|||
till she got Tin Woodman were glad my body, splitting me said Alice, very much long arms growing out her and bit her before she |
|||
while they And oh, my poor journey. This worried Dorothy wag my tail when cats!' cried the Mouse, like to cry a She did not get |
|||
had drunk tremble. Quick! cried the a low, trembling voice. corner, but the Rabbit never heard it before,' small point a foot in |
|||
she found to be I do not want truck was all ready the Lion's back. To she might as well and four nights, hammering his leg, and |
|||
a little rippling the little girl was silver whistle twice. Straightway in groups. But the green leaves that lay well! It means |
|||
was dance?' 'Thank you, it's Em, and said, We who lived in the the same when I the gate the Lion down with one elbow he had |
|||
much who ran to Alice said the Cowardly Lion, Palace for several days, head and arms and say How doth the the effect: the next |
|||
seen. They a reasonable pace,' said nearly blunted my claws, next; so she took terrible Beast. It was the Scarecrow, having no |
|||
her; so I set not doing these little saw no one at who played with Toto So the Scarecrow followed have witches and wizards |
|||
know,' the Mock Turtle his Palace. But first the Scarecrow, What will From the Land of I know. Well, one Land of Oz, how cloth, |
|||
people to keep away ropes, and the balloon added to one of answered Oz. But I if you don't mind, for them. They came her in any |
|||
and put it both sides of it, those needles and pins was, how to get To their great joy the Mouse was bristling an M, such as not |
|||
way. that it might happen Hatter said, turning to at the water's edge. anything to say, she Are you going with it a kind heart? |
|||
to make personal we leave her here the King, rubbing his back again, and looking took a great interest she looked back once |
|||
still in existence; 'and of speaking to a of tin. After this was as big as From the Land of it with hot air. The country here is |
|||
smooth, like the surface silk dress she had curious sensation, which puzzled he gave so loud blinded by the glare except Toto, |
|||
and frightening my cow? a coward. Have you upon it.) 'I'm glad creeping back, and Toto But Dorothy they did grin, and she said |
|||
and taking hill. So he said, and shepherds dressed in her nicked elbow close Oz. First they came indeed, said the man. nor do I |
|||
for one so cowardly. but I think I dear! Let this be Dorothy and Toto and it's an arm, yer sent the soldier with what to do with |
|||
know about it, so she a morsel of the little people so they I am a very the limbs of trees, the Queen, pointing to the Woodman |
|||
a mouse: she had not think of any their paws. 'And how I will fight them there were two little Making believe! cried Dorothy. |
|||
both shook had happened; and Toto settled down again, the Cap. Willingly! exclaimed Dorothy; on a pole in houses in this country |
|||
</pre> |
</pre> |
||