【问题标题】:NLTK for Google App Engine用于 Google App Engine 的 NLTK
【发布时间】:2020-04-13 05:58:36
【问题描述】:

我在this thread 上关注了所有内容,但我无法在 Google App Engine 上使用 NLTK。

我非常需要 GAE 上的 NLTK,请帮助。我面临以下问题。

>>> import nltk
>>> sentence = """At eight o'clock on Thursday morning
... Arthur didn't feel very good."""
>>> tokens = nltk.word_tokenize(sentence)
>>> tokens
['At', 'eight', "o'clock", 'on', 'Thursday', 'morning', '...', 'Arthur', 'did', "n't", 'feel', 'very', 'good', '.']
>>> tagged = nltk.pos_tag(tokens)

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    tagged = nltk.pos_tag(tokens)
  File "C:\Python27\lib\site-packages\nltk\tag\__init__.py", line 99, in pos_tag
    tagger = load(_POS_TAGGER)
  File "C:\Python27\lib\site-packages\nltk\data.py", line 605, in load
    resource_val = pickle.load(_open(resource_url))
  File "C:\Python27\lib\site-packages\nltk\data.py", line 686, in _open
    return find(path).open()
  File "C:\Python27\lib\site-packages\nltk\data.py", line 467, in find
    raise LookupError(resource_not_found)
LookupError: 
**********************************************************************
  Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not
  found.  Please use the NLTK Downloader to obtain the resource:
  >>> nltk.download()
  Searched in:
    - 'C:\\Users\\Anshu/nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'C:\\Python27\\nltk_data'
    - 'C:\\Python27\\lib\\nltk_data'
    - 'C:\\Users\\Anshu\\AppData\\Roaming\\nltk_data'
**********************************************************************
>>> 

【问题讨论】:

  • 1 & 2 的可能重复
  • @AshishNitinPatil 不,不要认为它与那些重复。这是 GAE 特有的。但是,它可能与 link 重复。
  • 你有一堆问题,nltk lib必须安装在appengine项目目录中,这样才能与代码一起部署。因此,您所做的任何事情 - 即您上面的外壳示例都与 appengine 安装无关。其次,nltk 需要的任何其他资源也需要在您的 appengine 项目中手动安装。

标签: python google-app-engine python-2.7 nltk


【解决方案1】:

如果有人正在寻找一个快速的答案(英文的分词器非常小,所以它适合谷歌应用引擎):

  1. http://www.nltk.org/nltk_data下载Punkt Tokenizer Models
  2. 在 app.yaml 所在的位置创建一个名为 /nltk_data/tokenizers/punkt/PY3 的目录
  3. 从 Punkt Tokenizer Models 文件 (punkt.zip) 的 PY3 目录中提取 english.pickle
  4. 将english.pickle 复制到./nltk_data/tokenizers/punkt/PY3/
  5. 只需在 app.yaml 中添加以下行: 环境变量: NLTK_DATA: './nltk_data/'

【讨论】:

    【解决方案2】:

    1) 转到您的云控制台

    2) 运行以下命令:

    pip install -U textblob
    python -m textblob.download_corpora
    

    它将下载带有语料库的 nltk 数据。现在只需再次部署您的应用,它就可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 2010-10-19
      • 2013-05-06
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多