Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 730 Bytes

spacy.adoc

File metadata and controls

44 lines (35 loc) · 730 Bytes

Spacy

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]