How to break up a paragraph by sentences in Python

David542 picture David542 · Feb 28, 2012 · Viewed 19.2k times · Source

I need to parse sentences from a paragraph in Python. Is there an existing package to do this, or should I be trying to use regex here?

Answer

strcat picture strcat · Feb 28, 2012

The nltk.tokenize module is designed for this and handles edge cases. For example:

>>> from nltk import tokenize
>>> p = "Good morning Dr. Adams. The patient is waiting for you in room number 3."
>>> tokenize.sent_tokenize(p)
['Good morning Dr. Adams.', 'The patient is waiting for you in room number 3.']