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

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

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

问题

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 'wordnet' not found.
请使用NLTK Downloader获取资源:

>>> import nltk
>>> nltk.download('wordnet')

获取更多信息,请访问:https://www.nltk.org/data.html

尝试加载 'corpora/wordnet'

搜索位置:
- '/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
英文:
import numpy as np
import nltk
nltk.download(&#39;wordnet&#39;)
from nltk.corpus import wordnet as wn

def main(a):

    b = wn.synsets(a)
    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.

python {
  pip {
    install &quot;numpy&quot;
    install &quot;nltk&quot;
    install &quot;wordnet&quot;
  }
}

The Logcat shows me the following error


 Resource [93mwordnet[0m not found.
      Please use the NLTK Downloader to obtain the resource:
    
      [31m&gt;&gt;&gt; import nltk
      &gt;&gt;&gt; nltk.download(&#39;wordnet&#39;)
      [0m
      For more information see: https://www.nltk.org/data.html
    
      Attempted to load [93mcorpora/wordnet[0m
    
      Searched in:
        - &#39;/data/user/0/com.example.nlp/files/nltk_data&#39;
        - &#39;/usr/local/nltk_data&#39;
        - &#39;/usr/local/share/nltk_data&#39;
        - &#39;/usr/local/lib/nltk_data&#39;
        - &#39;/usr/share/nltk_data&#39;
        - &#39;/usr/local/share/nltk_data&#39;
        - &#39;/usr/lib/nltk_data&#39;
        - &#39;/usr/local/lib/nltk_data&#39;
    **********************************************************************
    
        at &lt;python&gt;.nltk.data.find(data.py:585)
        at &lt;python&gt;.nltk.corpus.util.__load(util.py:80)
        at &lt;python&gt;.nltk.corpus.util.__load(util.py:85)
        at &lt;python&gt;.nltk.corpus.util.__getattr__(util.py:120)
        at &lt;python&gt;.hello.main(hello.py:10)
        at &lt;python&gt;.chaquopy_java.call(chaquopy_java.pyx:285)
        at &lt;python&gt;.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

答案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:

确定