Recent Entries

Rss Feed

Related Entries

Automatic tag generation for UltimateTagWarrior with Python

Saturday, November 25th, 2006

After 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:

  1. A frequency of 10
  2. >3 letters. We don’t care about short words.
  3. 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 ;)

5 Responses to “Automatic tag generation for UltimateTagWarrior with Python”

  1. Michiel Bijland Says:

    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

  2. Amy Stephen Says:

    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.

  3. Yury Timofeev Says:

    Please send me a copy.

  4. Tobias Schwarz Says:

    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

  5. Maurice Says:

    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!! :D

Leave a Reply