[英]missing corpus error in textblob using django
I am using Python 2.7, Django 1.8 and my server is Apache on Linux Ubuntu. 我使用的是Python 2.7,Django 1.8,我的服务器是Linux Ubuntu上的Apache。 I have a JSON file with 23000 tweets in it.
我有一个包含23000条推文的JSON文件。 I want to classify the tweets according to predefined categories.
我想根据预定义的类别对推文进行分类。 But when I run the code, it throws
MissingCorpusError at /
and suggests: 但是当我运行代码时,它会抛出
MissingCorpusError at /
并建议:
To download the necessary data, simply run 要下载必要的数据,只需运行即可
python -m textblob.download_corpora
I already have the latest corpora for TextBlob. 我已经有了TextBlob的最新语料库。 Still, I get the error.
不过,我收到了错误。
My views.py is as follows: 我的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")
I have the same problem. 我也有同样的问题。 When i download nltk_data it was placed to /root/nltk_data/, when I copy this nltk_data folder to /var/www/ it works OK.
当我下载nltk_data时,它被放置到/ root / nltk_data /,当我将这个nltk_data文件夹复制到/ var / www /时,它工作正常。
$ sudo cp -avr nltk_data/ /var/www/
I had the dame problem. 我有这个女人的问题。 I am using anaconda and it worked for me.
我正在使用anaconda,它对我有用。 This might help:
这可能有所帮助:
http://www.nltk.org/data.html http://www.nltk.org/data.html
https://anaconda.org/anaconda/nltk https://anaconda.org/anaconda/nltk
$ pip3 install -U textblob $ pip3 install -U textblob
$ python3 -m textblob.download_corpora $ python3 -m textblob.download_corpora
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.