GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-docs-samples/language/api at master · ortgit/python-docs-samples

Expand file tree

/

api

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

api

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
README.md
README.md
 
 
analyze.py
analyze.py
 
 
analyze_test.py
analyze_test.py
 
 
requirements.txt
requirements.txt
 
 

README.md

Outline

Google Cloud Natural Language API Sample

This Python sample demonstrates the use of the Google Cloud Natural Language API for sentiment, entity, and syntax analysis.

Setup

Please follow the Set Up Your Project steps in the Quickstart doc to create a project and enable the Cloud Natural Language API. Following those steps, make sure that you Set Up a Service Account, and export the following environment variable:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json

Run the sample

Install pip if not already installed.

To run the example, install the necessary libraries using pip:

$ pip install -r requirements.txt

Then, run the script:

$ python analyze.py <command> <text-string>

where <command> is one of: entities, sentiment, or syntax.

The script will write to STDOUT the json returned from the API for the requested feature.

For example, if you run:

$ python analyze.py entities "Tom Sawyer is a book written by a guy known as Mark Twain."

You will see something like the following returned:

{
  "entities": [
    {
      "salience": 0.49785897,
      "mentions": [
        {
          "text": {
            "content": "Tom Sawyer",
            "beginOffset": 0
          }
        }
      ],
      "type": "PERSON",
      "name": "Tom Sawyer",
      "metadata": {
        "wikipedia_url": "http://en.wikipedia.org/wiki/The_Adventures_of_Tom_Sawyer"
      }
    },
    {
      "salience": 0.12209519,
      "mentions": [
        {
          "text": {
            "content": "Mark Twain",
            "beginOffset": 47
          }
        }
      ],
      "type": "PERSON",
      "name": "Mark Twain",
      "metadata": {
        "wikipedia_url": "http://en.wikipedia.org/wiki/Mark_Twain"
      }
    }
  ],
  "language": "en"
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.