Exemplo n.º 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')
Exemplo n.º 2
0
    def _setup_color_palette(self):
        palette_list = []
        palette_list.append({
            'icon': ColorImage('xo'),
            'selected': ColorImage('xo', selected=True),
            'callback': self.__color_selected_cb,
            'label': 'XO'
        })
        for color in list(COLOR_SCHEMES.keys()):
            palette_list.append({
                'icon':
                ColorIcon(COLOR_SCHEMES[color]),
                'selected':
                ColorIcon(COLOR_SCHEMES[color], selected=True),
                'callback':
                self.__color_selected_cb,
                'label':
                color
            })
        palette_list.append({
            'icon': ColorImage('random'),
            'selected': ColorImage('random', selected=True),
            'callback': self.__color_selected_cb,
            'label': _('random')
        })

        return palette_list
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')
Exemplo n.º 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]))
Exemplo n.º 5
0
    def _setup_color_palette(self):
        palette_list = []
        palette_list.append({'icon': ColorImage('xo'),
                             'selected': ColorImage('xo', selected=True),
                             'callback': self.__color_selected_cb,
                             'label': 'XO'})
        for color in COLOR_SCHEMES.keys():
            palette_list.append({'icon': ColorIcon(COLOR_SCHEMES[color]),
                                 'selected': ColorIcon(
                                     COLOR_SCHEMES[color], selected=True),
                                 'callback': self.__color_selected_cb,
                                 'label': color})
        palette_list.append({'icon': ColorImage('random'),
                             'selected': ColorImage('random', selected=True),
                             'callback': self.__color_selected_cb,
                             'label': _('random')})

        return palette_list
Exemplo n.º 6
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]))
Exemplo n.º 7
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")
Exemplo n.º 8
0
#!/usr/bin/python

# -*- coding: utf-8 -*-
import os, sys
from optparse import OptionParser, OptionGroup
from pytagcloud import create_tag_image, create_svg_image, create_html_data, make_tags

from pytagcloud.colors import COLOR_SCHEMES

import pytagcloud
import pytagcloud.helper

# globals
DEFAULT_COLOR = COLOR_SCHEMES.keys()[0]

class FontError(Exception):
    pass

def ParseOptions(options, args):
    # Check font 
    if not options.font in [pytagcloud.FONT_CACHE[i]['name'] for i in range(len(pytagcloud.FONT_CACHE))]:
        if not os.path.exists(options.font):
            raise(FontError('Font %s not found.'%(options.font)))
    
    '''
    if options.font is not '':                
        if os.path.exists(options.font): # check for aboslute reference
            font = options.font
        else:
            raise(FontError('Cannot find font %s'%(options.font)))        
        '''
#!/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")