Python 使用django的textblob中缺少语料库错误
我使用的是Python 2.7、Django 1.8,我的服务器是Linux Ubuntu上的Apache。我有一个JSON文件,里面有23000条推文。我想根据预定义的类别对tweet进行分类。但当我运行代码时,它会在/处抛出Python 使用django的textblob中缺少语料库错误,python,django,textblob,Python,Django,Textblob,我使用的是Python 2.7、Django 1.8,我的服务器是Linux Ubuntu上的Apache。我有一个JSON文件,里面有23000条推文。我想根据预定义的类别对tweet进行分类。但当我运行代码时,它会在/处抛出MissingCorpusError并建议: 要下载必要的数据,只需运行 python -m textblob.download_corpora 我已经有了TextBlob的最新语料库。尽管如此,我还是得到了错误 My views.py如下所示: def get_twe
MissingCorpusError并建议:
要下载必要的数据,只需运行
python -m textblob.download_corpora
我已经有了TextBlob的最新语料库。尽管如此,我还是得到了错误
My views.py如下所示:
def get_tweets(request):
retweet = 0
category = ''
sentiment = ''
tweets_data_path = STATIC_PATH+'/stream.json'
tweets_data = []
tweets_file = open(tweets_data_path, "r")
for line in tweets_file:
try:
tweet = json.loads(line)
tweets_data.append(tweet)
except:
continue
subs = []
for l in tweets_data:
s = re.sub("http[\w+]{0,4}://t.co/[\w]+","",l)
subs.append(s)
for t in subs:
i = 0
while i < len(t):
text = t[i]['tweet_text']
senti = TextBlob(text)
category = cl.classify(text)
if senti.sentiment.polarity > 0:
sentimen = 'positive'
elif senti.sentiment.polarity < 0:
sentimen = 'negative'
else:
sentimen = 'neutral'
if text.startswith('RT'):
retweet = 1
else:
retweet = 0
twe = Tweet(text=text,category=category,
sentiment=sentimen, retweet= retweet)
twe.save()
i = i+1
return HttpResponse("done")
def get_tweets(请求):
转发=0
类别=“”
情绪=“”
tweets_data_path=STATIC_path+'/stream.json'
tweets_data=[]
tweets\u file=open(tweets\u数据路径,“r”)
对于tweets_文件中的行:
尝试:
tweet=json.loads(行)
tweets_data.append(tweet)
除:
持续
subs=[]
对于tweets_数据中的l:
s=re.sub(“http[\w+]{0,4}://t.co/[\w]+”,“”,l)
附加子项
对于t-in-subs:
i=0
而i0:
sentimen=‘阳性’
elif senti.touction.polarity<0:
sentimen=‘负’
其他:
哨兵=‘中立’
如果text.startswith('RT'):
转发=1
其他:
转发=0
twe=Tweet(text=text,category=category,
情绪=哨兵,转发=转发)
twe.save()
i=i+1
返回HttpResponse(“完成”)
我也有同样的问题。
当我下载nltk_数据时,它被放置到/root/nltk_data/,当我将此nltk_数据文件夹复制到/var/www/it works OK时
$ sudo cp -avr nltk_data/ /var/www/
我有女人的问题。我用的是蟒蛇,它对我有效。
这可能有助于:
$pip3安装-U textblob
$python3-m textblob.下载_corpora请发布json的结构。并将while循环重写为t中ti的。每个潜艇有多少条tweet?总共有23689条tweet。我应该发布json文件的结构还是特定的推文?$pip安装-U textblob$python-m textblob.download\U corpora