当我试图识别名词和动词时,Python nltk显示错误

2024-06-07 13:00:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图识别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:\Users\zivsi\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\tokenize\__init__.py", line 144, in word_tokenize
    sentences = [text] if preserve_line else sent_tokenize(text, language)
  File "C:\Users\zivsi\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\tokenize\__init__.py", line 105, in sent_tokenize
    tokenizer = load('tokenizers/punkt/{0}.pickle'.format(language))
  File "C:\Users\zivsi\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\data.py", line 868, in load
    opened_resource = _open(resource_url)
  File "C:\Users\zivsi\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\data.py", line 993, in _open
    return find(path_, path + ['']).open()
  File "C:\Users\zivsi\AppData\Local\Programs\Python\Python36\lib\site-packages\nltk\data.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'
    - ''
**********************************************************************

你能帮我吗?或者还有其他需要识别的包


Tags: textinpydatalocallinetableusers

热门问题