Archive for February, 2012

Building a Twitter Sentiment Classifier

Wednesday, February 15th, 2012

For my final year project as part of my MEng Computer Science degree at UCL I conducted a sociometric analysis of London-based tweeters. I looked at correlating sentiment (i.e. the positivity/negativity — or happiness/sadness) of 32 million tweets for some 260,000 Twitter users against a number of other factors.

In order to determine the sentiment of each tweet, it was necessary to classify as either 1 corresponding to “positive”, -1 corresponding to “negative” or 0 corresponding to “unclassified” or “neutral”.

In the literature there have been many (many!) approaches to sentiment classification. The simplest method employs a simple word-counting algorithm whereby the word in each text fragment (in this case, tweet) is compared against a list of positive and negative words. The occurrence of each type of word is counted, and those tweets which contain more positive words than negative are classified as positive, and vice-versa for negative words.

(more…)

performSelector with Primitives, Enums, Structs and Objects

Friday, February 10th, 2012

Most iOS developers will at some point have come across performSelector: and its’ variants, which provide much greater flexibility than standard method calling, and is often used to defer method call decisions to runtime. Particularly when combined with NSSelectorFromString(), it becomes an incredibly powerful meta-programming tool.

However, one thing that performSelector: and its variants don’t handle well at all are primitives, enums and structs (hereon referred to simply as “primitives”). Because performSelector: heavily uses the generic id type which is only suitable for objects. Therefore, only objects can be specified as arguments, and only objects are returned (if a primitive is returned, it just reverts to nil).

However, there are often times when you are working not only with just objects, but also structs, enums and primitives both as arguments and as return values. I’ve therefore written a wrapper around NSInvocation (a more powerful set of tools than performSelector:) which handles passing pointers to primitives, and returning pointers to primitives.

(more…)