Nlp 空间动词突出显示?

Nlp 空间动词突出显示?,nlp,spacy,Nlp,Spacy,就像空间置换在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

就像空间置换在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)
这里的输出将以绿色突出显示!怎么做

类似的东西


通过在
render()
service()
上设置
manual=True
,可以使用displacy-ent界面高亮显示自定义实体。 下面是一个简单的例子:

sentence = [{'text': 'The cat jumped quickly over the wall.',
    'ents': [{'start': 8, 'end':14, 'label': 'VERB'}],
    'title': None}]

displacy.render(sentence, style='ent', manual=True)

此外,为了获得所需格式的数据,您可以进行依赖项解析,并使用它来获取
start
end