concordia-preprocessor/tests/lemmatize.py
2019-06-26 12:17:07 +02:00

13 lines
326 B
Python
Executable File

#!/usr/bin/python3
import spacy
nlp = spacy.load('en', disable=['parser', 'ner'])
sentence = "The striped bats are hanging on their feet for best"
# Parse the sentence using the loaded 'en' model object `nlp`
doc = nlp(sentence)
# Extract the lemma for each token and join
print(" ".join([token.lemma_ for token in doc]))