Reader small image

You're reading from  Google Cloud AI Services Quick Start Guide

Product typeBook
Published inMay 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788626613
Edition1st Edition
Languages
Right arrow
Author (1)
Arvind Ravulavaru
Arvind Ravulavaru
author image
Arvind Ravulavaru

Arvind Ravulavaru is a platform architect at Ubiconn IoT Solutions, with over 9 years of experience in software development and 2 years in hardware & product development. For the last 5 years, he has been working extensively on JavaScript, both on the server side and the client side. And for the last couple of years in IoT, building a platform for rapidly developing IoT solutions, named The IoT Suitcase. Prior to that, Arvind worked on big data, cloud computing, and orchestration.
Read more about Arvind Ravulavaru

Right arrow

Cloud Natural Language

In the last chapter, we learned how to work with Cloud Speech API, and saw how we can integrate the Cloud Speech API with SmartExchange to convert speech to text. In this chapter, we are going to work with the Cloud Natural Language API. We are going to let the users reply to a thread using a text message, a function we already have now. Before we save that message to the database, we will send that text for sentiment analysis, entity analysis, syntax analysis, and entity sentiment analysis, and classify the content. This will help us understand the mood and type of content. In this chapter, we are only going to display the response from the Cloud Natural Language API and not act on the results.

The topics covered are:

  • What is the Cloud Natural Language API?
  • Exploring the Cloud Natural Language API
  • Integrating the Cloud Natural Language API with SmartExchange...

Cloud Natural Language API

The Google Cloud Speech API is one of the machine learning services exposed under the Cloud AI vertical. This service is used to detect the structure and meaning of a text using machine learning.

This service does the following things:

  • Helps us extract insights from the text; the text can be an email, a tweet, or a support request
  • Supports content analysis for various languages
  • Classifies the text and can provide a relation graph between texts
  • Uses Google's deep learning models to predict as well as continuously improve the accuracy of the predictions

Some of the key features are as follows:

  • Syntax analysis
  • Entity recognition
  • Sentiment analysis
  • Content classification
  • Multi-language support

This service can be used in combination with another service, such as the Cloud Speech API, where an audio file can be uploaded to the Speech API and the...

Enabling the API

Now that we have a project and we have both the API and service account keys, we will enable the required API and test our application. Navigate to the project home page (https://console.cloud.google.com/home/dashboard?project=smart-exchange-b10882). From the menu on the left-hand side, select APIs & Services | Library. Once we land on this page, search for Cloud Natural Language API and click on that card. Then, click on the Enable button. This will prompt you to set up billing, if you have not already done so. Once you have enabled the billing and the API, you should see that the Cloud Natural Language API is enabled:

In the next section, we are going to explore the API.

Exploring the Cloud Natural Language API

Please refer to the Setting up the Rest Client section of Chapter 3, Cloud Vision API, to set up a REST API client, either Postman or cURL, before you continue. Now that we have all the required setup done, let's get started with exploring the API. In this section, we are going to explore two APIs of the Cloud Natural Language API:

  • Sentiment analysis
  • Entity analysis

There are three more APIs that are offered as part of the Cloud Natural Language API, which are as follows:

  • Syntax analysis
  • Entity sentiment analysis
  • Classifying content

While integrating with SmartExchange, we are going to make a request including all five features. But while working with Postman, we will be working with only two of them. We will start with sentiment analysis.

...

Integrating the Natural Language API with SmartExchange

Now that we have seen what can be done using the Natural Language API, let's actually integrate this into SmartExchange. We will allow the users to post a text response to a thread. Before we save this in the database, we will send the text for content analysis to the Natural Language API and get the analysis results. We are going to save the text as well as the analysis in our message collection and display the results to the user. The final output of the text analysis will appear as shown in the following screenshot:

So, let's get started with the implementation.

Solution design

To achieve the preceding result, we are going to do the following:

  1. On the view...

Deploying to Heroku

This step is optional and you can do it if you are interested in deploying this app to Heroku. To continue with this section, you need to have set up a Heroku account and installed the Heroku Toolbelt. Once that is done, open a new Command Prompt or Terminal inside the smart-exchange-base folder. Run the following:

$ heroku login

This will prompt you for the Heroku credentials that you have signed up with. Next, let's get our application ready for deployment. Run the following:

$ npm run build

Alternatively, run this:

$ yarn build

Either of these will run the required scripts to build the final dist folder, which will be deployed to Heroku. Once the build is completed, run the following:

$ git add -A
$ git commit -am "Cloud Natural language API Integration Commit"

Let's, push the code to Heroku. Run the following:

$ git push heroku master...

Summary

In this chapter, we have gone through the Google Natural Language API and we have worked with the annotateText API. We also set up the code that is required for integrating this API with the SmartExchange app. In the next chapter, we are going to work with the Cloud Translation API.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Google Cloud AI Services Quick Start Guide
Published in: May 2018Publisher: PacktISBN-13: 9781788626613
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Arvind Ravulavaru

Arvind Ravulavaru is a platform architect at Ubiconn IoT Solutions, with over 9 years of experience in software development and 2 years in hardware & product development. For the last 5 years, he has been working extensively on JavaScript, both on the server side and the client side. And for the last couple of years in IoT, building a platform for rapidly developing IoT solutions, named The IoT Suitcase. Prior to that, Arvind worked on big data, cloud computing, and orchestration.
Read more about Arvind Ravulavaru