Save lives with Watson Natural Language Understanding and Node-RED

Introduction

The Watson™ Natural Language Understanding service takes either a body of text or a publicly accessible website that the service can analyze. In this tutorial, we will analyze a news article that is accessible through a URL. You can also choose to analyze other URLs that contain a body of text.

Learning objectives

After completing this tutorial, you will be able to:

  • Instantiate a Node-RED Starter Kit and a Watson Cloud service (Natural Language Understanding API) on IBM Cloud
  • Bind a Watson service to a Node-RED application
  • Send a news article URL to the NLU API, and retrieve a table of the response in a table containing the concepts, entities, keywords, categories, sentiment, emotion, relations, and semantic roles

Prerequisites

  1. Create an IBM Cloud account.
  2. Log in to IBM Cloud.

Estimated time

Completing this tutorial should take 45-60 minutes.

Hands-on lab

Step 1. Set up your Node-RED starter kit

Log in and click Catalog in the upper right navigation bar.

flow

Click Starter Kits in the left menu, then click the Node-RED Starter option for the starter kit. The Starter Kit comes with:

  • A Cloudant database instance to store your flow configuration
  • A collection of nodes that make it easy to access various IBM Cloud services, including Watson, IoT, and blockchain services to name just a few

Write a name for your Node-RED Starter Kit. You can include “node red” somewhere in the title, so you will not confuse with your other future IBM Cloud applications.

flow

It will take a few minutes (5–15 minutes) to instantiate. After it is finished instantiating, you will see the green circle beside the name of your app where it will state “running.” Click Visit App URL to get to your new Node-RED starter kit.

flow

You will be taken to your new Node-RED app with a few setup instructions. You can choose to add a user name or password, or leave unsecured. It is up to you.

flow

A few other options are available; keep clicking Next until you get to this final page. Click Go to your Node-RED flow editor.

flow

You will see your first flow. You are ready to begin your first Node-RED flow. Congrats!

flow

Step 2. Add Natural Language Understanding in IBM Cloud

Click the Catalog link in the upper right of the IBM Cloud dashboard. Under the AI section, click the Natural Language Understanding tile.

flow

You can optionally give the service a custom name or leave it as the one given. Click Create.

Click Connections in the menu on the left.

Click Create connection on the right.

Click Connect next to the Node-RED application you created earlier.

flow

IBM Cloud will prompt to restage the application. Click Restage, and the application will restart and include the new service credentials in the environment.

flow

When the application has finished restaging, open the Node-RED Flow Editor. If you already have Node-RED open, refresh the page.

Step 3. Analyze a news article in Node-RED

The Watson Natural Language Understanding service takes either a body of text or a publicly accessible URL to provide content the service can analyze. In this section, we will analyze a news article that is accessible through a URL. You can also choose to analyze other URLs that contain a body of text.

flow

flow

flow

flow

flow

Get the code snippet.

flow

Open a browser tab and visit your application’s endpoint, passing in the URL to the content: http://<<MY-APP>>.mybluemix.net/analyze?url=<<URL-TO-STORY>>.

  • Replace <> with the host of the Node-RED application you chose to name your app.
  • Replace <> with the URL of the content.

Depending on the content at the URL, you might see a list of attributes, including concepts, entities, keywords, categories, sentiment, emotion, relations, semantic roles, and more mentioned within the text.

flow

To see the JSON representation of the content, insert format=json in the URL query string.

flow

Finally, return to Step 3 and experiment by disabling some of the features to see how the results change. Try analyzing other URLs and see what results are returned.

Summary

This tutorial explained how to analyze a news article that is accessible through a URL. In the tutorial, you learned how to instantiate a Node-RED Starter Kit and a Watson Cloud service on IBM Cloud, bind a Watson service to a Node-RED application, and send a news article URL to the Natural Language Understanding API. Take a look at all of the Watson services and learn how you can use them in your app.

Anamita Guha
John Walicki
Dan Krook