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

  1. 首先是看看wordnet.zipomw-1.4.zip,大小分别为12m11mntlk的数据在下载时不完整导致
  2. omw-1.4.zip是不存在的,githup上下载下来只有omw.zip;解决方案通过修改omw.zipomw-1.4.zip,并将其解压为omw-1.4;
  3. 文件的地址: wordnet.zipomw-1.4.zip

一系列操作过后,效果展示:

在这里插入图片描述

参考资料:

[1]: https://blog.csdn.net/weixin_41848012/article/details/124535050

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐