I'm trying to get the position of a word and it's entity tag by iterating over a sentence, as per the spacy docs
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
I've tried to get the position of the word with the tag ent.i and ent.idx however neither of these work and give the following error
AttributeError: 'spacy.tokens.span.Span' object has no attribute 'i'
It would appear to be 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With