def classify(self, results): """Classifies the results set by adding a "tag" attribute to each of the results. The same set of results are returned, with additional statistics and tagging. Each result gets one of the tags :), :( or :| And a stats section is added. @return an annotated array of results. [{"tag": "pos", "iso_language_code": "en", "text": "@chucklelate im not that excited about google voice. although it seems neat, i dont see myself using it.", "created_at": "Sat, 14 Mar 2009 00:00:03 +0000", "profile_image_url": "http:\/\/s3.amazonaws.com\/twitter_production\/profile_images\/80373954\/IMG_0008_normal.JPG", "to_user": "******", "source": "<a href="http:\/\/twitter.com\/">web<\/a>", "from_user": "******", "from_user_id": 5160745, "to_user_id": 409063, "id": 1324759664},...], """ c = BayesianClassifier() c.train(db.fetch_all_tweets()) for result in results: tag = c.classify(result['text']) result['tag'] = tag return results
def get(self): tweets = db.fetch_all_tweets() template_values = {'tweets': tweets} path = os.path.join(os.path.dirname(__file__), 'dbdrop.html') self.response.out.write(template.render(path, template_values))