Created
October 10, 2019 15:27
-
-
Save dksifoua/dbd7bbdb71547614e28a011f89892a2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from textblob import TextBlob | |
from textblob import blob | |
nltk.download('averaged_perceptron_tagger') | |
nltk.download('punkt') | |
nltk.download('wordnet') | |
def to_wordnet(tag): | |
_wordnet = _wordnet | |
if tag in ("NN", "NNS", "NNP", "NNPS"): | |
return blob._wordnet.NOUN | |
if tag in ("JJ", "JJR", "JJS"): | |
return blob._wordnet.ADJ | |
if tag in ("VB", "VBD", "VBG", "VBN", "VBP", "VBZ"): | |
return blob._wordnet.VERB | |
if tag in ("RB", "RBR", "RBS"): | |
return blob._wordnet.ADV | |
return blob._wordnet.NOUN | |
text = "Some texts" | |
text = TextBlob(text).tags | |
text = [Word(word).lemmatize(to_wordnet(tag)) for (word, tag) in text] | |
text = ' '.join(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment