Пример #1
0
def plot(game_name, game_id):
    dict = {}
    comments = DbUtil.getAllResult("select * from comment where game_id = %s" %
                                   game_id)
    for comment in comments:

        result = jieba.analyse.extract_tags(comment[2], topK=3)

        for word in result:
            if len(word) < 2:
                continue
            elif word in stop:
                continue

            if word not in dict:
                dict[word] = 1
            else:
                dict[word] += 1

    print(dict)

    swd = sorted(dict.items(), key=itemgetter(1), reverse=True)
    swd = swd[1:50]
    tags = make_tags(swd,
                     minsize=30,
                     maxsize=120,
                     colors=random.choice(list(COLOR_SCHEMES.values())))

    create_tag_image(tags,
                     'c:/%s.png' % game_name,
                     background=(0, 0, 0, 255),
                     size=(900, 600),
                     fontname='SimHei')

    print('having save file to dick')
def plot(game_name, game_id):
    dict = {}
    comments = DbUtil.getAllResult("select * from comment where game_id = %s" % game_id)
    for comment in comments:

        result = jieba.analyse.extract_tags(comment[2], topK=3)

        for word in result:
            if len(word) < 2:
                continue
            elif word in stop:
                continue

            if word not in dict:
                dict[word] = 1
            else:
                dict[word] += 1

    print(dict)

    swd = sorted(dict.items(), key=itemgetter(1), reverse=True)
    swd = swd[1:50]
    tags = make_tags(swd,
                     minsize=30,
                     maxsize=120,
                     colors=random.choice(list(COLOR_SCHEMES.values())))

    create_tag_image(tags,
                     'c:/%s.png' % game_name,
                     background=(0, 0, 0, 255),
                     size=(900, 600),
                     fontname='SimHei')

    print('having save file to dick')
Пример #3
0
def plot(game_name, game_id):
    dict = {}
    comments = DbUtil.getAllResult("select * from comment where game_id = %s" %
                                   game_id)
    for comment in comments:

        result = jieba.analyse.extract_tags(comment[2], topK=3)

        for word in result:
            if len(word) < 2:
                continue
            elif word in stop:
                continue

            if word not in dict:
                dict[word] = 1
            else:
                dict[word] += 1

    swd = sorted(dict.items(), key=itemgetter(1), reverse=True)
    swd = swd[1:50]

    tags = make_tags(swd,
                     minsize=30,
                     maxsize=100,
                     colors=random.choice(list(COLOR_SCHEMES.values())))

    create_tag_image(tags,
                     'C:/Users/Administrator/Desktop/%s_%s.png' %
                     (game_name, game_id),
                     background=(0, 0, 0, 255),
                     size=(900, 600),
                     fontname='SimHei')
    print('create file ---%s' % game_name)

    # dict = {}
    #
    # for (k, v) in swd:
    #     dict[k] = v
    # print('INSERT INTO keyword (game_id, keyword) VALUES (%s, "%s"' % (game_id, str(dict)))
    # cur.execute('INSERT INTO keyword (game_id, keyword) VALUES (%s, "%s")' % (game_id, str(dict)))
    # conn.commit()

    word = DbUtil.getOneResult('select keyword from keyword limit 1')
    print(eval(word[0]))
Пример #4
0
def plot(game_name, game_id):
    dict = {}
    comments = DbUtil.getAllResult("select * from comment where game_id = %s" % game_id)
    for comment in comments:

        result = jieba.analyse.extract_tags(comment[2], topK=3)

        for word in result:
            if len(word) < 2:
                continue
            elif word in stop:
                continue

            if word not in dict:
                dict[word] = 1
            else:
                dict[word] += 1

    swd = sorted(dict.items(), key=itemgetter(1), reverse=True)
    swd = swd[1:50]

    tags = make_tags(swd,
                     minsize=30,
                     maxsize=100,
                     colors=random.choice(list(COLOR_SCHEMES.values())))


    create_tag_image(tags,
                 'C:/Users/Administrator/Desktop/%s_%s.png' % (game_name, game_id),
                 background=(0, 0, 0, 255),
                 size=(900, 600),
                 fontname='SimHei')
    print('create file ---%s' % game_name)

    # dict = {}
    #
    # for (k, v) in swd:
    #     dict[k] = v
    # print('INSERT INTO keyword (game_id, keyword) VALUES (%s, "%s"' % (game_id, str(dict)))
    # cur.execute('INSERT INTO keyword (game_id, keyword) VALUES (%s, "%s")' % (game_id, str(dict)))
    # conn.commit()

    word = DbUtil.getOneResult('select keyword from keyword limit 1')
    print(eval(word[0]))
Пример #5
0
import random
from pytagcloud import create_tag_image, create_html_data, make_tags, \
    LAYOUT_HORIZONTAL, LAYOUTS
from pytagcloud.colors import COLOR_SCHEMES
from pytagcloud.lang.counter import get_tag_counts

wd = dict()
fp = codecs.open("rsa.txt", "r", 'utf-8')
lines = fp.readlines()
fp.close()

for line in lines:
    word = line.split(' ')
    print word
    wd[word[0]] = int(float(word[1]) * 100000)
print wd

from operator import itemgetter

swd = sorted(wd.iteritems(), key=itemgetter(1), reverse=True)
tags = make_tags(swd,
                 minsize=50,
                 maxsize=240,
                 colors=random.choice(COLOR_SCHEMES.values()))
create_tag_image(tags,
                 'keyword_tag_cloud4.png',
                 background=(0, 0, 0, 255),
                 size=(2400, 1000),
                 layout=LAYOUT_HORIZONTAL,
                 fontname="SimHei")
#!/usr/bin/env python
# coding=utf-8

# -*- coding: utf-8 -*-
import codecs
import random
from pytagcloud import create_tag_image, create_html_data, make_tags, \
    LAYOUT_HORIZONTAL, LAYOUTS
from pytagcloud.colors import COLOR_SCHEMES
from pytagcloud.lang.counter import get_tag_counts

wd = dict()
fp = codecs.open("rsa.txt", "r", 'utf-8')
lines = fp.readlines()
fp.close()

for line in lines:
    word = line.split(' ')
    print word
    wd[word[0]] = int(float(word[1]) * 100000)
print wd

from operator import itemgetter

swd = sorted(wd.iteritems(), key = itemgetter(1), reverse=True)
tags = make_tags(swd, minsize=50, maxsize=240, colors=random.choice(COLOR_SCHEMES.values()))
create_tag_image(tags, 'keyword_tag_cloud4.png', background=(0, 0, 0, 255), size=(2400, 1000), layout=LAYOUT_HORIZONTAL,
                 fontname="SimHei")