本文整理汇总了Python中pytagcloud.create_tag_image函数的典型用法代码示例。如果您正苦于以下问题:Python create_tag_image函数的具体用法?Python create_tag_image怎么用?Python create_tag_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_tag_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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')
示例2: 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')
示例3: 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)
示例4: 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)
示例5: 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
示例6: 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
示例7: _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
示例8: 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)
示例9: 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)
示例10: 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')
示例11: 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"
示例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)
示例13: _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)
示例14: test_layouts
def test_layouts(self):
start = time.time()
tags = make_tags(get_tag_counts(self.hound.read())[:80], maxsize=120)
for layout in LAYOUTS:
create_tag_image(tags, os.path.join(self.test_output, 'cloud_%s.png' % layout),
size=(900, 600),
background=(255, 255, 255, 255),
layout=layout, fontname='Lobster')
print "Duration: %d sec" % (time.time() - start)
示例15: make_tag_cloud
def make_tag_cloud():
for line in sys.stdin:
try:
text += ' ' + line.strip().lower()
except:
pass
tags = make_tags(get_tag_counts(text), maxsize=150)
create_tag_image(tags, sys.argv[1] + '.png', size=(1024, 768))