【发布时间】:2013-11-20 11:15:29
【问题描述】:
我正在编写一个脚本,用 Python 将文本拆分成句子。但是我不擅长编写更复杂的正则表达式。
我希望根据 5 条规则来拆分句子。我想拆分句子,如果他们:
* end with "!" or
* end with "?" or
* end with "..." or
* end with "." and the full stop is not followed by a number or
* end with "." and the full stop is followed by a whitespace
Python 的正则表达式是什么?
【问题讨论】:
-
是否需要保留结尾字符?
-
显示您以前的尝试将是对问题的一个很好的补充:)
-
到目前为止我有一个非常基本的代码: import re splitter = r"\.(?!\d)" re.split(splitter, s) 但它将“USA”分成三个句子和“嘿...”是四个句子我不需要保留结尾字符。
-
正在为您使用库和选项?如果您这样做是为了进行一些自然语言处理,我真的建议您采用另一种方法。
-
任务是自己写一个简单的算法,所以库不是选项
标签: python regex nlp text-segmentation