python - NLTK Wordnet,错误排序(wn.langs())

标签 python nltk wordnet

所以我对此还比较陌生,我需要一些帮助。

所以我试图让 nltk 中的 Wordnet 使用开放多语言 WordNet。这是我访问的页面,其中显示了如何执行此操作 http://www.nltk.org/howto/wordnet.html

问题是当我尝试 sorted(wn.langs()) 时出现此错误

Traceback (most recent call last): 
File "<stdin>", line 1, in <module>
AttributeError: 'WordNetCorpusReader' object has no attribute 'langs'

由于我使用的是 python 2.7,我知道它必须是 sorted(wn.langs) 而不是 sorted(wn.langs()) 但无论哪种方式得到这个错误。

有人可以帮我解决这个问题吗?

最佳答案

我查了一下,我认为这是 NLTK 版本问题。您有什么 NLTK 版本?

如果您启动解释器然后运行

from nltk.corpus import wordnet as wn
sorted(wn.langs())

当我在 nltk==2.0.4(也使用 Python 2.7)下运行此代码时,我看到了与您相同的错误。所以我检查了源代码,langs(self)方法不存在。然而,看看最新的stable version on GitHub ,你可以看到它就在那里。

假设您正在使用 pip(如果您没有使用 pip,并且您使用 Windows go here 并遵循“替代说明”),请执行

pip install --upgrade nltk

并且应该安装nltk==3.0.0

再次运行代码,您应该会看到

>>> sorted(wn.langs())
[u'als', u'arb', u'cat', u'cmn', u'dan', u'eng', u'eus', u'fas', u'fin', u'fra', u'fre', u'glg', u'heb', u'ind', u'ita', u'jpn', u'nno', u'nob', u'pol', u'por', u'spa', u'tha', u'zsm']

关于python - NLTK Wordnet,错误排序(wn.langs()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25560879/

相关文章:

带有自定义缩写的 Python nltk 不正确的句子标记化

python - 如何使用 Python、NLTK 和 WordNet 获取反义词引理列表?

python - the_model = TheModelClass(*args, **kwargs) 是什么意思?

python - 将 pyodbc.rows 列表转换为 pandas Dataframe 需要很长时间

python - 使用 Google App Engine 标准环境时将 "/blog"转发到 WordPress 安装

python - 使用 Krippendorff Alpha 的 NLTK 注释者间协议(protocol)

python - 将列表 L 中的子字符串 l 与字符串 S 进行比较并根据 L 中的 l 编辑 S 的最Pythonic 方法?

python - 获取副词和形容词对应的动词和名词

python - 如何在 NLTK 的 Wordnet 中检索目标同义词集的反义词同义词集?