简体   繁体   English

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

[英]Python nltk shows error when i try to identify nouns and verbs

I try to identify nouns and verbs in Python.我尝试在 Python 中识别名词和动词。 I used the nltk package and it shows me a yellow color error with a long red lettering.我使用了 nltk 包,它显示了一个带有红色长字的黄色错误。 my code:我的代码:

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')]

my error:我的错误:

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'
    - ''
**********************************************************************

can you help me?你能帮助我吗? or there are anothers packages to recognize或者有其他包可以识别

i needed to write:我需要写:
import nltk导入 nltk
nltk.download('punkt') nltk.download('朋克')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM