英文:
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('wordnet')
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 "numpy"
install "nltk"
install "wordnet"
}
}
The Logcat shows me the following error
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
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论