|There's more than one way to do things|
Create hierarchies from list of keywords -- well known algorithm?by revdiablo (Prior)
|on Feb 24, 2005 at 00:26 UTC||Need Help??|
Before I start, please note this is not strictly a Perl question. It is more of a general algorithms questions, and that's why I posted to Meditations.
A friend of mine has come up with a neat algorithm for creating a hierarchy from a messy bag of keywords. I was wondering if this was something novel or not, so I thought I would ask the Monks if anyone recognizes it.
Another reason I'm posting is simply because I like this algorithm. Whether it's new or not, it's simple and intuitive. It creates hierarchies in a way that seems natural and "right." I would like to hear other people's thoughts about it. Maybe there are some things I am overlooking.
The idea is to start with a list of items that have keywords assigned to them. The keywords are not necessarily chosen with a hierarchy in mind, yet by grouping commonly used keywords, a hierarchy can be synthesized. It goes something like this:
Thus, given the following items:
The frequencies would be:
And the hierarchy would end up looking like:
Here's my quick and dirty Perl implementation, so there's something to actually play with:
Update: funny that The Mad Hatter should mention tags. This was originally made to parse the tags from a http://del.icio.us dump and create a hierarchy of links from it. I used "keywords" instead of "tags" because I thought it would be a more generic term for essentially the same thing. :-)