diff --git a/packages/google-cloud-language/samples/README.md b/packages/google-cloud-language/samples/README.md new file mode 100644 index 00000000000..2d7fe494e1f --- /dev/null +++ b/packages/google-cloud-language/samples/README.md @@ -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 +``` + +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" +} +``` diff --git a/packages/google-cloud-language/samples/package.json b/packages/google-cloud-language/samples/package.json new file mode 100644 index 00000000000..f1fe11ce5f2 --- /dev/null +++ b/packages/google-cloud-language/samples/package.json @@ -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" +}