Open ali3assi opened 2 years ago
Hi @ali3assi, The error you are mentioning happens because by default the blank pipelines don't load the sentencizer. You can do the following:
import spacy
nlp = spacy.blank('en')
nlp.add_pipe('sentencizer')
nlp.add_pipe('dbpedia_spotlight')
doc = nlp("This is an example text. Let's mention Natural Language Processing")
for ent in doc.ents:
print(ent.text, ent.start_char-ent.sent.start_char, ent.end_char-ent.sent.start_char, ent.label_)
# Natural Language Processing 14 41 DBPEDIA_ENT
Or in alternative load one of the models that already load the sentencizer:
import spacy
# this needs to be installed https://spacy.io/models/en#en_core_web_sm
nlp = spacy.load('en_core_web_sm')
# then the following is the same
nlp.add_pipe('dbpedia_spotlight')
doc = nlp("This is an example text. Let's mention Natural Language Processing")
for ent in doc.ents:
print(ent.text, ent.start_char-ent.sent.start_char, ent.end_char-ent.sent.start_char, ent.label_)
# Natural Language Processing 14 41 DBPEDIA_ENT
Once I get the annotation of the entities how can get the starting position and ending position in the text. So I want to relate the text to its corresponding entity.
I do the following:
But I get the following exception: