NLTK及nltk_data安装教程

安装nltk

pip3 install nltk

安装nltk_data 打开 https://github.com/nltk/nltk_data 页面,点击绿色按钮下载整个压缩包。可以通过解压缩到指定的目录(目录可运行下面代码)

import nltk
print(nltk.data.path)

测试

from nltk.book import *

#输出以下结果则安装成功
*** Introductory Examples for the NLTK Book ***
Loading text1, ..., text9 and sent1, ..., sent9
Type the name of the text or sentence to view it.
Type: 'texts()' or 'sents()' to list the materials.
text1: Moby Dick by Herman Melville 1851
text2: Sense and Sensibility by Jane Austen 1811
text3: The Book of Genesis
text4: Inaugural Address Corpus
text5: Chat Corpus
text6: Monty Python and the Holy Grail
text7: Wall Street Journal
text8: Personals Corpus
text9: The Man Who Was Thursday by G . K . Chesterton 1908

但是,等运行代码时,发现如下错误:

[nltk_data] Error loading punkt: <urlopen error [WinError 10060]

按照提示操作还是不行,后来百度到了方法,记录一下

命令行进入python交互模式,运行如下:

import nltk
nltk.download()

然后会弹出一个窗口,点击models,找到punkt,双击进行下载即可。 下载punkt

本文作者:肖云

本文链接:http://www.d7dd.com/2022/9/nltk-nltk-data

版权声明:本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0许可协议。转载请注明出处!

0 条评论
已登录,注销 取消