[英]Error with “ blob = TextBlob(tweet[text])” in sentiment analysis using Python and Textblob
[英]missing corpus error in textblob using django
我使用的是Python 2.7,Django 1.8,我的服務器是Linux Ubuntu上的Apache。 我有一個包含23000條推文的JSON文件。 我想根據預定義的類別對推文進行分類。 但是當我運行代碼時,它會拋出MissingCorpusError at /
並建議:
要下載必要的數據,只需運行即可
python -m textblob.download_corpora
我已經有了TextBlob的最新語料庫。 不過,我收到了錯誤。
我的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")
我也有同樣的問題。 當我下載nltk_data時,它被放置到/ root / nltk_data /,當我將這個nltk_data文件夾復制到/ var / www /時,它工作正常。
$ sudo cp -avr nltk_data/ /var/www/
我有這個女人的問題。 我正在使用anaconda,它對我有用。 這可能有所幫助:
https://anaconda.org/anaconda/nltk
$ pip3 install -U textblob
$ python3 -m textblob.download_corpora
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.