views:

292

answers:

6

Hi everybody,

Good morning!

Have been trying to find an answer to this. How do you implement the 'related tags' functionality as used in many websites like our stackoverflow.com and http://tagexplorer.sandbox.yahoo.com/.

A user clicks on tag and he gets all the related tags connected to that.

Daksh

+8  A: 

My guess is that it is a correlation between which tags are most often used together.

For example:

  • Question A tagged with tag1, tag2
  • Question B tagged with tag1, tag3
  • Question C tagged with tag1, tag2

Then it's natural to assume that tag2 "is related to" tag1.

I would say the best place to learn would be O'Reilly's Programming Collective Intelligence book.

Swaroop C H
ok but if you have, suppose, 3 tags on a post you have to correlate each couple let's say (a,b) (b,c) (a,c) = binomial(3,2) = 3. if you have 10 tags you end up with 45 queries, 20 tags it's 190 and so on :]
gpilotino
A: 

A couple of ways come to mind. You could just do a quick query to select related tag names:

SELECT * FROM tags WHERE tag_name LIKE '%$current_tag%'

Another way would be to actually setup your tag table to have a relations field, maybe related IDs separated by commas, but this seems hellish to maintain.

I'm sure someone will come up with a better answer, so I'm quite curious as well.

Dave
A: 

Hmm, I'm not very good at math :-), but sounds like you are looking for the correlation between two tags. My first instinct would be to set the expected value to 50% (expecting each tag to appear on 50% of the articles - this might be way off), calculate the correlation coefficient of tags in pairs and decide that if the correlation is above a certain value (which you must determine by experimenting), they are related.

Alternatively you might get by using a simple measure like (number of articles they co-appear) / (total number of articles where at least one tag appears).

Cd-MaN
A: 

IMHO, I thought it is a ready made script which is being used.

Daksh
A: 

Maybe s.o. tracks how many time tags come together

  1. I insert Q1 with tags A + B so relationWeight(A,B) = 1

  2. I insert Q2 with tags A + B so relationWeight(A,B) = 2

  3. Now I delete Q1 and Q2. I have to know the "relationWeight" to disassociate tags when relationWeight=0

gpilotino
A: 

using (DataAccessDataContext db = new DataAccessDataContext()) { Repeater1.DataSource = from rt in db.RelatedTags where st.ITEMID == itemid select new TagView() { ID = rt.Tag.ID, NAME = rt.Tag.NAME }; Repeater1.DataBind();
}

///:)

emre
there are max 5 tags! don't forget!
emre