In nltk, if you want to improve the efficiency of application, word parts-of-speech is a very useful way. In this tutorial, we will introduce how to tag and extract the parts-of-speech of words in a sentence.
Import library
import nltk
Download resource if needed
nltk.download('averaged_perceptron_tagger')
Create a sentence
sentence = 'tutorialexample.com is a very good blog!'
Tokenize this sentence
text = nltk.word_tokenize(sentence)
Get the parts-of-speech of words
res = nltk.pos_tag(text) print(res
The result is:
[('tutorialexample.com', 'NN'), ('is', 'VBZ'), ('a', 'DT'), ('very', 'RB'), ('good', 'JJ'), ('blog', 'NN'), ('!', '.')]
To want to know full list of word part-of-speech, you can read this tutorial.
A Full List of Part-of-Speech of Word in NLTK – NLTK Tutorial