YouTube keyword web construction

I was interested in constructing a web of related keywords on youtube, based on their likelyhood of relating to one another, so I downloaded the YouTube SDK API and wrote some code. Here’s what I came up with (some of the methods are not posted here but you can get the idea). This method would be repeatedly called from tags already in the database that we are ‘upsert’-ing to. (I use the terminology ‘upsert’ to refer to insert-or-update.).

 
        public override void ParseRelatedTags(string tag, int limit)
        {
            int parsed = 0;
 
            YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
            query.Categories.Add(new QueryCategory(new AtomCategory(tag, YouTubeNameTable.KeywordSchema)));
            Feed<video> videoFeed = (new YouTubeRequest(_settings)).Get<video>(query);
            foreach (Video video in videoFeed.Entries)
            {
                try
                {
                    string keywordsString = video.Keywords;
                    string[] keywords = keywordsString.Split(new char[] { ',' });
                    for (int i = 0; i < keywords.Length; i++)
                    {
                        string keyword = keywords[i].Trim();
 
                        UpsertTag(keyword);
                        UpsertTagConnection(tag, keyword);
 
                        parsed++;
                        if (parsed >= limit)
                        {
                            Console.WriteLine("Hit limit of " + limit + ". Finished.");
                            return;
                        }
                    }
                }
                catch { /* oh noes! a programming crime! */ }
            }
        }

Update: This produced some interesting results:

TAG_NAME_A TAG_NAME_B EX_WEIGHT
beat it 19
beat jackson 18
beat michael 18
aloud girls 14
around the 13
backstreet boys 13
freddie queen 12
allen lily 11
apple macintosh 11
astley rick 11
basie count 11
david archuleta 11
achmed terrorist 10
animation animator 10
around world 10
backstreet pop 10
balisong knife 10
ballmer microsoft 10
computer apple 10
funny accidents 10

Posted: May 15th, 2010 | Author: | Filed under: benlakey.com | Tags: , , , , , | No Comments »