如何在Python中按句子拆分段落 [英] How to break up a paragraph by sentences in Python
本文介绍了如何在Python中按句子拆分段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从Python的一个段落中解析句子.是否有现有的软件包可以执行此操作,或者我应该在此处尝试使用正则表达式?
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?
推荐答案
nltk.tokenize
模块就是为此目的而设计的,并且可以处理边缘情况.例如:
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.']
这篇关于如何在Python中按句子拆分段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文