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 twitgraph(request): bayesname = 'bayesdata' srch = 'happy' tag = 'n' c = BayesianClassifier() if not memcache.get('bayesdata'): c.save() #laod form local file system c.load() #load picke from memecache '''q=request.get_all("q")''' if (request.GET.has_key('q')): srch = request.GET['q'] tag = c.classify(srch) html = "<html><body>sentiment is %s </body></html>" % tag #return HttpResponse(html) gv = globvars context = {'thispage': 'Sentiment', 'the_tweet': srch, 'sentmnt': tag} context = dict(context, **gv.context) return render_to_response('sentiment.html', context)
def classify(self, results): c = BayesianClassifier() c.train(db.fetch_all_status()) for result in results: message = "%s" % result.get('message') comments = result.get('comments') tag = c.classify(message) x = {str('sentiment'):str(tag)} result.update(x) if 'data' in comments: for cm in comments.get('data'): comment = "%s" % cm.get('message') c_tag = c.classify(comment) cm.update(sentiment=c_tag) return results
def get(self): id = self.request.get("id") c = BayesianClassifier() #access_token = self.request.cookies.get('at', '') analyzer = StatusAnalyzer() fetcher = StatusFetcher() info_dict = fetcher.FetchInfo(id) data = fetcher.FetchWall(id) classified_results = analyzer.classify(data.get("data")) template_values = { 'id': info_dict.id, 'feed': classified_results, 'picture': info_dict.picture, 'likes': info_dict.likes, 'name': info_dict.name, 'category': info_dict.category, } path = os.path.join(os.path.dirname(__file__), 'templates/analyze.html') self.response.out.write(template.render(path, template_values))
def twitgraph(request): bayesname='bayesdata' srch = 'happy' tag = 'n' c = BayesianClassifier() if not memcache.get('bayesdata'): c.save()#laod form local file system c.load()#load picke from memecache '''q=request.get_all("q")''' if(request.GET.has_key('q')): srch = request.GET['q'] tag = c.classify(srch) html = "<html><body>sentiment is %s </body></html>" % tag #return HttpResponse(html) gv = globvars context = { 'thispage':'Sentiment', 'the_tweet':srch, 'sentmnt':tag } context = dict(context, **gv.context) return render_to_response('sentiment.html', context)