安装NLTK的方法请参考:https://blog.csdn.net/weixin_35757704/article/details/115629297
词性还原 Lemmatization
from nltk.stem import WordNetLemmatizer
def word_lemmatize(all_content):
lemmatize = WordNetLemmatizer()
for i, content in enumerate(all_content):
word = all_content[i]
word = lemmatize.lemmatize(word, pos='v')
word = lemmatize.lemmatize(word, pos='n')
all_content[i] = lemmatize.lemmatize(word, pos='a')
return all_content
if __name__ == '__main__':
print(word_lemmatize(['hello world', 'HELLO WORLDS']))