如何在spacy中查找文档中跨度的起始索引和结束索引



我正在使用spacy进行一些NLP工作。我有一个句子和一个名词块,如何使用spacy找到名词块的起始词索引和结束词索引?例如,如果我有";我住在纽约市";,名词组块是";纽约";,那么我想要3作为输出

import spacy
nlp = spacy.load("en_core_web_sm")
text="I live in New York City"
doc = nlp(text)
#To find the Noun chunks
Noun_chunks= [chunk.text for chunk in doc.noun_chunks]
#for loop to find the index of noun chunks
for noun in Noun_chunks:
starting_index = text.index(noun)
ending_index = text.index(noun) + len(noun) - 1
print(noun,starting_index,ending_index)
#output
#There are 2 noun_chunks: I and New York City
#I 0 0 (starting at 0 and ending at 0)
#New York City 10 22 (starting at 10 and ending at 22)