Python - 用于将文本拆分为句子的正则表达式(句子标记)

标签 python regex nlp tokenize

我想从一个字符串中创建一个句子列表,然后将它们打印出来。我不想使用 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.

最佳答案

(?<!\w\.\w.)(?<![A-Z][a-z]\.)(?<=\.|\?)\s

试试这个。拆分你的字符串 this.You 也可以查看演示。

http://regex101.com/r/nG1gU7/27

关于Python - 用于将文本拆分为句子的正则表达式(句子标记),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25735644/

相关文章:

python - 将 pandas 数据框中的一行分解为多行

python - 使用python发送电子邮件: how to form the message?

Java:如果使用Pattern.quote(),是否保证在编译期间不会抛出PatternSyntaxException?

python - 水平和垂直标记

python - Mysql AES_DECRYPT() 函数在 Django 原始查询中不起作用

python - 对 Groovy 脚本调用的 Python 脚本中的异常进行编码

regex - 如何解决关于 'filter'字段必须是BSON类型对象的问题

c# - 从 html 文件中获取 javascript 代码

python - 属性错误 : 'FeatureChartParser' object has no attribute 'nbest_parse'

nlp - 短文本分类