How to break up a paragraph by sentences in Python

后端 未结 2 1019
独厮守ぢ
独厮守ぢ 2020-12-09 05:50

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?

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 06:46

    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.']
    

提交回复
热议问题