You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The doc.noun_chunks iterator is read-only, because it's computed by a getter function that uses the tokens' dependencies and part-of-speech tags. See lang/en/syntax_iterators.py for an example of this.
However, you could use a custom extension attribute to create your own custom noun chunks property on the Doc, and then make it return
fromspacy.tokensimportDocdefget_custom_noun_chunks(doc):
default_noun_chunks=list(doc.noun_chunks)
# Add your logic with the matcher etc. herecustom_noun_chunks=get_your_custom_chunks(doc)
returndefault_noun_chunks+custom_noun_chunksDoc.set_extension("custom_noun_chunks", getter=get_custom_noun_chunks)
You can then access doc._.custom_noun_chunks and it should return a list of the combined spans.
Feature description
Is there a way to append the doc.noun_chunk generator object in the way its possible to append the doc.ents tuple?
I can see the doc.ents can be appended with doc.ents += (new_entity,), but I've been unable to recreate with itertools.chain() for doc.noun_chunks.
The new noun_chunks are based on patterns identified by the pattern matcher.
Reproducing example code
in this case, would it be possible to add 'the enemy of America' to doc.noun_chunks?
The text was updated successfully, but these errors were encountered: