NLTK panlex_lite 给我错误 [英] NLTK panlex_lite giving me error

查看:21
本文介绍了NLTK panlex_lite 给我错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 NLTK 用于我在 Python 中的 NLP 学习.

I'm trying to use NLTK for my NLP learning in Python.

某些名为panlex_lite"的包一直给我错误,所以我尝试使用以下方法:

Certain package called "panlex_lite" keeps giving me error so I tried using the following:

import nltk
nltk.download('all', halt_on_error = False)

它给了我以下错误:

[nltk_data]    | Downloading package panlex_lite to
[nltk_data]    |     /Users/Harshil/nltk_data...
[nltk_data]    |   Unzipping corpora/panlex_lite.zip.
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
  nltk.download('all', halt_on_error = False)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk/downloader.py", line 664, in download
for msg in self.incr_download(info_or_id, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk/downloader.py", line 543, in incr_download
for msg in self.incr_download(info.children, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk/downloader.py", line 529, in incr_download
for msg in self._download_list(info_or_id, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk/downloader.py", line 572, in _download_list
for msg in self.incr_download(item, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk/downloader.py", line 549, in incr_download
for msg in self._download_package(info, download_dir, force):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk/downloader.py", line 638, in _download_package
for msg in _unzip_iter(filepath, zipdir, verbose=False):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk/downloader.py", line 2039, in _unzip_iter
outfile.write(contents)
OSError: [Errno 22] Invalid argument

无论如何要解决这个问题?我试过使用halt_on_error = False"方法,但它仍然给我错误.

Anyway to fix this? I've tried using "halt_on_error = False" method but it still gives me error.

谢谢.

推荐答案

这是一个肮脏的"黑客:

Here's a "dirty" hack:

$ rm /Users/Harshil/nltk_data/corpora/panlex_lite.zip
$ rm -r /Users/Harshil/nltk_data/corpora/panlex_lite
$ python

>>> import nltk
>>> dler = nltk.downloader.Downloader()
>>> dler._update_index()
>>> dler._status_cache['panlex_lite'] = 'installed' # Trick the index to treat panlex_lite as it's already installed.
>>> dler.download('all')

<小时>

另外,试试earthy:

pip install earthy

TL;DR:

import earthy
path_to_nltk_data = '/home/yourusername/nltk_data/'
earthy.download('all', path_to_nltk_data) # Excludes the third party (non-NLTK) packages.

要独家下载 panlex_lite:

import earthy
earthy.download('panlex_lite', path_to_nltk_data)

要下载不是在 nltk_data github 上本地托管的所有第三方数据集:

To download all third-party datasets not natively hosted on nltk_data github:

import earthy
earthy.download('third_party', path_to_nltk_data')

这篇关于NLTK panlex_lite 给我错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆