nltk词性还原不充分,有的单词没被还原

我对一段纯英文文本用nltk分别进行了分词,去符号,标注,词性还原的操作,但是最终得到的单词还是和想象出入很大,是因为我用了分词使其失去了语境,从而无法如意标注词性导致还原的错误吗?

以下是我的标注和分词部分的代码,
#词性还原及去重
words_3=pos_tag(words_2) #词性标注

def get_wordnet_pos(tag):#获得词性的函数
if tag.startswith('J'):
return wordnet.ADJ
elif tag.startswith('V'):
return wordnet.VERB
elif tag.startswith('N'):
return wordnet.NOUN
elif tag.startswith('R'):
return wordnet.ADV

wnl=WordNetLemmatizer()

for tag in words_3:
wordnet_pos = get_wordnet_pos(tag[1]) or wordnet.NOUN # tag[1]指单词词性
book_words.append(wnl.lemmatize(tag[0], pos=wordnet_pos)) # tag[0]指单词本身

book_words=set(book_words)#去重

with open('book_words.txt','w')as fs:
fs.write(str(book_words))

画圈只是很小一部分,还有很多我不期待的词性还原不如意项

img

解决办法

1、POS 标记在句子上下文之外并不能很好地工作。
2、输入一个完整的句子pos_tag而不是一个单词,然后再试一次。
3、如果它不起作用,请使用nltk.download()获取更好的 POS 标记模型并运行它。
4、如果您需要单个单词的所有 POS 标签,请尝试 WordNet:

In [9]: nltk.corpus.wordnet.synsets('cat')
Out[9]: 
[Synset('cat.n.01'),
 Synset('guy.n.01'),
 Synset('cat.n.03'),
 Synset('kat.n.01'),
 Synset("cat-o'-nine-tails.n.01"),
 Synset('caterpillar.n.02'),
 Synset('big_cat.n.01'),
 Synset('computerized_tomography.n.01'),
 Synset('cat.v.01'),
 Synset('vomit.v.01')]

参考链接:

你没分词