Error in importing (from nltk.corpus import wordnet) in android studio using Chaquopy

huangapple go评论116阅读模式
英文:

Error in importing (from nltk.corpus import wordnet) in android studio using Chaquopy

问题

  1. import numpy as np
  2. import nltk
  3. nltk.download('wordnet')
  4. from nltk.corpus import wordnet as wn
  5. def main(a):
  6. b = wn.synsets(a)
  7. return b

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

  1. python {
  2. pip {
  3. install "numpy"
  4. install "nltk"
  5. install "wordnet"
  6. }
  7. }

Logcat显示了以下错误信息:

  1. Resource 'wordnet' not found.
  2. 请使用NLTK Downloader获取资源:
  3. >>> import nltk
  4. >>> nltk.download('wordnet')
  5. 获取更多信息,请访问:https://www.nltk.org/data.html
  6. 尝试加载 'corpora/wordnet'
  7. 搜索位置:
  8. - '/data/user/0/com.example.nlp/files/nltk_data'
  9. - '/usr/local/nltk_data'
  10. - '/usr/local/share/nltk_data'
  11. - '/usr/local/lib/nltk_data'
  12. - '/usr/share/nltk_data'
  13. - '/usr/local/share/nltk_data'
  14. - '/usr/lib/nltk_data'
  15. - '/usr/local/lib/nltk_data'
  16. **********************************************************************
  17. at <python>.nltk.data.find(data.py:585)
  18. at <python>.nltk.corpus.util.__load(util.py:80)
  19. at <python>.nltk.corpus.util.__load(util.py:85)
  20. at <python>.nltk.corpus.util.__getattr__(util.py:120)
  21. at <python>.hello.main(hello.py:10)
  22. at <python>.chaquopy_java.call(chaquopy_java.pyx:285)
  23. at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:257)
  24. at com.chaquo.python.PyObject.callAttrThrows(Native Method)
  25. at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
  26. at com.example.nlp.MainActivity.onCreate(MainActivity.java:26)
  27. at android.app.Activity.performCreate(Activity.java:6915)
  28. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
  29. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
  30. ... 9 more
  31. 2020-10-17 18:05:18.975 2101-2101/com.example.nlp I/Process: Sending signal. PID: 2101 SIG: 9
英文:
  1. import numpy as np
  2. import nltk
  3. nltk.download(&#39;wordnet&#39;)
  4. from nltk.corpus import wordnet as wn
  5. def main(a):
  6. b = wn.synsets(a)
  7. return b

I have error in importing wordnet using nltk.corpus. I have used the numpy library and it works fine, but gives me error when try to import wordnet.
Note: I have already installed the nltk, wordnet in Gradle.

  1. python {
  2. pip {
  3. install &quot;numpy&quot;
  4. install &quot;nltk&quot;
  5. install &quot;wordnet&quot;
  6. }
  7. }

The Logcat shows me the following error

  1. Resource [93mwordnet[0m not found.
  2. Please use the NLTK Downloader to obtain the resource:
  3. [31m&gt;&gt;&gt; import nltk
  4. &gt;&gt;&gt; nltk.download(&#39;wordnet&#39;)
  5. [0m
  6. For more information see: https://www.nltk.org/data.html
  7. Attempted to load [93mcorpora/wordnet[0m
  8. Searched in:
  9. - &#39;/data/user/0/com.example.nlp/files/nltk_data&#39;
  10. - &#39;/usr/local/nltk_data&#39;
  11. - &#39;/usr/local/share/nltk_data&#39;
  12. - &#39;/usr/local/lib/nltk_data&#39;
  13. - &#39;/usr/share/nltk_data&#39;
  14. - &#39;/usr/local/share/nltk_data&#39;
  15. - &#39;/usr/lib/nltk_data&#39;
  16. - &#39;/usr/local/lib/nltk_data&#39;
  17. **********************************************************************
  18. at &lt;python&gt;.nltk.data.find(data.py:585)
  19. at &lt;python&gt;.nltk.corpus.util.__load(util.py:80)
  20. at &lt;python&gt;.nltk.corpus.util.__load(util.py:85)
  21. at &lt;python&gt;.nltk.corpus.util.__getattr__(util.py:120)
  22. at &lt;python&gt;.hello.main(hello.py:10)
  23. at &lt;python&gt;.chaquopy_java.call(chaquopy_java.pyx:285)
  24. at &lt;python&gt;.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:257)
  25. at com.chaquo.python.PyObject.callAttrThrows(Native Method)
  26. at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
  27. at com.example.nlp.MainActivity.onCreate(MainActivity.java:26)
  28. at android.app.Activity.performCreate(Activity.java:6915)
  29. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
  30. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
  31. ... 9 more
  32. 2020-10-17 18:05:18.975 2101-2101/com.example.nlp I/Process: Sending signal. PID: 2101 SIG: 9

答案1

得分: 1

如我在我之前的回答中所提到的:

  • WordNet pip软件包显然与NLTK无关,因此可以将其移除。
  • 由于模拟器的错误,您可能需要按照这里所述,在循环中调用nltk.download
英文:

As I already said in my previous answer:

  • The wordnet pip package apparently has nothing to do with NLTK, so you can remove it.
  • Because of an emulator bug, you may need to call nltk.download in a loop, as described here.

huangapple
  • 本文由 发表于 2020年10月17日 21:18:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64402907.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定