我正在尝试通过迭代句子来获取单词的位置及其实体标签,按照 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)
看起来是 ent.start
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, ent.start)
#GPE London 0
#GPE the United Kingdom 6
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2145 次 |
| 最近记录: |