【问题标题】:NLTK Wordnet, error sorted(wn.langs())NLTK Wordnet,错误排序(wn.langs())
【发布时间】:2014-08-29 02:35:30
【问题描述】:

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

所以我试图让 nltk 中的 Wordnet 使用 Open Multilingual 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()),但无论哪种方式都会出现此错误。

谁能帮我解决这个问题?

【问题讨论】:

    标签: python nltk wordnet


    【解决方案1】:

    我追查到这个,我认为这是一个 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(如果您不是,并且如果您使用 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']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-11
      • 2011-10-03
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多