I am new to Spacy and I would like to extract \"all\" the noun phrases from a sentence. I\'m wondering how I can do it. I have the following code:
i
For every noun chunk you can also get the subtree beneath it.
Spacy provides two ways to access that:left_edge and right edge attributes and
the subtree attribute, which returns a Token iterator rather than a span.
Combining noun_chunks and their subtree lead to some duplication which can be removed later.
Here is an example using the left_edge and right edge attributes
{np.text
for nc in doc.noun_chunks
for np in [
nc,
doc[
nc.root.left_edge.i
:nc.root.right_edge.i+1]]}
==>
{'We',
'the edges',
'the edges of the images',
'the geometry',
'the geometry of the edges of the images',
'the images'}