Random sentence from book: Difference between revisions
Content added Content deleted
m (further handle proper nouns, commas, and the apostrophe ’ which Gutenberg uses in words) |
|||
Line 38: | Line 38: | ||
""" Remove extraneous punctuation, but keep at least sentence-ending punctuation characters . ! and ? """ |
""" Remove extraneous punctuation, but keep at least sentence-ending punctuation characters . ! and ? """ |
||
text = replace(replace |
text = replace(replace(text, r"[^01-9a-zA-Z\.\?\!’,]" => " "), r"([.?!])" => s" \1") |
||
words = split(text, r"\s+") |
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. |
""" Keep account of what words follow words and how many times it is seen. |
||
Line 130: | Line 133: | ||
The landlord should leave his. |
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> |
</pre> |
||