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

后端 未结 4 922
傲寒
傲寒 2021-01-18 02:55

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:

4条回答
  •  滥情空心
    2021-01-18 03:10

    The tagger works on a list of words. To turn the string into a list simply use something like

    word_list = [word]
    

    then use the pos tagger on the word_list. Note that if you have more than one word, you should run nltk.word_tokenize on the string first.

    As for the success in tagging only one word, you should look into the lookup tagger mentioned in section 4.3 here. The pos_tag used by nltk is more complicated than just a one word lookup tagger, but it does use one as part of the process, so you should see ok results.

提交回复
热议问题