nltk.stem.WordNetLemmatizer()时报错BadZipFile(“File is not a zip file“)的解决方法
问题描述
nltk里有个库可以很方便的还原单词的基本型,调用方法如下:
from nltk.stem import WordNetLemmatizer
lamma = WordNetLemmatizer()
lamma.lemmatize('cars', 'n')
安装完nltk,然后下载对应的语料库(python环境下执行)
import nltk
nltk.download("wordnet")
nltk.download("omw-1.4")
一般linux下的下载位置为 /home/[user_name]/nltk_data/corpura
1.File is not a zip file报错
文件不是一个zip(首先是wordnet.zipwen文件未下载完成)
##报错信息
zipfile.BadZipFile: File is not a zip file
2.owm-1.4不存在
githup上nltk_data整个库下载下来有664m,可以使用迅雷下载(比较快);下面文件地址附带了对应文件的下载网址;
原因解释:
一般linux下的下载位置为 /home/[user_name]/nltk_data/corpura
- 首先是看看
wordnet.zip
和omw-1.4.zip
,大小分别为12m
和11m
; ntlk的数据在下载时不完整导致; omw-1.4.zip
是不存在的,githup
上下载下来只有omw.zip
;解决方案通过修改omw.zip
为omw-1.4.zip
,并将其解压为omw-1.4
;- 文件的地址: wordnet.zip 和 omw-1.4.zip
一系列操作过后,效果展示:
参考资料:
[1]: https://blog.csdn.net/weixin_41848012/article/details/124535050