21. Streaming In Ruby There’s a gem for that gem install tweetstream Built IN DAEmonizATION TweetStream::Daemon.new(’usr','pwd') .track('term1’, 'term2') do |status| puts "#{status.text}" end
22.
23. Lazy Twitter Solution Simplest: CURB the basic rest api gem install curb status = Timeout::timeout(timeout) do r = Curl::Easy.perform(url) do |c| c.headers["User-Agent"] = ”TB/1.1” end response = r.body_str end
24. Lots of DB Writes Optimize import gem install ’activerecord-import’ tweets = [] raw_tweet = grab_tweets() raw_tweet.times do |t| tweets << Tweet.new(to_fields(raw_tweet)) end Tweet.import tweets
25. Twitter API Quirks - JSON and XML have different data - With Heroku must set a user-agent - Speed Varies - Query Complexity limits - Unpredictable rate limits
26.
27. Twitter Sentiment Analysis Bayesian Classification with Classifier gem + Interesting for age, mood, personality type - Not so good for sentiment on object require 'classifier’ b = Classifier::Bayes.new ’positive', ’negative’ b.train_positive ”I <3 my iPhone” b.train_negative ”iPhone can’t make calls #fail” b.classify ”iPhone is a rip off #fail" # returns ’negative'
28. Twitter Sentiment Analysis Natural Language Processing with Ruby Linguistics Find the direct object of the sentence => “dog” "he is a big dog".en.sentence.object.to_s Find the infinitive verb form of the sentence => “be” "he is a big dog".en.sentence.verb.infinitive
41. Get thumbnails don’t make your own #lazyclass TwitpicResolver < ImageResolver SEARCH_SNIPPET = "twitpic" URL = "http://twitpic.com/show/[size]/[id]" THUMB = "thumb" LARGE = "large" ID_EXTRACTOR = /twitpiccom(.*)/ end