При использовании Spacy у меня есть следующее:
import spacy
nlp = spacy.load('en_core_web_lg')
sentence = "a quick John jumps over the lazy dog"
tag_entities = [(x, x.ent_iob_, x.ent_type_) for x in nlp(sentence)]
inputlist = tag_entities
print (inputlist)
[(a, 'O', ''), (quick, 'O', ''), (John, 'B', 'PERSON'), (jumps, 'O', ''), (over, 'O', ''), (the, 'O', ''), (lazy, 'O', ''), (dog, 'O', '')]
Это список кортежей. Я хочу извлечь элемент человека. Вот что я делаю:
for i in inputlist:
if (i)[2] == "PERSON":
print ((i)[0])
John
Что может быть лучше? Спасибо.