Skip to content

Instantly share code, notes, and snippets.

@ajb413
Created March 29, 2018 00:25
Show Gist options
  • Save ajb413/9336737d4a582c1bf430f3a53513c341 to your computer and use it in GitHub Desktop.
Save ajb413/9336737d4a582c1bf430f3a53513c341 to your computer and use it in GitHub Desktop.
Amazon Comprehend code snippet
this.sentimentAnalysis(plainText, message.timetoken)
.then(function(id, sentiment) {
var messageInfoSpan = $('span[data-identifier="' + id + '"]');
var messageDiv = $('div[data-identifier="' + id + '"]');
if (sentiment.Sentiment &&
sentiment.SentimentScore &&
sentiment.SentimentScore.Negative &&
sentiment.SentimentScore.Positive
) {
messageDiv.removeClass('neutral');
messageDiv.addClass(sentiment.Sentiment);
var neg = (sentiment.SentimentScore.Negative * 100).toFixed(2);
var pos = (sentiment.SentimentScore.Positive * 100).toFixed(2);
messageInfoSpan.text('+' + pos + '% -' + neg + '%');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment