• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pytagcloud.make_tags函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pytagcloud.make_tags函数的典型用法代码示例。如果您正苦于以下问题:Python make_tags函数的具体用法?Python make_tags怎么用?Python make_tags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了make_tags函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: make_tag_cloud

def make_tag_cloud(data, can_be_noun_arg, process_option='freqs'):
    stop_words = sw.words()
    process_f = {
            'concatenate': lambda : concatenate(data, can_be_noun_arg, stop_words),
            'freqs': lambda : freq_weight(data, can_be_noun_arg, stop_words),
            'race' : lambda : race_tfidf(data, can_be_noun_arg, stop_words)
    }
    freqs = process_f[process_option]()
    if type(freqs) == type([]):
        freqs = freqs[:30]
        # normalize freqs in case they are counts
        sum_freqs = np.sum(x for _,x in freqs)
        freqs = [(w, np.float(f)/sum_freqs) for w,f in freqs]
        #pprint(freqs)
        #return
        tags = make_tags(freqs, maxsize=80)
        fname = 'noun_last_words_{}.png'.format(process_option)
        if not can_be_noun_arg:
            fname = 'not_'+fname
        create_tag_image(tags, fname, size=(900, 600), fontname='Lobster')
    elif type(freqs)==type({}):
        for k in freqs:
            top_freqs = freqs[k][:30]
            # normalize    
            sum_freqs = np.sum(x for _,x in top_freqs)
            top_freqs = [(w, np.float(f)/sum_freqs) for w,f in top_freqs]
            print top_freqs
            tags = make_tags(top_freqs, maxsize=15)
            fname = 'noun_last_words_{}_{}.png'.format(process_option,k)
            create_tag_image(tags, fname, size=(900, 600), fontname='Lobster')
开发者ID:raresct,项目名称:last_words,代码行数:30,代码来源:last_words.py


示例2: wordcloud

     def wordcloud(self,OVERALLTEXT,NEGATIVETEXT,POSITIVETEXT,test_output, font):
 
         #Constants
         overalltext = open(OVERALLTEXT, 'r')
         negativetext = open(NEGATIVETEXT, 'r')
         positivetext = open(POSITIVETEXT, 'r')
         
         #Overall
         tags = make_tags(get_tag_counts(overalltext.read())[:50],maxsize=90, minsize = 15)
         for layout in LAYOUTS:
             
             create_tag_image(tags,os.path.join(test_output, 'Overall_%s.png' % layout), size=(900,600),
                              background=(255, 255, 255), layout = layout, fontname = font, rectangular=True)
     
         #Negative
         tags = make_tags(get_tag_counts(negativetext.read())[:50], maxsize=90,minsize = 15, colors=COLOR_SCHEMES['audacity'])
         
         for layout in LAYOUTS: 
             create_tag_image(tags, os.path.join(test_output, 'negative_%s.png' % layout), 
                          size=(900,600), background=(205, 50, 50), 
                          layout=layout, fontname = font)
         
         #Positive
         tags = make_tags(get_tag_counts(positivetext.read())[:50], maxsize=120, minsize = 25, colors=COLOR_SCHEMES['oldschool'])
         
         for layout in LAYOUTS: 
             create_tag_image(tags, os.path.join(test_output, 'positive_%s.png' % layout), 
                          size=(900,600), background=(0, 255, 15), 
                          layout=layout, fontname = font) 
开发者ID:emmadickson,项目名称:Bellevue-Data-Science-Project,代码行数:29,代码来源:Comment_Tools.py


示例3: run

def run(textpath):
	text = open(textpath, 'r')
	start = time.time()
	taglist = get_tag_counts(text.read().decode('utf8'))
	cleantaglist = process_tags(taglist)
	tags = make_tags(taglist[0:100], colors=COLOR_MAP)
	create_tag_image(tags, 'cloud.png', size=(1280, 900), background=(0, 0, 0 , 255), layout=LAYOUT_MOST_HORIZONTAL, crop=False,  fontname='Cuprum', fontzoom=2)
	tags2 = make_tags(cleantaglist[0:100], colors=COLOR_MAP)
	create_tag_image(tags2, 'rcloud.png', size=(1280, 900), background=(0, 0, 0, 255), layout=LAYOUT_MOST_HORIZONTAL, crop=False, fontname='Cuprum', fontzoom=2)
	print "Duration: %d sec" % (time.time() - start)
开发者ID:Wild2,项目名称:ruspytagmap,代码行数:10,代码来源:generate.py


示例4: createTagCloud

 def createTagCloud(self,wordline):
     """
     Create tag cloud image 
     """
     wordstream = []
     if wordline == '':
         return False
     
     wordsTokens = WhitespaceTokenizer().tokenize(wordline)
     wordsTokens.remove(wordsTokens[0])
     wordstream.append(' '.join(wordsTokens))
     wordstream = ' '.join(wordstream)
     thresh = self.wordCount
     colorS = self.colorSchemes[self.color]
     
     tags = make_tags(get_tag_counts(wordstream)[:thresh],\
                      minsize=3, maxsize=40,\
                      colors = COLOR_SCHEMES[colorS])
     
     create_tag_image(tags, self.png,\
                      size=(960, 400),\
                      background=(255, 255, 255, 255),\
                      layout= LAYOUT_HORIZONTAL,\
                      fontname='Neuton')
     return True
开发者ID:BloodD,项目名称:PyTopicM,代码行数:25,代码来源:wordCloudDraw.py


示例5: word_cloud

def word_cloud(final_object, cloud_object):

    import re
    from pytagcloud.lang.stopwords import StopWords
    from operator import itemgetter
    final_object = [x for x in final_object if x != "no_object"]


    counted = {}

    for word in final_object:
        if len(word) > 1:
            if counted.has_key(word):
                counted[word] += 1
            else:
                counted[word] = 1
    #print len(counted)

    counts = sorted(counted.iteritems(), key=itemgetter(1), reverse=True)

    print "Total count of Word Cloud List Items: ",counts
    #type(counts)

    words = make_tags(counts, maxsize=100)
    print "Word Cloud List items: ", words


    create_tag_image(words, 'cloud_1_All_Objects.png', size=(1280, 900), fontname='Lobster')

    width = 1280
    height = 800
    layout = 3
    background_color = (255, 255, 255)
开发者ID:nus-iss-ca,项目名称:text-mining,代码行数:33,代码来源:Q2-Objects_Extraction.py


示例6: plot

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')
开发者ID:WhiteDevilBan,项目名称:CommentCrawler,代码行数:34,代码来源:CreateWordCloud.py


示例7: make_cloud

    def make_cloud(self, output_html):
        keywords = KeywordManager().all()
        text = ' '.join([kw.keyword for kw in keywords])

        if output_html:
            max_tags = 30
            max_size = 42
        else:
            max_tags = 100
            max_size = self.maxsize

        tags = make_tags(get_tag_counts(text)[:max_tags], minsize=self.minsize,
                         maxsize=max_size)

        if output_html:
            size = (900, 300)
            result = create_html_data(tags, size=size,
                                      layout=LAYOUT_HORIZONTAL)
        else:
            #now = datetime.utcnow()
            #filename = 'jcuwords/static/clouds/keyword-cloud-%s.png' % now.isoformat()
            cloud = self.resolver.resolve('jcuwords:keyword-cloud.png')
            filename = cloud.abspath()
            size = (1024, 500)
            create_tag_image(tags, filename, size=size,
                             fontname='IM Fell DW Pica',
                             layout=LAYOUT_MIX)
            image_url = self.request.resource_url(None, 'keyword-cloud.png')
            result = {'image': image_url}

        return result
开发者ID:jcu-eresearch,项目名称:jcu.words,代码行数:31,代码来源:views.py


示例8: get_tag_cloud

def get_tag_cloud(request, region_code):
    # Get all tweets in the region
    data_zone = DataZone.objects.get(code=region_code)
    tweet_locations = TweetLocation.objects.filter(zone=data_zone)

    body_text = ''

    for x in tweet_locations:
        body_text += x.tweet.body + ' '

    tc = TagCloud()
    body_text = tc.filter_body(body_text)

    if body_text.strip() == '':
        body_text = "Region Empty"

    tags = make_tags(get_tag_counts(body_text)[:50], maxsize=50, colors=COLOR_SCHEMES['audacity'])
    data = create_html_data(tags, (560,450), layout=LAYOUT_HORIZONTAL, fontname='PT Sans Regular')

    context = {}
        
    tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
    left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'
    
    context['tags'] = ''.join([tags_template % link for link in data['links']])
    context['width'] = data['size'][0]
    context['height'] = data['size'][1]
    context['css'] = "".join("a.%(cname)s{color:%(normal)s;}a.%(cname)s:hover{color:%(hover)s;}" % {'cname':k, 'normal': v[0], 'hover': v[1]} for k,v in data['css'].items())

    return render_to_response('tag_cloud.html', {'tags': context['tags'], 'css': context['css']})
开发者ID:camerongray1515,项目名称:ilwhack2014,代码行数:30,代码来源:views.py


示例9: _create_image

    def _create_image(self, text):
        tag_counts = get_tag_counts(text)
        if tag_counts is None:
            sys.exit(-1)

        if self._repeat_tags:
            expanded_tag_counts = []
            for tag in tag_counts:
                expanded_tag_counts.append((tag[0], 5))
            for tag in tag_counts:
                expanded_tag_counts.append((tag[0], 2))
            for tag in tag_counts:
                expanded_tag_counts.append((tag[0], 1))
            tag_counts = expanded_tag_counts

        tags = make_tags(tag_counts, maxsize=150, colors=self._color_scheme)
        path = os.path.join('/tmp/cloud_large.png')

        if Gdk.Screen.height() < Gdk.Screen.width():
            height = Gdk.Screen.height()
            width = int(height * 4 / 3)
        else:
            width = Gdk.Screen.width()
            height = int(width * 3 / 4)

        if self._font_name is not None:
            create_tag_image(tags, path, layout=self._layout,
                             size=(width, height),
                             fontname=self._font_name)
        else:
            create_tag_image(tags, path, layout=self._layout,
                             size=(width, height))
        return 0
开发者ID:sugarlabs,项目名称:wordcloud,代码行数:33,代码来源:wordcloud.py


示例10: create_cloud

def create_cloud(oname, words,maxsize=120, fontname='Lobster'):
    '''Creates a word cloud (when pytagcloud is installed)

    Parameters
    ----------
    oname : output filename
    words : list of (value,str)
    maxsize : int, optional
        Size of maximum word. The best setting for this parameter will often
        require some manual tuning for each input.
    fontname : str, optional
        Font to use.
    '''
    try:
        from pytagcloud import create_tag_image, make_tags
    except ImportError:
        if not warned_of_error:
            print("Could not import pytagcloud. Skipping cloud generation")
        return

    # gensim는 각 단어에 대해 0과 1사이의 가중치를 반환하지만 
    # pytagcloud는 단어 수를 받는다. 그래서 큰 수를 곱한다
    # gensim는 (value, word)를 반환하고 pytagcloud는 (word, value)으로 입력해야 한다
    words = [(w,int(v*10000)) for v,w in words]
    tags = make_tags(words, maxsize=maxsize)
    create_tag_image(tags, oname, size=(1800, 1200), fontname=fontname)
开发者ID:flyingbest,项目名称:machine-learning,代码行数:26,代码来源:wordcloud.py


示例11: test_create_html_data

 def test_create_html_data(self):
     """
     HTML code sample
     """
     tags = make_tags(get_tag_counts(self.hound.read())[:100], maxsize=120, colors=COLOR_SCHEMES['audacity'])
     data = create_html_data(tags, (440,600), layout=LAYOUT_HORIZONTAL, fontname='PT Sans Regular')
     
     template_file = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'web/template.html'), 'r')    
     html_template = Template(template_file.read())
     
     context = {}
     
     tags_template = '<li class="cnt" style="top: %(top)dpx; left: %(left)dpx; height: %(height)dpx;"><a class="tag %(cls)s" href="#%(tag)s" style="top: %(top)dpx;\
     left: %(left)dpx; font-size: %(size)dpx; height: %(height)dpx; line-height:%(lh)dpx;">%(tag)s</a></li>'
     
     context['tags'] = ''.join([tags_template % link for link in data['links']])
     context['width'] = data['size'][0]
     context['height'] = data['size'][1]
     context['css'] = "".join("a.%(cname)s{color:%(normal)s;}\
     a.%(cname)s:hover{color:%(hover)s;}" % 
                               {'cname':k,
                                'normal': v[0],
                                'hover': v[1]} 
                              for k,v in data['css'].items())
     
     html_text = html_template.substitute(context)
     
     html_file = open(os.path.join(self.test_output, 'cloud.html'), 'w')
     html_file.write(html_text)
     html_file.close()       
开发者ID:johnlaudun,项目名称:PyTagCloud,代码行数:30,代码来源:tests.py


示例12: create_cloud

def create_cloud(oname, words,maxsize=120, fontname='Lobster'):
    '''Creates a word cloud (when pytagcloud is installed)

    Parameters
    ----------
    oname : output filename
    words : list of (value,str)
    maxsize : int, optional
        Size of maximum word. The best setting for this parameter will often
        require some manual tuning for each input.
    fontname : str, optional
        Font to use.
    '''
    try:
        from pytagcloud import create_tag_image, make_tags
    except ImportError:
        if not warned_of_error:
            print("Could not import pytagcloud. Skipping cloud generation")
        return

    # gensim returns a weight between 0 and 1 for each word, while pytagcloud
    # expects an integer word count. So, we multiply by a large number and
    # round. For a visualization this is an adequate approximation.
    words = [(w,int(v*10000)) for w,v in words]
    tags = make_tags(words, maxsize=maxsize)
    create_tag_image(tags, oname, size=(1800, 1200), fontname=fontname)
开发者ID:Let4ik,项目名称:BuildingMachineLearningSystemsWithPython,代码行数:26,代码来源:wordcloud.py


示例13: tagCloud

    def tagCloud(self):
        texts =""
        for item in self.docSet:
            texts = texts +" " +item

        tags = make_tags(get_tag_counts(texts), maxsize=120)
        create_tag_image(tags,'filename.png', size=(2000,1000), background=(0, 0, 0, 255), layout=LAYOUT_MIX, fontname='Lobster', rectangular=True)
开发者ID:prathmeshgat,项目名称:SuicidalPersonDetection,代码行数:7,代码来源:TagCloud.py


示例14: generate_word_cloud

def generate_word_cloud(counts, title):
	# Sort the keywords
	sorted_wordscount = sorted(counts.iteritems(), key=operator.itemgetter(1), reverse=True)[:20]
	
	# Generate the word cloud image
	create_tag_image(make_tags(sorted_wordscount, minsize=50, maxsize=150), title + '.png', size=(1300,1150), 
		background=(0, 0, 0, 255), layout=LAYOUT_MIX, fontname='Molengo', rectangular=True)
开发者ID:eco2116,项目名称:Storytelling-Final-Project,代码行数:7,代码来源:articles.py


示例15: search

def search(query_word):
	result = []
	es = Elasticsearch()
	query1 = {"query": {"wildcard": {"name": {"value": "*" + query_word + "*" } } } }
	res = es.search(index="urban", body=query1)

	if res['hits']['total'] == 0:
		res = es.search(index="champ", body=query1)

	if res['hits']['total'] == 0:
		return 0

	ret = res['hits']['hits']

	temp = defaultdict(int)
	for item in ret:
		ids = item['_source']['business_id']
		query2 = {"query":  {"match": {"business_id": ids } } }
		res = es.search(index="my_data", body=query2)

		for item in res['hits']['hits'][0]['_source']['word_freq']:
			temp[item[0]] += item[1]

	words = []
	for item in temp:
		words.append((item,temp[item]))

	tags = make_tags(words, maxsize=80)

	create_tag_image(tags, 'static/cloud_large.jpg', size=(900, 600), fontname='Lobster')
开发者ID:neostoic,项目名称:DataVisualizerHack,代码行数:30,代码来源:searchapi.py


示例16: wordcloud

def wordcloud(query, layout, font, max_words, verbosity=False):
    my_oauth, complete_url, stop_words = twitter(query)
    punctuation = "#@!\"$%&'()*+,-./:;<=>?[\]^_`{|}~\'"  # characters exluded from tweets
    my_text = ''
    r = requests.get(complete_url, auth=my_oauth)
    tweets = r.json()
    if verbosity == True:
        print tweets
    for tweet in tweets['statuses']:
        text = tweet['text'].lower()
        text = ''.join(ch for ch in text if ch not in punctuation)  # exclude punctuation from tweets
        my_text += text

    words = my_text.split()
    counts = Counter(words)
    for word in stop_words:
        del counts[word]

    for key in counts.keys():
        if len(key) < 3 or key.startswith('http'):
            del counts[key]

    final = counts.most_common(max_words)
    max_count = max(final, key=operator.itemgetter(1))[1]
    final = [(name, count / float(max_count))for name, count in final]
    tags = make_tags(final, maxsize=max_word_size)
    create_tag_image(tags, query + '.png', size=(width, height), layout=layout, fontname=font, background=background_color)
    print "new png created"
开发者ID:IndicoDataSolutions,项目名称:sentimentalCloud,代码行数:28,代码来源:sentimentalCloud.py


示例17: _test_large_tag_image

 def _test_large_tag_image(self):
     start = time.time()
     tags = make_tags(get_tag_counts(self.hound.read())[:80], maxsize=120, 
                      colors=COLOR_SCHEMES['audacity'])
     create_tag_image(tags, os.path.join(self.test_output, 'cloud_large.png'), 
                      ratio=0.75, background=(0, 0, 0, 255), 
                      layout=LAYOUT_HORIZONTAL, fontname='Lobster')
     print "Duration: %d sec" % (time.time() - start)
开发者ID:johnlaudun,项目名称:PyTagCloud,代码行数:8,代码来源:tests.py


示例18: semantic_cloud

def semantic_cloud(topic):
    topic_list = TopicList(topic)
    tlist = topic_list.GetTopicList()
    htagsl = HashtagsList(tlist['statuses'], topic)
    hl = htagsl.GetHashtagsList()
    cadena = " ".join(hl)
    print cadena
    tags = make_tags(get_tag_counts(cadena), maxsize=120)
    create_tag_image(tags, 'semantic_cloud.png', size=(900, 600), fontname='Lobster')
开发者ID:Pycero91,项目名称:Segundo,代码行数:9,代码来源:ClassPyTw+V3.py


示例19: calAccuracy

	def calAccuracy(self):	
		self.cursor1.execute("select id, name from phone_id;")
		result = self.cursor1.fetchall()
		for data in result:
			print data[0],data[1]
		self.phone_id=raw_input("Enter phone id\n");
		self.name = raw_input("Enter name:")
		import os
		os.mkdir('/home/darshan-ubuntu/Project/Products/Features/'+self.name)

		self.getReview(1)
		tags = make_tags(get_tag_counts(self.actual_review), maxsize=120)
		create_tag_image(tags, self.name+'/positive.png', size=(900, 600))
		self.actual_review=""
		
		self.getReview(0)
		tags = make_tags(get_tag_counts(self.actual_review), maxsize=60)
		create_tag_image(tags, self.name+'/negative.png', size=(900, 600))
开发者ID:DarshanMn,项目名称:PhoneReviews,代码行数:18,代码来源:get_words.py


示例20: build_pytag_cloud

 def build_pytag_cloud(self):
   width = 900
   height = 575
   fileName = '{0}/{1}.{2}.{3}.{4}.png'.format(self.img_directory, self.state, self.city, width, height)
   items = sorted(self.tagcloud.iteritems(), key=itemgetter(1), reverse=True)
   tags = make_tags(items[:self.wordcount], maxsize=80)
   create_tag_image(tags, fileName, size=(width, height), fontname='Droid Sans')
   import webbrowser
   webbrowser.open(fileName) # see results
开发者ID:mitch-b,项目名称:fcc-comments-tagcloud,代码行数:9,代码来源:tagcloud_builder.py



注:本文中的pytagcloud.make_tags函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python counter.get_tag_counts函数代码示例发布时间:2022-05-27
下一篇:
Python pytagcloud.create_tag_image函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap