Skip to content

Instantly share code, notes, and snippets.

Created January 12, 2013 03:50
Show Gist options
  • Save anonymous/4515960 to your computer and use it in GitHub Desktop.
Save anonymous/4515960 to your computer and use it in GitHub Desktop.
Split up text into sentences (roughly)
import re
with open("infile.txt", "r") as fp:
queue=""
match=r"[?!.]+\s+"
for rawLine in fp:
rawLine=" ".join((queue, rawLine))
queue=""
lines=rawLine.split(match)
if re.search(match+"$", rawLine):
queue=lines.pop()
for realLine in lines:
#feed line to bot here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment