Skip to content

Instantly share code, notes, and snippets.

@dksifoua
Created October 10, 2019 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dksifoua/dbd7bbdb71547614e28a011f89892a2d to your computer and use it in GitHub Desktop.
Save dksifoua/dbd7bbdb71547614e28a011f89892a2d to your computer and use it in GitHub Desktop.
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