user5315166
user5315166

Reputation: 51

missing corpus error in textblob using django

I am using Python 2.7, Django 1.8 and my server is Apache on Linux Ubuntu. I have a JSON file with 23000 tweets in it. I want to classify the tweets according to predefined categories. But when I run the code, it throws MissingCorpusError at / and suggests:

To download the necessary data, simply run

python -m textblob.download_corpora

I already have the latest corpora for TextBlob. Still, I get the error.

My views.py is as follows:

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")

Upvotes: 4

Views: 2856

Answers (2)

rzskhr
rzskhr

Reputation: 991

I had the dame problem. I am using anaconda and it worked for me. This might help:

http://www.nltk.org/data.html

https://anaconda.org/anaconda/nltk

$ pip3 install -U textblob

$ python3 -m textblob.download_corpora

Upvotes: 0

Gašper Gračner
Gašper Gračner

Reputation: 129

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.

$ sudo cp -avr nltk_data/ /var/www/

Upvotes: 2

Related Questions