import spacy
nlp = spacy.load('en')
def create_pos_tag(text):
doc = nlp(u'' + text)
return [[token, token.tag_] for token in doc]
text = 'I want to book a flight'
tags = create_pos_tag(text)
def extract_nouns(tags):
nouns = [tag[0] for tag in tags if tag[1][:2] == 'NN']
return nouns
text = 'I want to book a flight'
tags = create_pos_tag(text)
nouns = extract_nouns(tags)
# [flight]