代码之家  ›  专栏  ›  技术社区  ›  lazarus

nltk-udhr模块中出错[已关闭]

  •  0
  • lazarus  · 技术社区  · 10 年前

    我在用python运行NLP代码片段时出错。。如下所示

    >>> from nltk.corpus import udhr
    >>> languages = ['Chickasaw','English','German_Deutsh',
    ...     'Greenlandic_Inuktikut','Hungarian_Magyar','Ibibio_Efik']
    >>> cfd = nltk.ConditionalFreqDist(
    ...             (lang,len(word))
    ...             for lang in languages
    ...             for word in udhr.words(lang + '-Latin1'))
    Traceback (most recent call last):
      File "<stdin>", line 3, in <module>
      File "/usr/local/lib/python2.7/dist-packages/nltk/probability.py", line 1729, in __init__
        for (cond, sample) in cond_samples:
      File "<stdin>", line 4, in <genexpr>
      File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/plaintext.py", line 91, in words
        in self.abspaths(fileids, True, True)])
      File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/reader/api.py", line 167, in abspaths
        paths = [self._root.join(f) for f in fileids]
      File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 176, in join
        return FileSystemPathPointer(path)
      File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 154, in __init__
        raise IOError('No such file or directory: %r' % path)
    IOError: No such file or directory: '/home/anupam/nltk_data/corpora/udhr/German_Deutsh-Latin1'
    

    我已经导入了所需的模块,如 导入nltk 我刚接触python,有人能告诉我错误到底是什么吗。。

    1 回复  |  直到 9 年前
        1
  •  1
  •   Basic    10 年前

    您输入了一个错别字:

    应该是 German_Deutsch German_Deutsh

    见第1.7节: http://www.nltk.org/book/ch02.html

    请注意,Stack跟踪的最后一行指示无法加载的语料库,如果您再次遇到此情况,这应该是一个提示