使用nltk pos标记器标记单个单词会标记每个字母而不是单词 [英] Tagging a single word with the nltk pos tagger tags each letter instead of the word
本文介绍了使用nltk pos标记器标记单个单词会标记每个字母而不是单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用nltk pos标记器标记一个单词:
I'm try to tag a single word with the nltk pos tagger:
word = "going"
pos = nltk.pos_tag(word)
print pos
但是输出是这样的:
[('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')]
这篇关于使用nltk pos标记器标记单个单词会标记每个字母而不是单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文