Python nltk 在我尝试识别名词和动词时显示错误



我尝试识别Python中的名词和动词。我使用了 nltk 包,它向我显示了一个带有长红色字母的黄色错误。 我的代码:

import nltk

text = 'This is a table. We should table this offer. The table is in the center.'
text = nltk.word_tokenize(text)
result = nltk.pos_tag(text)
result = [i for i in result if i[0].lower() == 'table']
print(result) # it need to show: [('table', 'JJ'), ('table', 'VB'), ('table', 'NN')]

我的错误:

Traceback (most recent call last):
File "C:/Users/zivsi/PycharmProjects/AI/a.py", line 5, in <module>
text = nltk.word_tokenize(text)
File "C:UserszivsiAppDataLocalProgramsPythonPython36libsite-packagesnltktokenize__init__.py", line 144, in word_tokenize
sentences = [text] if preserve_line else sent_tokenize(text, language)
File "C:UserszivsiAppDataLocalProgramsPythonPython36libsite-packagesnltktokenize__init__.py", line 105, in sent_tokenize
tokenizer = load('tokenizers/punkt/{0}.pickle'.format(language))
File "C:UserszivsiAppDataLocalProgramsPythonPython36libsite-packagesnltkdata.py", line 868, in load
opened_resource = _open(resource_url)
File "C:UserszivsiAppDataLocalProgramsPythonPython36libsite-packagesnltkdata.py", line 993, in _open
return find(path_, path + ['']).open()
File "C:UserszivsiAppDataLocalProgramsPythonPython36libsite-packagesnltkdata.py", line 701, in find
raise LookupError(resource_not_found)
LookupError: 
**********************************************************************
Resource punkt not found.
Please use the NLTK Downloader to obtain the resource:
import nltk
nltk.download('punkt')
For more information see: https://www.nltk.org/data.html
Attempted to load tokenizers/punkt/english.pickle
Searched in:
- 'C:\Users\zivsi/nltk_data'
- 'C:\Users\zivsi\AppData\Local\Programs\Python\Python36\nltk_data'
- 'C:\Users\zivsi\AppData\Local\Programs\Python\Python36\share\nltk_data'
- 'C:\Users\zivsi\AppData\Local\Programs\Python\Python36\lib\nltk_data'
- 'C:\Users\zivsi\AppData\Roaming\nltk_data'
- 'C:\nltk_data'
- 'D:\nltk_data'
- 'E:\nltk_data'
- ''
**********************************************************************

你能帮我吗? 或者有另一个包要识别

我需要写:
import nltk nltk.download
('punkt'(

相关内容

最新更新