Пример #1
0
def sentiment():
    if query.count() > 0:
        articles = query.paginate_article(1, 100)

        for article in articles:
            if article.title:
                s = SnowNLP(article.title)
                article.feeling_factor = s.sentiments
            else:
                article.feeling_factor = -2

            article.save()

            logger.info("Sentiment SUCCEED ARTICLE<%s>" % article.uuid)
    else:
        time.sleep(10)
Пример #2
0
def sentiment():
    if query.count() > 0:
        articles = query.paginate_article(1, 100)

        for article in articles:
            if article.title:
                s = SnowNLP(article.title)
                article.feeling_factor = s.sentiments
            else:
                article.feeling_factor = -2

            article.save()
            
            logger.info("Sentiment SUCCEED ARTICLE<%s>" % article.uuid)
    else:
        time.sleep(10)
Пример #3
0
                          [(a_count[x]**2) for x in xrange(len(union))])
    denominator2 = reduce(lambda x, y: x + y,
                          [(b_count[x]**2) for x in xrange(len(union))])

    value = numerator / (math.sqrt(denominator1) * math.sqrt(denominator2))

    return value


if __name__ == '__main__':
    """
    test 1
    """
    # compare(jieba.cut(u"我喜欢看电视,不喜欢看电影"), jieba.cut(u"我不喜欢看电视,也不喜欢看电影"))
    """
    tese from mysql
    """

    title1 = u"中国铝业巨亏162亿元成亏损王"
    articles = query.paginate_article(1, 2000)

    for article in articles:
        if not title1 or not article.title:
            continue
        a = jieba.cut(title1)
        b = jieba.cut(article.title)
        value = compare(a, b)

        if value > 0.2:
            print title1.encode("utf-8"), article.title.encode("utf-8"), value
Пример #4
0
    denominator1 = reduce(lambda x, y: x + y, [(a_count[x] ** 2) for x in xrange(len(union))])
    denominator2 = reduce(lambda x, y: x + y, [(b_count[x] ** 2) for x in xrange(len(union))])

    value = numerator / (math.sqrt(denominator1) * math.sqrt(denominator2))

    return value


if __name__ == '__main__':
    """
    test 1
    """
    # compare(jieba.cut(u"我喜欢看电视,不喜欢看电影"), jieba.cut(u"我不喜欢看电视,也不喜欢看电影"))

    """
    tese from mysql
    """

    title1 = u"中国铝业巨亏162亿元成亏损王"
    articles = query.paginate_article(1, 2000)

    for article in articles:
        if not title1 or not article.title:
            continue
        a = jieba.cut(title1)
        b = jieba.cut(article.title)
        value = compare(a, b)

        if value > 0.2:
            print title1.encode("utf-8"), article.title.encode("utf-8"), value