手动安装 Open Multilingual Worldnet (NLTK)

Manually install Open Multilingual Worldnet (NLTK)

我正在使用一台只能访问专用网络的计算机,它无法从命令行发送 inst运行 操作。所以,每当我必须安装 Python 包时,我必须手动安装(我什至不能使用 Pypi)。幸运的是,NLTK 允许我手动下载语料库(来自 here) and to "install" them by putting them in the proper folder (as explained here)。

现在,我需要完全按照中所说的去做:


>>> cane_lemmas = wn.lemmas("cane", lang="ita")
>>> print(cane_lemmas) 

[Lemma('dog.n.01.cane'), Lemma('cramp.n.02.cane'), Lemma('hammer.n.01.cane'), Lemma('bad_person.n.01.cane'), Lemma('incompetent.n.01.cane')]

为此,我认为下载文件“52.Open Multilingual Wordnet”就足够了,将其解压缩到 C:\nltk_data\corpora 并在 运行 之前提到的代码之后导入

from nltk.corpus import wordnet as wn

然而,当我运行代码:


>>> cane_lemmas = wn.lemmas("cane", lang="ita")
>>> print(cane_lemmas) 

我收到这个错误:

WordNetError: line 'es; it won brilliant victories over British frigates during the War of 1812 and is without doubt the most famous ship in the history of the United States Navy; it has been rebuilt and is anchored in the Charlestown Navy Yard in Boston \n': not enough values to unpack (expected 2, got 1)

但是,如果我 运行:

>>> cane_lemmas = wn.lemmas("dog", lang="eng")
>>> print(cane_lemmas) 

我正确地得到:

[Lemma('dog.n.01.dog'), Lemma('frump.n.01.dog'), Lemma('dog.n.03.dog'), Lemma('cad.n.01.dog'), Lemma('frank.n.02.dog'), Lemma('pawl.n.01.dog'), Lemma('andiron.n.01.dog'), Lemma('chase.v.01.dog')]

我做错了什么?

我正在使用 python 3.7.4 和 nltk 3.4.5

为了确定,您能否验证您当前的 nltk_data 文件夹结构?正确的结构是:

nltk_data
+ corpora
  + wordnet
    + adj.exc
    + adv.exc
    + ...
  + omw
    + ...
    + ita
      + citation.bib
      + LICENSE
      + ...
    + ...

然而,在大多数情况下,问题是由于 nltk_data 安装不正确造成的,NLTK 会通知您安装存在问题(并且您必须执行 nltk.download("wordnet")解决它)

我认为,为了执行您的建议,您必须同时下载 wordnetomw

请记住,NLTK 现在支持 2 个版本的 OMW(还有 omw-1.4.,但仅在 NLTK 3.6.7 中添加了对此的支持)。此外,wordnet 有 3 个版本:wordnetwordnet2021wordnet31wordnet_ic。但是,我相信您应该可以坚持使用 omwwordnet.

有关 nltk_data 软件包的更多信息,请参阅 https://www.nltk.org/nltk_data/