analyze

command
v0.0.0-...-847fd54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

README

Google Cloud Natural Language API Go example

Authentication

  • Follow the instructions to set up your project and enable the Cloud Natural Language API.

  • From the Cloud Console, create a service account, download its json credentials file, then set the GOOGLE_APPLICATION_CREDENTIALS environment variable:

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

Run the sample

go run analyze.go <command> <text>

Where command is entities, sentiment, or syntax.

For example:

go run analyze.go entities "Renee French designed the Go gopher."

Prints something like this:

{
    "entities": [
        {
            "mentions": [
                {
                    "text": {
                        "content": "Renee French"
                    }
                }
            ],
            "name": "Renee French",
            "salience": 0.51491237,
            "type": "PERSON"
        },
        {
            "mentions": [
                {
                    "text": {
                        "beginOffset": 26,
                        "content": "Go"
                    }
                }
            ],
            "metadata": {
                "wikipedia_url": "http://en.wikipedia.org/wiki/Go_(programming_language)"
            },
            "name": "Go",
            "salience": 0.31268582,
            "type": "OTHER"
        }
    ],
    "language": "en"
}

Documentation

Overview

Command analyze performs sentiment, entity, and syntax analysis on a string of text via the Cloud Natural Language API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL