Wednesday, May 31, 2017

A new post on SocializeMe:It's been a couple of months now since my last project on Node.js . The other day I wanted to set up an example of a dashboard with sentiment coming from Twitter around a keyword.

To keep things simple, I used IFTTT to export tweets to a CSV file. With that I could then use Watson's libraries to measure sentiment. To start, I created a new trial account on BlueMix. Once there, go to Services - Watson - Create Watson service. Once there pick Natural Language Understanding and it will create an instance of the service. This Watson service helps to make sense out of pretty much any text.

Let me walk through the code (which I'll put on Github soon). First, import and setup the libraries (you get the Watson credentials directly from Bluemix and my preference is to store them as environment variables):

Next, read the CSV, parse it, measure it and write a new CSV out all with this one line of code:

The function sentimentFromWatson is key above. That function takes advantage of the Watson library already available. Here's what that function looks like:

And that's it! In total, you have a quick sample in 20-30 lines of code to measure sentiment from Twitter. Below is the graphic that I created. In a span of a weekend, the keyword that I was monitoring had some positive tweets and others that were negative. Overall, that weekend was pretty neutral.

(Note: the free plan for Watson Natural Language Understanding gives you 1,000 calls / day. If you expect more than 1,000 tweets / day you'll need a paid plan).

Overall, this took me about 30 minutes to put together and a bit of troubleshooting. If you haven't played with Node.js and Watson yet, go for it!