我知道从文档中获取各种属性的基本spacy工作流程,但是我找不到内置函数来返回作为句子一部分的单词的位置(开始/结束).
有人会知道Spacy是否可以做到这一点?
我正在尝试通过迭代句子来获取单词的位置及其实体标签,按照 spacy 文档
import spacy
nlp = spacy.load('en')
doc = nlp(u'London is a big city in the United Kingdom.')
for ent in doc.ents:
print(ent.label_, ent.text)
# GPE London
# GPE United Kingdom
Run Code Online (Sandbox Code Playgroud)
我尝试使用标签 ent.i 和 ent.idx 获取单词的位置,但是这些都不起作用并给出以下错误
AttributeError: 'spacy.tokens.span.Span' object has no attribute 'i'
Run Code Online (Sandbox Code Playgroud) spacy ×2