How-tos

Analyze tweets in under 30 minutes using Node-RED

Share this post:

I created a Node-RED app in Bluemix which searches for a specified keyword, username, or hashtag phrase in the public Twitter universe whenever a new tweet is posted. This application can be created in less then 30 minutes by anyone and requires no coding experience. When a tweet is posted that matches the provided search criteria, the tweet is passed through the sentiment analysis node which returns a sentiment value.

If that sentiment value has a value less than -5 (which is a very negative tweet) then the app sends me an email with the word “tweets/” and the username who wrote the tweet in the subject header and the actual tweet in the body. This allows me to catch any very negative tweets about the search terms within a couple of seconds.

Below is an example email alert:

Quick introduction to creating Node-RED applications

A Node-RED app is created by dragging and dropping nodes—pre-written pieces of code that perform desired actions—on the left hand side of the Node-RED editor into the middle work space. The nodes are then connected by clicking the output point of one node and dragging it to the input point of another node (the little grey squares on either side of a node):

Lastly and most importantly, each node has to be given the proper parameters by double clicking on it and filling in the form that pops up:

Once those steps are completed, you click the Deploy button on the top right corner of the editor and your application will be running. Simply stated, Node-RED applications are just programmable nodes that you wire together.

My Node-RED tweet sentiment app

As shown earlier, my entire Node-RED application consists of just five nodes. The first node will search Twitter for the desired keywords entered into the form after double clicking on the node. You will need to authenticate to your Twitter username, which will allow the application to search all public tweets. To specify the search keywords fill in the “for” parameter with a word, username, or hashtag keyword that you want to retrieve all tweets containing that term (I used #testnegative as my keyword for testing purposes).

Next I added the sentiment analysis node and connected its input to the output of the Twitter node. This node will analyze all tweets that match the search term and assign them a sentiment value (this node does not need any parameters unless you want to change the name of the node itself). Average sentiment values will range from -5 to 5 with -5 being a very negative tweet, 0 being a neutral tweet and 5 being a very positive tweet. Anything outside of those ranges are extreme values and the tweets I want to capture. I then added a debug node called “debug sentiment value” to print out the sentiment value to the Node-RED debug log on the right side of the editor (this node is not required but helps to see sentiment values).

Below are some example sentiment values based on the given tweet:

  • Sentiment value of 4: #testnegative Jim’s fries is awesome!
  • Sentiment value of -3: #testnegative Jim’s fries is the worst restaurant ever!
  • Sentiment value of -4: #testnegative Jim’s fries is the worst restaurant ever! I could not pay with a debit card!
  • Sentiment value of -5: #testnegative Jim’s fries is the worst restaurant ever! I could not pay with a debit card! No one should ever go here!
  • Sentiment value of -8: #testnegative Jim’s fries is the worst restaurant ever! I could not pay with a debit card! No one should ever go here! Horrible service!

The sentiment value is then passed to a “switch” node which looks for tweets with a sentiment value that is less than or equal to -5. In the diagram above, noted that I renamed my switch node to “Analyze how negative”. If the sentiment value falls into this category, then an email is sent from my Gmail account to my work email:

Conclusion

That is the entire application; as you can see, there is absolutely no coding necessary. The only requirements are to drag and drop nodes, fill them out, and connect them. This app idea can be transformed in many ways. The app can be used to find very positive tweets, the app can send specified tweets containing multiple keywords to a Slack chat, the Twilio node can be integrated to have tweets be sent to your cell phone as a text, and many more implementations to analyze any tweet by anyone within a couple of seconds of it being posted. To try out Node-RED on Bluemix, go to the Bluemix Node-RED Page after you have signed up for your free 30 day Bluemix trial.

Add Comment
3 Comments

Leave a Reply

Your email address will not be published.Required fields are marked *


John Walicki

The sentiment analysis node outputs an additional value: msg.sentiment.score

The switch function node should evaluate the msg.sentiment.score property to determine whether the tweet is positive/negative. The article is ambiguous about which property in the switch function it should query / evaluate.

Reply

John Walicki

Thanks to @knolleary for the msg.sentiment.score property hint in his Node-RED flow posted here:
Twitter Sentiment Analysis
http://flows.nodered.org/flow/2832e7986c794f55708f

Reply

Ryan Ing

Hey thanks I got this working

Two issues
1. John Walicki is right in that you need to configure the switch node. You can’t just drag and drop it

2. You need to enable ‘allow less secure apps’ on your gmail for NodeRed to connect to it

Reply
More How-tos Stories

Watson Visual Recognition, drones, and custom classifiers

Back in May, I authored “Bringing Drones to the Enterprise with Bluemix and OpenWhisk“, demonstrating a proof of concept application that brought together a cloud-connected drone with cognitive image tagging and facial recognition services by leveraging both Bluemix and OpenWhisk. Since the Watson Visual Recognition services have since been upgraded to general availability, I've updated the “smart”-drone app to take advantage of everything that the Watson Visual Recognition service has to offer.

Continue reading

Extend your toolchain by adding a tool integration

Are you getting the most out of your toolchain? You can extend its capabilities by adding tool integrations. You can select from several predefined tool integrations or add a custom tool integration.

Continue reading

Best of Bluemix: Machine translation, SSO for social networks, MongoDB

This weekly post showcases some of best new tutorials, videos, and other content published each week on developerWorks. The three featured articles include: Adding language translation to your apps with IBM Watson, enabling social network logins using the Bluemix Single Sign On service, and a two-part tutorial showing how you can leverage MongoDB to build powerful, scalable MongoDB-powered cloud applications.

Continue reading