Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.64 KB

File metadata and controls

53 lines (38 loc) · 1.64 KB

Introduction

Open in Cloud Shell

This sample contains the code referenced in the Sentiment Analysis Tutorial within the Google Cloud Natural Language API Documentation. A full walkthrough of this sample is located within the documentation.

This sample is a simple illustration of how to construct a sentiment analysis request and process a response using the API.

Prerequisites

Set up your Cloud Natural Language API project , which includes:

  • Enabling the Natural Language API
  • Setting up a service account
  • Ensuring you've properly set up your GOOGLE_APPLICATION_CREDENTIALS for proper authentication to the service.

Download the Code

$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
$ cd python-docs-samples/language/sentiment

Run the Code

Open a sample folder, create a virtualenv, install dependencies, and run the sample:

$ virtualenv env
$ source env/bin/activate
(env)$ pip install -r requirements.txt

Usage

This sample provides four sample movie reviews which you can provide to the sample on the command line. (You can also pass your own text files.)

(env)$ python sentiment_analysis.py textfile.txt
Sentiment: score of -0.1 with magnitude of 6.7