您的位置:首页 > 其它

win10下使用nltk的brown的词性tag包报错以及处理方法安装nltk相应包的操作办法

2017-06-17 21:43 671 查看
笔者近期练习NLP的给句子的词性进行tag操作,操作中出错,具体显示如下:

LookupError                               Traceback (most recent call last)
C:\Users\Administrator\Anaconda2\lib\site-packages\nltk\corpus\util.py in __load(self)
79             except LookupError as e:
---> 80                 try: root = nltk.data.find('{}/{}'.format(self.subdir, zip_name))
81                 except LookupError: raise e

C:\Users\Administrator\Anaconda2\lib\site-packages\nltk\data.py in find(resource_name, paths)
652     resource_not_found = '\n%s\n%s\n%s' % (sep, msg, sep)
--> 653     raise LookupError(resource_not_found)
654

LookupError:
**********************************************************************
Resource 'corpora/brown.zip/brown/' not found.  Please use the
NLTK Downloader to obtain the resource:  >>> nltk.download()
Searched in:
- 'C:\\Users\\Administrator/nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- 'C:\\Users\\Administrator\\Anaconda2\\nltk_data'
- 'C:\\Users\\Administrator\\Anaconda2\\lib\\nltk_data'
- 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
**********************************************************************

During handling of the above exception, another exception occurred:

LookupError                               Traceback (most recent call last)
<ipython-input-9-e6766bb96d33> in <module>()
9 brown_tags_words=[ ]
10
---> 11 for sent in brown.tagged_sents():
12     #添加开头:类似一个队列的开头添加,使用append()
13     brown_tags_words.append(("START","START"))

C:\Users\Administrator\Anaconda2\lib\site-packages\nltk\corpus\util.py in __getattr__(self, attr)
114             raise AttributeError("LazyCorpusLoader object has no attribute '__bases__'")
115
--> 116         self.__load()
117         # This looks circular, but its not, since __load() changes our
118         # __class__ to something new:

C:\Users\Administrator\Anaconda2\lib\site-packages\nltk\corpus\util.py in __load(self)
79             except LookupError as e:
80                 try: root = nltk.data.find('{}/{}'.format(self.subdir, zip_name))
---> 81                 except LookupError: raise e
82
83         # Load the corpus.

C:\Users\Administrator\Anaconda2\lib\site-packages\nltk\corpus\util.py in __load(self)
76         else:
77             try:
---> 78                 root = nltk.data.find('{}/{}'.format(self.subdir, self.__name))
79             except LookupError as e:
80                 try: root = nltk.data.find('{}/{}'.format(self.subdir, zip_name))

C:\Users\Administrator\Anaconda2\lib\site-packages\nltk\data.py in find(resource_name, paths)
651     sep = '*' * 70
652     resource_not_found = '\n%s\n%s\n%s' % (sep, msg, sep)
--> 653     raise LookupError(resource_not_found)
654
655

LookupError:
**********************************************************************
Resource 'corpora/brown' not found.  Please use the NLTK
Downloader to obtain the resource:  >>> nltk.download()
Searched in:
- 'C:\\Users\\Administrator/nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- 'C:\\Users\\Administrator\\Anaconda2\\nltk_data'
- 'C:\\Users\\Administrator\\Anaconda2\\lib\\nltk_data'
- 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
**********************************************************************


以上错误的原因就是nltk的语言等等tag包没准备好,所以需要对nltk进行补齐安装:
操作如下(博主的环境是python3.6,使用anaconda下的jupyter notebook界面做python开发)

在jupyter notebook中的cell中输入:

import nltk
nltk.download()


输入后点击运行该cell,也可以使用shift+回车 组合键执行cell

然后cell下方会弹出一句话:

showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml


并且,系统会开启一个界面:



以博主的尿性,必然是选择界面中的 all 这一行,再点击“download”,就静待整个过程的完结了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐