【问题标题】:missing corpus error in textblob using django使用 django 在 textblob 中缺少语料库错误
【发布时间】:2015-12-11 04:47:30
【问题描述】:

我使用的是 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")

【问题讨论】:

  • 请贴出json的结构。并将 while 循环重写为 for ti in t 。每个订阅者有多少条推文?
  • 总共有 23689 条推文。我应该发布 json 文件的结构还是特定的推文?

标签: python django textblob


【解决方案1】:

我遇到了贵妇问题。我正在使用 anaconda,它对我有用。 这可能会有所帮助:

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

https://anaconda.org/anaconda/nltk

$ pip3 install -U textblob

$ python3 -m textblob.download_corpora

【讨论】:

  • $ pip install -U textblob $ python -m textblob.download_corpora
【解决方案2】:

我也有同样的问题。 当我下载 nltk_data 时,它被放置到 /root/nltk_data/,当我将此 nltk_data 文件夹复制到 /var/www/ 时,它工作正常。

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

【讨论】:

    猜你喜欢
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 2018-04-10
    • 1970-01-01
    相关资源
    最近更新 更多