Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tagging a single word with the nltk pos tagger tags each letter instead of the word

I'm try to tag a single word with the nltk pos tagger:

word = "going"
pos = nltk.pos_tag(word)
print pos

But the output is this:

[('g', 'NN'), ('o', 'VBD'), ('i', 'PRP'), ('n', 'VBP'), ('g', 'JJ')]

It's tagging each letter rather than just the one word.

What can I do to make it tag the word?

like image 683
jksnw Avatar asked Apr 01 '15 18:04

jksnw


2 Answers

nltk.tag.pos_tag accepts a list of tokens, separate and tags its elements. Therefore you need to put your words in an iterable like list:

>>> nltk.tag.pos_tag(['going'])
[('going', 'VBG')]
like image 95
Mazdak Avatar answered Sep 22 '22 14:09

Mazdak


>>> word = 'going'
>>> word = nltk.word_tokenize(word)
>>> l1 = nltk.pos_tag(word)
>>> l1
[('going', 'VBG')]
like image 40
Ashok Kumar Jayaraman Avatar answered Sep 22 '22 14:09

Ashok Kumar Jayaraman