stephbuon / posextract

Grammatical information extraction methods designed for the analysis of historical and contemporary textual corpora.
MIT License
3 stars 0 forks source link

Option to Extract Noun Chunks #177

Open stephbuon opened 1 year ago

stephbuon commented 1 year ago

Instead of just extracting the subject or just the object, extract the whole noun chunk. See under "Noun chunks": https://spacy.io/usage/linguistic-features#dependency-parse

import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("Autonomous cars shift insurance liability toward manufacturers")
for chunk in doc.noun_chunks:
    print(chunk.text, chunk.root.text, chunk.root.dep_,
            chunk.root.head.text)
stephbuon commented 1 year ago

@steph to validate