Automatic tag generation for UltimateTagWarrior with Python
Saturday, November 25th, 2006After importing categories as tags, I realized that the tag cloud at the bottom of the site was pretty lonely. Whatever is a programmer to do who has access to the underlying database for the posts and the tags? Hmmmmmm. Last night, I started putting together a python script to parse all of the posts of the site and generate a word-frequency list. Essentially, it finds all of the words of the site that meet the following requirements:
- A frequency of 10
- >3 letters. We don’t care about short words.
- Aren’t in a banned list of words that occur in regular speech like “it, was, green, dog, blue, friday, one”. The list is pretty big (and configurable).
From that exported word-frequency list, I selected 80 tags for my site which I preconfigured as the official tag list. From the official tag list, the appropriate wp_tags and wp_tag2post entries are created for tags that occur in each post, and in a matter of milliseconds, python has created them in the database.
Check out the tag cloud at the bottom. Pretty, eh?
This was all made possible because of mysqldb, a python implementation of the mysql libraries in python’s standard database API. In English: every database type in python inherits from a common API. That means that the code I wrote in python would be the same if it were for sqlite or posgresql.
Let me know if you want the python script. It worked wonders for me ![]()
November 25th, 2006 at 4:21 pm
Nice post and do send me a copy of the script as it has given my name a official tag on your site.
I don’t think I will use it but reviewing and learning from it will be more funny anyway.
- Michiel
December 8th, 2006 at 3:20 pm
I was happy for your marriage (even though that is small) that Bethany figures so prominently. And, it was good to see a BIG Joomla! and a smaller Drupal. Your code is socially acceptable.
December 29th, 2006 at 4:23 am
Please send me a copy.
March 29th, 2007 at 6:21 pm
Hi Brent,
I don’t know Python, but I’m wondering if you could nonetheless send me the script, as I am trying to get something similar going for my blog, albeit with “simple tagging”, PHP, and mySQL.
Thanks a lot,
Tobias
May 26th, 2008 at 2:46 am
Hey I definitely can use a script like this for my site. Though I’m not that well versed in python I definitely can find a way to make it work for me!!