在使用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,(John,'B','PERSON'),(jumps,(over,(the,(lazy,(dog,'')]
这是一个元组列表。我要提取人员元素。这就是我要做的:
for i in inputlist:
if (i)[2] == "PERSON":
print ((i)[0])
John
有什么更好的方法?谢谢。