Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pos taggging in nltk

# 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 :: replace in lists python 
Python :: replace in lists py 
Python :: knuth morris pratt algorithm 
Python :: __repr__ in python 
Python :: how to tell python to go back to a previous line 
Python :: rename rows pandas based on condiions 
Python :: max and min int in python 
Python :: roc auc score 
Python :: pytorch convert tensor dtype 
Python :: use functions to resample pandas 
Python :: python while loop guessing game 
Python :: python insert item into list 
Python :: python console install package 
Python :: regular expression syntax python 
Python :: python dict in dict 
Python :: python sort 2d list different sort order for different columns 
Python :: how print array in python with clean dublication 
Python :: remove toggle/pandaslux 
Python :: Install pygmt in Anaconda prompt 
Python :: pandas excelfile 
Python :: python check if attribute exists in dictionary 
Python :: matplotlib object oriented 
Python :: python remove (string) 
Python :: python function as argument 
Python :: request login python 
Python :: Code Example of Hashmap in Python 
Python :: why python stops after plt.show() 
Python :: how to access app.config globally in flask app 
Python :: ascii to int python 
Python :: get last save id django model 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =