【发布时间】:2021-06-23 19:37:20
【问题描述】:
就像 spacy displacy 在 html 中呈现实体高亮一样。
import spacy
from spacy import displacy
nlp = spacy.load('en')
doc1 = nlp(u'This is a google sentence.')
doc2 = nlp(u'This is another sentence.')
html = displacy.render([doc1, doc2], style='ent', page=True)
如何突出显示给定文本中的所有动词。
from __future__ import unicode_literals
import spacy,en_core_web_sm
import textacy
nlp = en_core_web_sm.load()
sentence = 'The cat jumped quickly over the wall.'
doc = textacy.Doc(sentence, lang='en_core_web_sm')
for token in doc:
if (token.pos_ == 'VERB'):
print(token.text)
这里的输出 Jumped 将以绿色突出显示!怎么样?
类似的东西
【问题讨论】: