diff options
author | cedricbonhomme <devnull@localhost> | 2010-04-16 14:47:01 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2010-04-16 14:47:01 +0200 |
commit | 496f3a624d56dacc28a3ee9be152ba4a891014a6 (patch) | |
tree | ad42ddb8275da8e28c2e3bdfd42ccee75116a187 /utils.py | |
parent | Minor improvement. (diff) | |
download | newspipe-496f3a624d56dacc28a3ee9be152ba4a891014a6.tar.gz newspipe-496f3a624d56dacc28a3ee9be152ba4a891014a6.tar.bz2 newspipe-496f3a624d56dacc28a3ee9be152ba4a891014a6.zip |
Added tags cloud.
Diffstat (limited to 'utils.py')
-rwxr-xr-x | utils.py | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -85,7 +85,7 @@ def top_words(dic_articles, n=10): articles_content += remove_html_tags(article[4].encode('utf-8')) words_gen = (word.strip(punctuation).lower() \ for word in articles_content.split() \ - if len(word) >= 5) + if len(word) >= 6) words = defaultdict(int) for word in words_gen: words[word] += 1 @@ -93,6 +93,14 @@ def top_words(dic_articles, n=10): key=lambda(word, count): (-count, word))[:n] return top_words +def tag_cloud(tags): + """ + Generates a tags cloud. + """ + tags.sort(lambda x,y: cmp(x[0], y[0])) + return ' '.join([('<font size="%d"><a href="/q/?querystring=%s">%s</a></font>' % \ + (min(1+p*7/max([tag[1] for tag in tags]), 7), x, x)) for (x, p) in tags]) + def create_histogram(words, file_name="./var/histogram.png"): """ Create a histogram. |