我对一段纯英文文本用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))
画圈只是很小一部分,还有很多我不期待的词性还原不如意项