0
import numpy as np
import nltk
nltk.download('wordnet')
from nltk.corpus import wordnet as wn

def main(a):

    b = wn.synsets(a)
    return b

我在使用 nltk.corpus 导入 wordnet 时出错。我使用了 numpy 库,它工作正常,但在尝试导入 wordnet 时出现错误。注意:我已经在 Gradle 中安装了 nltk、wordnet。

python {
  pip {
    install "numpy"
    install "nltk"
    install "wordnet"
  }
}

Logcat 向我显示以下错误


 Resource [93mwordnet[0m not found.
      Please use the NLTK Downloader to obtain the resource:
    
      [31m>>> import nltk
      >>> nltk.download('wordnet')
      [0m
      For more information see: https://www.nltk.org/data.html
    
      Attempted to load [93mcorpora/wordnet[0m
    
      Searched in:
        - '/data/user/0/com.example.nlp/files/nltk_data'
        - '/usr/local/nltk_data'
        - '/usr/local/share/nltk_data'
        - '/usr/local/lib/nltk_data'
        - '/usr/share/nltk_data'
        - '/usr/local/share/nltk_data'
        - '/usr/lib/nltk_data'
        - '/usr/local/lib/nltk_data'
    **********************************************************************
    
        at <python>.nltk.data.find(data.py:585)
        at <python>.nltk.corpus.util.__load(util.py:80)
        at <python>.nltk.corpus.util.__load(util.py:85)
        at <python>.nltk.corpus.util.__getattr__(util.py:120)
        at <python>.hello.main(hello.py:10)
        at <python>.chaquopy_java.call(chaquopy_java.pyx:285)
        at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:257)
        at com.chaquo.python.PyObject.callAttrThrows(Native Method)
        at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
        at com.example.nlp.MainActivity.onCreate(MainActivity.java:26)
        at android.app.Activity.performCreate(Activity.java:6915)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
            ... 9 more
2020-10-17 18:05:18.975 2101-2101/com.example.nlp I/Process: Sending signal. PID: 2101 SIG: 9

4

1 回答 1

1

正如我在之前的回答中已经说过的:

  • wordnet pip 包显然与 NLTK 无关,因此您可以将其删除。
  • 由于仿真器错误,您可能需要nltk.download循环调用,如此所述。
于 2020-10-17T13:38:39.240 回答