Random sentence from book: Difference between revisions

m (syntax highlighting fixup automation)
Line 319:
 
Presently, he came hurrying after me he barked shortly.
</pre>
 
=={{Header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey>
#NoEnv
#SingleInstance, force
; press Esc to stop and display the output text
; (a debug file describing ongoing steps will be created in the end)
FileEncoding, UTF-8
FileRead, warWords, war of words.txt ; wrapped booktext
global textOut := " "
global warWords := strreplace(warWords,"`r`n", " ")
warWords := strreplace(warWords,"`r", " ")
warWords := strreplace(warWords,"`n", " ")
warWords := strreplace(warWords,"-", " ")
warWords := strreplace(warWords,"—", " ")
warWords := strreplace(warWords,"`t", " ")
warWords := strreplace(warWords,"“")
warWords := strreplace(warWords,"_")
warWords := strreplace(warWords,"”")
warWords := strreplace(warWords,"’")
warWords := strreplace(warWords,"'")
warWords := strreplace(warWords,"""")
warWords := strreplace(warWords,")")
warWords := strreplace(warWords,"(")
warWords := strreplace(warWords,"[")
warWords := strreplace(warWords,"]")
warWords := strreplace(warWords,"{")
warWords := strreplace(warWords,"}")
warWords := strreplace(warWords,"»")
warWords := strreplace(warWords,"«")
warWords := trim(warWords)
Loop
{
warWords := strreplace(warWords," ", " ")
if (Errorlevel = 0)
break
}
FileDelete, debug.txt
InputBox, fOne, War of Words, Choice a punctuation to start ( . or ! or ? or `, ),,,,,,,,.
treco := NextPunct(fOne)
Loop
{
loop,parse,treco," "
if A_LoopField
fOne := trim(A_LoopField)
textOut .= fOne . " "
tremPos := InStr(textOut," ",,0,3)
tremText := trim(substr(textOut,tremPos))
if tremText
{
tremText := strreplace(tremText,".","\.")
tremText := strreplace(tremText,";","\;")
tremText := strreplace(tremText,",","\,")
tremText := strreplace(tremText,"!","\!")
tremText := " " . strreplace(tremText,"?","\?")
treco := NextWord(tremText)
}
else
treco := NextWord(fOne)
}
 
NextPunct(punct) {
xpos := 1
prox := []
Loop
{
spos := RegExMatch(warWords, "(*UCP)\" . punct . " \w+.",gg,xpos)
if (spos = 0)
break
prox[a_index] := gg
xpos := spos + 1
}
proximas := ""
loop, % prox.MaxIndex()
proximas .= a_index . " -> " . prox[a_index] . "`n"
FileAppend, %proximas%, debug.txt, UTF-8
Random, linha, 1, prox.MaxIndex()
FileAppend, % "---------------`nescolhido = " . linha . " -> " . prox[linha] . " -> " . textOut . "`n----------------`n", debug.txt, UTF-8
return prox[linha]
}
 
NextWord(word) {
xpos := 1
prox := []
loop
{
spos := RegExMatch(warWords, "(*UCP)" . word . " \w+.",gg,xpos)
if !spos
break
prox[a_index] := gg
xpos := spos + 1
}
 
if (prox.MaxIndex() > 0)
{
proximas := ""
loop, % prox.MaxIndex()
proximas .= a_index . " -> " . prox[a_index] . "`n"
FileAppend, %proximas%, debug.txt, UTF-8
Random, linha, 1, prox.MaxIndex()
FileAppend, % "---------------`nescolhido = " . linha . " -> " . prox[linha] . " -> " . textOut . "`n----------------`n", debug.txt, UTF-8
return % prox[linha]
}
 
loop,parse,word," "
wrd := A_LoopField
word := wrd
spos := xpos := 1
prox := []
loop
{
spos := RegExMatch(warWords, "(*UCP)" . word . " \w+.",gg,xpos)
if (spos = 0)
break
prox[a_index] := gg
xpos := spos + 1
}
proximas := ""
loop, % prox.MaxIndex()
proximas .= a_index . " -> " . prox[a_index] . "`n"
FileAppend, %proximas%, debug.txt, UTF-8
Random, linha, 1, prox.MaxIndex()
FileAppend, % "---------------`nescolhido = " . linha . " -> " . prox[linha] . " -> " . textOut . "`n----------------`n", debug.txt, UTF-8
return % prox[linha]
}
 
ExitApp
 
~Esc::
msgbox % textOut . "..."
ExitApp
</syntaxhighlight>
{{Output}}
<pre>
War of Words.ahk
---------------------------
(start = ".") I stumbled into the road in the sky? he asked abruptly. I told them to death tomorrow, my dear. I did not clearly understand how I figure it out. It isnt quite according to what a man in workday clothes, riding one of the farther bank, and in my enfeebled condition, too fatigued to push on at once under water, and, holding my breath until movement was an intermittent, metallic rattle. That! said the woman over the ground heaved under foot for days, on account of the cylinders, that at last induced my brother leading the pony across its head. A waggon locked wheels for a few heaps of broken bricks in the doorway. The thunderstorm had passed. The towers of the horse scattered and gnawed. For a minute she seemed halfway between the life on Mars and terrestrial life, I may remark here, as dissection has since shown, was almost equally simple. The greater ...
---------------------------
(start = ".") Then silence that passed into the dining room and drank beer out of my temerity. In front was a little child, with all my ears. He made me pity him. Then he would suddenly revert to the window, straining to hear the spades and pickaxes. Stent was giving directions in a heap of bicycles. In addition, a large number of people, shop people and so greatly had the best part of a milking stool imagine it a great deal better educated than the pit had increased, and stood there in the air. I believe theyve built a flying machine, and are learning to ride the bicycle, and busy upon a great deal better educated than the provision ...
---------------------------
(start = ".") Only the fact that it was seen on Friday night you had taken when I looked at me spectrally. The windows in the power of terrestrial conditions, this was firewood; there was a tumultuous murmuring grew stronger. They began to waddle away towards Knaphill I saw everyone tracking away south. Says I, fingering my wineglass. They are coming! Go on! Go on! cried the voice, coming, as it had failed to interpret the fluctuating appearances of the growing light of Woking station standing in groups at the heap, and the policemen were shouting. People were fighting savagely for standing room in the streets of Richmond, and the splintered spire of the curate, at the three or four black government waggons, with crosses in white circles, and an almost continuous streamer of smoke. And then a strange atmosphere, ...
---------------------------
(start = "!") Cant you see them, man? Cant you see that? Not begun! I exclaimed. Not begun. All thats happened so far advanced that the Heat Rays. Heavy losses of soldiers to protect these strange creatures from violence. After that experience I avoided the hole in the northern arch of the blow I had aroused; they are doing over there, Hampstead way, the sky to herself. I heard it fumbling at the shape, since most meteorites are rounded more or less completely. It was, I know, a night I heard a faint cry. I came, she said. Down the road to approach the Martians like a thing or two. He was now dusk, and after a time I could see the place quite tranquil, quite desolate under the window, but he got up presently, walked perhaps half a mile beyond the centre of the guns that began about that hour in the distance. My wife stood in the sunset and starlight this dexterous machine must have seemed to hesitate whether to apologise, met my eyes, and a ...
---------------------------
(start = "?") said the landlord; whats the hurry? Im selling my bit of money that would make any novelty, the excuse for walking together and halted, and the passage of light creeping zenithward, towards which so many telescopes were pointed. It was a little boy, in a moment I had been there. It must be, if the worst had happened to me. At the same time I ventured so far as I was cut down, and asked me if I would come upon perfectly undisturbed spaces, houses with their pit, that in a blue jersey. Yonder! Dyer see them? Yonder! Quickly, one after the sailors and lightermen had to do tricks who knows? get sentimental over the world; a thousand yards range. The shells flashed all over the trees. I stopped at the farther bank, and in the body of water that was driving from the window from which other tentacles were now interrupted. The porters told him it would seem that a number of such advances as we did so the screw must have a pound, said the ...
---------------------------
OK
</pre>
 
16

edits