def add_tags(_, update, args, quoted_sticker_id): message = update.message arg_str = ' '.join(args) tags = extract_tags(arg_str) if not tags: message.reply_text('Usage: /add_tags *tags*') return if not sticker_storage.has_sticker_with_file_id(quoted_sticker_id): sticker_storage.add(file_id=quoted_sticker_id, owner_id=message.from_user.id) old_tags = sticker_storage.get_by_file_id(file_id=quoted_sticker_id, tagged=True).tags sticker_storage.add_tags_by_file_id(file_id=quoted_sticker_id, tags=tags, owner_id=message.from_user.id) current_tags = sticker_storage.get_by_file_id(file_id=quoted_sticker_id, tagged=True).tags added_tags = set(current_tags) - set(old_tags) if added_tags: result_message = ('Tags have been added!\n\n' + 'New tags: ' + ', '.join(sorted(added_tags))) else: result_message = 'No new tags have been added.' message.reply_text(result_message + '\n\n' + 'Current tags: ' + ', '.join(sorted(current_tags)))
def blog(): """ blog page """ content = u.get_content()["blog"] # Get all possible filtering tags tags = u.extract_tags(content.values()) return render_template( "blog.html", html_tab_title="Villoro - Blog", blog=content, tags=tags, **u.get_page("blog") )
def portfolio(): """ portfolio page """ content = u.get_content()["portfolio"] # Get all possible filtering tags tags = u.extract_tags(content.values()) return render_template("portfolio.html", portfolio=content, tags=tags, **u.get_page("portfolio"))
def tags_handler(_, update, user_data): message = update.message text = message.text.strip() tags = extract_tags(text) sticker_id = sticker_storage.add(file_id=user_data['sticker_file_id'], owner_id=message.from_user.id) sticker_storage.add_tags(sticker_id=sticker_id, tags=tags, owner_id=message.from_user.id) message.reply_text('Sticker has been added.') return ConversationHandler.END
return attempt raise Exception("Not found: " + fname) if output == "imagesamples": if dataset == 'ukbench': groupsize = 4 candidate_id = random.sample(range(len(image_names)), 1)[0] selected = extract_fname_id_test(image_names[candidate_id]) base_id = int(selected / groupsize) * groupsize targets = ["ukbench%05d.jpg" % i for i in range(base_id, base_id + groupsize)] captions = None elif dataset == 'mirflickr': training_images = utils.read_image_tags("../datasets/mirflickr", "-training") target_id = random.sample(range(len(image_names) / 2, len(image_names)), 3)[0] target = image_names[target_id] matches = utils.retrieve_matches(utils.extract_tags(target), training_images) targets = [] targets.append(target) for i in range(3): targets.append(matches[i]) captions = {} for target in targets: captions[target] = ", ".join(utils.extract_tags(target)) else: raise Exception('Unsupported') print(tex_image_table(targets, captions=captions)) if output in ["results1", "results2"]: if dataset == 'ukbench': captions = None if output == "results1":
def main(): vbmap = load_vbmap(sys.argv[1]) masters = extract_masters(vbmap['map']) replicas = extract_replicas(vbmap['map']) nodes = extract_nodes(vbmap['map']) nodes_count = len(nodes) nodes_dict = dict((n, i) for i, n in enumerate(nodes)) tags = extract_tags(vbmap, nodes) tags_list = sorted(set(tags.values())) tags_count = len(tags_list) pylab.figure() pylab.subplot(211) pylab.xticks([i + 0.5 for i in xrange(nodes_count)], nodes) plots = [hist(masters, nodes_dict)] + \ [hist(r, nodes_dict) for r in replicas] labels = ['master'] + ['replica %d' % i for i in xrange(len(replicas))] pylab.hist(plots, bins=xrange(nodes_count + 1), label=labels) pylab.title("Number of vbuckets per node") pylab.xlabel("Nodes") pylab.ylabel("Number of vbuckets") pylab.legend() pylab.subplot(212) pylab.xticks([i + 0.5 for i in xrange(nodes_count)], nodes) all_replicas = list(chain(*replicas)) pylab.hist(hist(all_replicas, nodes_dict), bins=xrange(nodes_count + 1), label='all replicas', rwidth=0.5) pylab.title("Number of replica vbuckets per node") pylab.xlabel("Nodes") pylab.ylabel("Number of vbuckets") pylab.legend() pylab.figure() pylab.subplot(211) plots = [[tags[n] for n in masters]] + \ [[tags[n] for n in r] for r in replicas] pylab.hist(plots, bins=xrange(tags_count + 1), label=labels) pylab.xticks([i + 0.5 for i in xrange(tags_count)], tags_list) pylab.title("Number of vbuckets per tag") pylab.xlabel("Tags") pylab.ylabel("Number of vbuckets") pylab.legend() pylab.subplot(212) pylab.xticks([i + 0.5 for i in xrange(nodes_count)], nodes) pylab.title("Number of nodes each node replicates to per tag") pylab.xlabel("Nodes") pylab.ylabel("Number of replica nodes") tags_repcounts = tag_replication_counts(vbmap['map'], nodes, tags_list, tags) plots = [] for tag_counts in tags_repcounts: plot = [] for node, count in enumerate(tag_counts): plot.extend([node] * count) plots.append(plot) pylab.hist(plots, bins=xrange(nodes_count + 1), label=map(str, tags)) pylab.legend() simulate(vbmap) pylab.show()
def test_that_extract_tags_leaves_only_alphanumeric_and_underline_characters(): assert extract_tags('this.is.a test') == ['thisisa', 'test']
def test_that_extract_tags_ignores_trailing_whitespace_and_comma_characters(): assert extract_tags('this is a test,') == ['this', 'is', 'a', 'test'] assert extract_tags('this is a test,,') == ['this', 'is', 'a', 'test'] assert extract_tags('this is a test ') == ['this', 'is', 'a', 'test'] assert extract_tags('this is a test ') == ['this', 'is', 'a', 'test'] assert extract_tags(', this is a test, ') == ['this', 'is', 'a', 'test']
def test_that_extract_tags_splits_on_whitespace_and_commma_characters(): assert extract_tags('this is a test') == ['this', 'is', 'a', 'test'] assert extract_tags('this, is, a, test') == ['this', 'is', 'a', 'test'] assert extract_tags('this, is a test') == ['this', 'is', 'a', 'test'] assert extract_tags('this,,,,,is,a,test') == ['this', 'is', 'a', 'test']
def generate_graphics_statement(image_path, width='.5in'): return "\\includegraphics[keepaspectratio=false, height=%s, width=%s]{%s}" % (width, width, image_path) targets = {} current_tags = None for line in lines1: if line.startswith('src'): continue if 'datasets' in line: if line.startswith('datasets'): current = line.split()[0] targets[current] = [] current_tags = extract_tags(current) else: image_path = line.split()[1] if len(targets[current]) >= 4: continue tags = extract_tags(image_path) targets[current].append((image_path, set(tags).intersection(set(current_tags)))) from pprint import pprint # fix up self for k, v in targets.iteritems(): others = [] for i in range(1, 4): image_path, tags = targets[k][i] others.extend(tags)
def extract_tags(text, topK=10): tf_tags = utils.extract_tags(text, topK=topK) rank_tags = utils.textrank(text, topK=topK) # 取tfidf和textrank结果的并集 return set(tf_tags + rank_tags)