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?
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')]
>>> word = 'going'
>>> word = nltk.word_tokenize(word)
>>> l1 = nltk.pos_tag(word)
>>> l1
[('going', 'VBG')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With