Skip to content

Instantly share code, notes, and snippets.

Last active March 10, 2017 19:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
PubNub Sentiment Analysis with IBM Watson
<!doctype html>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href="//" />
<link rel="stylesheet" href="" />
<div class="container" ng-app="PubNubAngularApp" ng-controller="MyTextCtrl">
NOTE: make sure to update the PubNub keys below with your keys,
and ensure that the sentiment analysis BLOCK is configured properly!
<h3>MyText Sentiment Analysis</h3>
<input ng-model="toSend" />
<input type="button" ng-click="publish()" value="Send!" />
<br /><br />
<li ng-repeat="message in messages track by $index">
text: {{message.text}}
<br />
sentiment: <span ng-bind-html="to_trusted(emote(message.sentiment_type))"></span> (score: {{message.sentiment_score}})
angular.module('PubNubAngularApp', ["pubnub.angular.service"])
.controller('MyTextCtrl', function($rootScope, $scope, $sce, Pubnub) {
$scope.messages = [];
$scope.msgChannel = 'group-sentiment-analysis-channel';
if (!$rootScope.initialized) {
publishKey: 'YOUR_PUB_KEY',
subscribeKey: 'YOUR_SUB_KEY',
$rootScope.initialized = true;
var msgCallback = function(payload) {
$scope.$apply(function() {
$scope.publish = function() {
channel: $scope.msgChannel,
message: {text:$scope.toSend}
$scope.toSend = "";
$scope.emote = function(type) {
if (type === 'positive') {
return '<i class="fa fa-smile-o" aria-hidden="true"></i>';
} else if (type === 'negative') {
return '<i class="fa fa-frown-o" aria-hidden="true"></i>';
} else {
return '<i class="fa fa-meh-o" aria-hidden="true"></i>';
$scope.to_trusted = function(html_code) {
return $sce.trustAsHtml(html_code);
Pubnub.subscribe({ channels: [$scope.msgChannel] });
Pubnub.addListener({ message: msgCallback });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment