How to break up document by sentences with with Spacy

 ̄綄美尐妖づ 提交于 2019-12-06 01:37:26

问题


How can I break a document (e.g., paragraph, book, etc) into sentences.

For example, "The dog ran. The cat jumped" into ["The dog ran", "The cat jumped"] with spacy?


回答1:


The up-to-date answer is this:

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]



回答2:


From spacy's github support page

from __future__ import unicode_literals, print_function
from spacy.en import English

raw_text = 'Hello, world. Here are two sentences.'
nlp = English()
doc = nlp(raw_text)
sentences = [sent.string.strip() for sent in doc.sents]


来源:https://stackoverflow.com/questions/46290313/how-to-break-up-document-by-sentences-with-with-spacy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!