我希望能从一个字符串中获取句子列表并将其打印出来,不想使用NLTK来实现。因此,需要在句子结尾的句号上进行分割,而不是在小数点、缩写或名称标题上进行分割,或者如果该句子包含.com。这是一个不起作用的正则表达式尝试。
import re
text = """\
Mr. Smith bought cheapsite.com for 1.5 million dollars, i.e. he paid a lot for it. Did he mind? Adam Jones Jr. thinks he didn't. In any case, this isn't true... Well, with a probability of .9 it isn't.
"""
sentences = re.split(r' *[\.\?!][\'"\)\]]* *', text)
for stuff in sentences:
print(stuff)
应该看起来像什么的示例输出
Mr. Smith bought cheapsite.com for 1.5 million dollars, i.e. he paid a lot for it.
Did he mind?
Adam Jones Jr. thinks he didn't.
In any case, this isn't true...
Well, with a probability of .9 it isn't.
tokenize.sent_tokenize()
相当粗暴。请看我的回答,了解它存在的许多问题。不要对提问者或问题不尊重,这实际上是非常复杂和有趣的,也是活跃研究的主题。 - smci