I am trying to create a corpus of documents which consists of lemmatized nouns and noun-chunks. I am using this code:
import spacy
nlp = spacy.load('en_core_web_sm')
def lemmatizer(doc, allowed_postags=['NOUN']):
doc = [token.lemma_ for token in doc if token.pos_ in allowed_postags]
doc = u' '.join(doc)
return nlp.make_doc(doc)
nlp.add_pipe(nlp.create_pipe('merge_noun_chunks'), after='ner')
nlp.add_pipe(lemmatizer, name='lemm', after='merge_noun_chunks')
doc_list = []
for doc in data:
pr = nlp(doc)
doc_list.append(pr)
The sentence 'the euro area has advanced a long way as a monetary union' after identifiying noun-chunks ['the euro area', 'advanced', 'long', 'way', 'a monetary union'] and lemmatization gets to: ['euro', 'area', 'way', 'monetary', 'union'].
Is there a way to combine the words of the identified noun-chunks to get an output like this: ['the euro area','way', 'a monetary union'] or ['the_euro_area','way', 'a_monetary_union']?
Thanks for your help!