python - NLTK 的额外缩写列表?
问题描述
我正在尝试使用 Python + NLTK 对大量文章进行一些繁重的句子标记化。不幸的是,它对待“等”。作为句子的结尾而不是缩写。我怀疑它对其他缩写也会做同样的事情,比如“eg”或“ie”
我知道我可以添加如下内容:
sent_detector = nltk.data.load('tokenizers/punkt/english.pickle')
extra_abbreviations = ['et al']
sentence_tokenizer._params.abbrev_types.update(extra_abbreviations)
但我不想手动确定数据集中可能遇到的所有可能的额外缩写并手动输入它们。有没有人为这个特定问题想出一个更通用的解决方案,即使它只是一长串可以从文件加载并作为参数传递给更新方法的缩写?
解决方案
SpaCy 的句子标记器将为您解决这个问题。
import spacy
nlp = spacy.load('en_core_web_lg')
text = 'Exercise (e.g. riding a bike or taking a hike) will help you live longer. This is a second sentence'
doc = nlp(text)
sentences = [sent.string.strip() for sent in doc.sents]
print(sentences)
输出:['锻炼(例如骑自行车或远足)会帮助你活得更久。','这是第二句话']
推荐阅读
- cmake - CMake find_path / find_library 是否搜索
_ROOT 默认? - python - 从字典值中删除方括号的函数
- python - 使用 tkinter 为每个按钮添加不同的图像
- ansible - 使用 become:yes 运行 docker_container 需要什么 sudo 权限
- environment-variables - 当我在 SwiftUI 中使用 EnvironmentObject 时,选择器正在弹回
- python - zeep with python3 如何从响应中获取信息,
- css - 如何在 vuetify 上将按钮放在另一个按钮上
- extjs - 选择 ExtJS 标记字段中的值后,输入字段不会被清除
- r - 如何在R中的XML文件的注释中删除多次出现的符号,删除该符号并将其保存回具有原始名称的XML?
- node.js - 如何从猫鼬获取最后一个插入数组ID