我是Spacy
的新手,希望能够从句子中提取“所有”名词短语。我想知道如何实现。我有以下代码:
import spacy
nlp = spacy.load("en")
file = open("E:/test.txt", "r")
doc = nlp(file.read())
for np in doc.noun_chunks:
print(np.text)
但它只返回基础名词短语,即不包含其他NP
的短语。也就是说,对于以下短语,我得到以下结果:短语:
We try to explicitly describe the geometry of the edges of the images.
结果: We, the geometry, the edges, the images
.期望的结果是:
We, the geometry, the edges, the images, the geometry of the edges of the images, the edges of the images.
如何获取所有名词短语,包括嵌套的短语?