Example #1
0
def calculate_trends_for_site(trends_count, site, published):
    with suppress(BaseException):
        if site:
            daily_articles = Article.objects.filter(published=published, site=site)
        else:
            daily_articles = Article.objects.filter(published=published)

        texts = ' '.join([article.text for article in daily_articles])
        corpus = ProbabilityCorpus(texts)
        corpus.calc_prob_difference()
        DailyTrend(trends=dict(corpus.get_top_trends(trends_count)),
                   counts=dict(corpus.get_top_counts(trends_count)),
                   site=site, date=published).save()

        write_words_count(corpus, site, published)
Example #2
0
def calc_trends(file_name):
    corpus = ProbabilityCorpus.from_file(file_name)
    corpus.calc_prob_difference()
    diff = corpus.prob_difference

    write_trends(file_name, diff)
    sorted_diff = sorted(diff.items(), key=operator.itemgetter(1), reverse=True)

    return sorted_diff