如何使用Spacy按句拆分文档
问题描述
如何将文档(如段落、书籍等)拆分成句子。
例如"The dog ran. The cat jumped"
into["The dog ran", "The cat jumped"]
with spacy?
解决方案
最新答案如下:
from __future__ import unicode_literals, print_function
from spacy.lang.en import English # updated
raw_text = 'Hello, world. Here are two sentences.'
nlp = English()
nlp.add_pipe(nlp.create_pipe('sentencizer')) # updated
doc = nlp(raw_text)
sentences = [sent.string.strip() for sent in doc.sents]
相关文章