-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.py
More file actions
12 lines (9 loc) · 550 Bytes
/
Copy path3.py
File metadata and controls
12 lines (9 loc) · 550 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
from nltk import word_tokenize, PorterStemmer, WordNetLemmatizer
raw = "My name is Maximus Decimus Meridius, commander of the armies of the north, General of the Felix legions and loyal servant to the true emperor, Marcus Aurelius. Father to a murdered son, husband to a murdered wife. And I will have my vengeance, in this life or the next."
tokens = word_tokenize(raw)
porter = PorterStemmer()
stems = [porter.stem(t) for t in tokens]
print(stems)
lemmatizer = WordNetLemmatizer()
lemmas = [lemmatizer.lemmatize(t) for t in tokens]
print(lemmas)