Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

lemmatization in nlp

# Lemmatize with POS Tag
from nltk.corpus import wordnet

def get_wordnet_pos(word):
    """Map POS tag to first character lemmatize() accepts"""
    tag = nltk.pos_tag([word])[0][1][0].upper()
    tag_dict = {"J": wordnet.ADJ,
                "N": wordnet.NOUN,
                "V": wordnet.VERB,
                "R": wordnet.ADV}

    return tag_dict.get(tag, wordnet.NOUN)


# 1. Init Lemmatizer
lemmatizer = WordNetLemmatizer()

# 2. Lemmatize Single Word with the appropriate POS tag
word = 'feet'
print(lemmatizer.lemmatize(word, get_wordnet_pos(word)))
Comment

PREVIOUS NEXT
Code Example
Python :: how to replace a string in python 
Python :: df set index 
Python :: kmp algorithm 
Python :: pandas describe 
Python :: python list object attributes 
Python :: get hex code of character python 
Python :: flask delete from database 
Python :: glob.glob python 
Python :: [<matplotlib.lines.Line2D object at 0x7fee51155a90] 
Python :: use functions to resample python 
Python :: python check characters in utf 8 
Python :: python set cookies 
Python :: extract address from text python 
Python :: pandas count occurrences of certain value in row 
Python :: How to get historical klines python binance 
Python :: openpyxl get row from sheet 
Python :: how stract avery .jpg string in a website python 
Python :: infinite monkey theorem 
Python :: Python Print hour, minute, second and microsecond 
Python :: numpy iterate over rows with index 
Python :: symmetrical sum 
Python :: Missing data counts and percentage 
Python :: python wrapper function 
Python :: python bubble plot 
Python :: resize qpushbutton pyqt 
Python :: email confirmation django 
Python :: plotly ylog 
Python :: cmap perlin noise python 
Python :: changing database of django 
Python :: Print and remove previous line 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =