Random sentence from book: Difference between revisions

m
further handle proper nouns, commas, and the apostrophe ’ which Gutenberg uses in words
m (further handle proper nouns, commas, and the apostrophe ’ which Gutenberg uses in words)
Line 38:
 
""" Remove extraneous punctuation, but keep at least sentence-ending punctuation characters . ! and ? """
text = replace(replace(lowercase(text), r"[^01-9a-zA-Z\.\?\!\'’,]" => " "), r"([.?!])" => s" \1")
words = split(text, r"\s+")
for (i, w) in enumerate(words)
w != "I" && i > 1 && words[i - 1] in [".", "?", "!"] && (words[i] = lowercase(words[i]))
end
 
""" Keep account of what words follow words and how many times it is seen.
Line 130 ⟶ 133:
 
The landlord should leave his.
 
(RUN:)
 
And a cheer that seemed so happy and bright.
 
Once down one of the tangled maze of streets would have questioned my intellectual superiority
to his feet and had been in active service and he turned to see Lord Hilton, the lord of the parapet.
 
What has happened?
 
</pre>
 
4,103

edits