在NLTK中导入WordNet

18 投票
2 回答
53001 浏览
提问于 2025-04-16 21:19

我想导入 wordnet 字典,但是当我从 wordnet 导入字典时,出现了这个错误:

 for l in open(WNSEARCHDIR+'/lexnames').readlines():
IOError: [Errno 2] No such file or directory: 'C:\\Program Files\\WordNet\\2.0\\dict/lexnames'

我在这个目录下安装了 wordnet2.1,但我还是无法导入。请帮我解决这个问题。

import nltk
from nltk import *
from nltk.corpus import wordnet
from wordnet import Dictionary

print '-----------------------------------------'
print Dictionary.length

2 个回答

9

你可以试试这些命令:

import nltk
nltk.download('wordnet')

这个对我有效。

30

以下内容对我有效:

>>> nltk.download()
# Download window opens, fetch wordnet
>>> from nltk.corpus import wordnet as wn

现在我有一个叫做 WordNetCorpusReader 的东西,简称 wn。我不明白你为什么要找一个 Dictionary 类,因为在文档中并没有列出这样的类。NLTK 书籍的第 2.5 节解释了你可以用 nltk.corpus.wordnet 模块做些什么。

撰写回答