Spacy NER实体位置

Spacy NER entities postition

如何获取NER在spacy中找到的实体位置?

来自以下示例:

doc = nlp('Rami Eid is studying at Stony Brook University in New York')
print(list([(ent for ent in doc.ents])

结果:

['Rami Eid','Stony Brook University','New York']

但我需要每个实体在句子中的位置,以便我可以知道哪些标记属于各个实体。

如果我需要从这些结果中进行搜索,我可能会遇到单个词实体与其他实体的多个词匹配的情况。

实体是spacy.Spanclass的对象,意味着它继承了startend[=15]等方法=]等

>>> doc = nlp('Rami Eid is studying at Stony Brook University in New York')
>>> [(e.start, e.end) for e in doc.ents]
[(0, 2), (5, 8), (9, 11)]