【发布时间】:2015-12-21 07:39:49
【问题描述】:
我的程序获取一个文本文件并使用split('.') 将每个句子拆分为一个列表,这意味着它会在注册句号时拆分,但它可能不准确。
举例
str='i love carpets. In fact i own 2.4 km of the stuff.'
输出
listOfSentences = ['i love carpets', 'in fact i own 2', '4 km of the stuff']
期望的输出
listOfSentences = ['i love carpets', 'in fact i own 2.4 km of the stuff']
我的问题是:如何拆分句子的结尾而不是每个句号。
【问题讨论】:
-
listOfSentences = file.split(".")
-
拆分成句子是一项不平凡的任务。也许你可以试试自然语言工具包。 Link 类似的问题。
-
确实,还要考虑缩写,例如像这个。标记化和句子分割是一项非常有趣的任务,尽管没有得到充分的重视。NLTK 肯定具有标记化和句子分割功能。对于专门的解决方案,您还可以考虑将 ucto 与 python-ucto (github.com/proycon/ucto , github.com/proycon/python-ucto) 一起使用,它可以对各种语言进行标记和句子分割。 [免责声明:我是ucto的作者]