解决nltk download(‘brown’)连接尝试失败问题

解决nltk download(‘brown’)连接尝试失败

1、去下载官方包 (http://www.nltk.org/nltk_data/)

在这里插入图片描述

2、选择其中一个路径,将解压后的文件按照该路径放好

在这里插入图片描述

在这里插入图片描述

再运行一下代码

# nltk库提供了直接生成N-gram的方法
# 以布朗语料库的单词(token)为例,尝试使用它

from nltk.corpus import brown
from nltk.util import ngrams

token = []
for each in brown.categories():
    token.append(brown.words(categories = each))

unigram = ngrams(token, 1)
bigram  = ngrams(token, 2)

for i in unigram:
    print(i)

出现一下结果即下载成功

(['Dan', 'Morgan', 'told', 'himself', 'he', 'would', ...],)
(['Northern', 'liberals', 'are', 'the', 'chief', ...],)
(['Assembly', 'session', 'brought', 'much', 'good', ...],)
(['Thirty-three', 'Scotty', 'did', 'not', 'go', 'back', ...],)
(['The', 'Office', 'of', 'Business', 'Economics', '(', ...],)
(['Too', 'often', 'a', 'beginning', 'bodybuilder', ...],)
(['It', 'was', 'among', 'these', 'that', 'Hinkle', ...],)
(['1', '.', 'Introduction', 'It', 'has', 'recently', ...],)
(['In', 'American', 'romance', ',', 'almost', 'nothing', ...],)
(['There', 'were', 'thirty-eight', 'patients', 'on', ...],)
(['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ...],)
(['As', 'a', 'result', ',', 'although', 'we', 'still', ...],)
(['It', 'is', 'not', 'news', 'that', 'Nathan', ...],)
(['They', 'neither', 'liked', 'nor', 'disliked', 'the', ...],)
(['Now', 'that', 'he', 'knew', 'himself', 'to', 'be', ...],)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白*进阶ing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值