Skip to content

Commit

Permalink
Add Cloud Natural Language API sample. (#155)
Browse files Browse the repository at this point in the history
* Add Cloud Natural Language API sample.

This sample makes a request to analyze the entities in text.

Change-Id: I387cff7ac70c6f3c00a5b213527b4bd71c6c44dc

* Update package.json

* Do it right this time
  • Loading branch information
jerjou authored and jmdobry committed Jul 20, 2016
0 parents commit 00ca22a
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
79 changes: 79 additions & 0 deletions packages/google-cloud-language/samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Cloud Natural Language API Sample

These samples demonstrate the use of the
[Google Cloud Natural Language API](https://cloud.google.com/natural-language/docs/).

`analyze.js` is a command-line program that demonstrates how different methods
of the API can be called.

## Setup

Please follow the [Set Up Your Project](https://cloud-dot-devsite.googleplex.com/natural-language/docs/getting-started#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](https://cloud.google.com/natural-language/docs/common/auth#set_up_a_service_account),
and export the following environment variable:

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

## Run locally

First install the needed dependencies.

```
npm install
```

To run:

```
node analyze.js <sentiment|entities|syntax> <text>
```

For example, the following command returns all entities found in the text:

```
node analyze.js entities "President Obama is speaking at the White House."
```

```
{
"entities": [
{
"name": "Obama",
"type": "PERSON",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Barack_Obama"
},
"salience": 0.84503114,
"mentions": [
{
"text": {
"content": "Obama",
"beginOffset": 10
}
}
]
},
{
"name": "White House",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/White_House"
},
"salience": 0.15496887,
"mentions": [
{
"text": {
"content": "White House",
"beginOffset": 35
}
}
]
}
],
"language": "en"
}
```
18 changes: 18 additions & 0 deletions packages/google-cloud-language/samples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "cloud-natural-language-api-samples",
"version": "1.0.0",
"description": "Samples for using the Google Cloud Natural Language API.",
"repository": {
"type": "git",
"url": "git://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"main": "analyze.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"googleapis": "^11.0.0"
},
"author": "Google, Inc.",
"license": "Apache-2.0"
}

0 comments on commit 00ca22a

Please sign in to comment.