Skip to content

Commit

Permalink
Language Partial Veneer (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
swcloud authored and stephenplusplus committed Jul 26, 2017
1 parent 2ccb300 commit 9fc73d8
Show file tree
Hide file tree
Showing 16 changed files with 3,924 additions and 3,056 deletions.
210 changes: 39 additions & 171 deletions packages/google-cloud-language/README.md
Original file line number Diff line number Diff line change
@@ -1,181 +1,49 @@
# @google-cloud/language ([Beta][versioning])
> Cloud Natural Language Client Library for Node.js
# Node.js Client for Google Cloud Natural Language API ([Beta](https://github.com/GoogleCloudPlatform/google-cloud-node#versioning))

*Looking for more Google APIs than just Natural Language? You might want to check out [`google-cloud`][google-cloud].*
[Google Cloud Natural Language API][Product Documentation]: Google Cloud Natural Language API provides natural language understanding technologies to developers. Examples include sentiment analysis, entity recognition, and text annotations.
- [Client Library Documentation][]
- [Product Documentation][]

- [API Documentation][gcloud-language-docs]
- [Official Documentation][cloud-language-docs]
## Quick Start
In order to use this library, you first need to go through the following steps:

1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
2. [Enable the Google Cloud Natural Language API.](https://console.cloud.google.com/apis/api/language)
3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/master/guides/authentication)

```sh
$ npm install --save @google-cloud/language
```
```js
var language = require('@google-cloud/language')({
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

// Get the entities from a sentence.
language.detectEntities('Stephen of Michigan!', function(err, entities) {
// entities = [
// {
// name: 'Stephen',
// type: 'PERSON',
// metadata: {
// mid: '/m/05d8y4q'
// },
// salience: 0.7309288382530212,
// mentions: [
// {
// text: {
// content: 'Stephen',
// beginOffset: -1
// },
// type: 'PROPER'
// }
// ]
// },
// // ...
// ]
});

// Create a document if you plan to run multiple detections.
var document = language.document('Contributions welcome!');

// Analyze the sentiment of the document.
document.detectSentiment(function(err, sentiment) {
// sentiment = {
// magnitude: 0.30000001192092896,
// score: 0.30000001192092896
// }
});

// Parse the syntax of the document.
document.annotate(function(err, annotation) {
// annotation = {
// language: 'en',
// sentiment: {
// magnitude: 0.30000001192092896,
// score: 0.30000001192092896
// },
// entities: [
// {
// name: 'Contributions',
// type: 'OTHER',
// metadata: {},
// salience: 1,
// mentions: [
// {
// text: {
// content: 'Contributions',
// beginOffset: -1
// },
// type: 'COMMON'
// }
// ]
// }
// ],
// sentences: [
// {
// text: {
// content: 'Contributions welcome!',
// beginOffset: -1
// },
// sentiment: {
// magnitude: 0.30000001192092896,
// score: 0.30000001192092896
// }
// }
// ],
// tokens: [
// {
// text: {
// content: 'Contributions',
// beginOffset: -1
// },
// partOfSpeech: {
// tag: 'NOUN',
// aspect: 'ASPECT_UNKNOWN',
// case: 'CASE_UNKNOWN',
// form: 'FORM_UNKNOWN',
// gender: 'GENDER_UNKNOWN',
// mood: 'MOOD_UNKNOWN',
// number: 'PLURAL',
// person: 'PERSON_UNKNOWN',
// proper: 'PROPER_UNKNOWN',
// reciprocity: 'RECIPROCITY_UNKNOWN',
// tense: 'TENSE_UNKNOWN',
// voice: 'VOICE_UNKNOWN'
// },
// dependencyEdge: {
// headTokenIndex: 1,
// label: 'NSUBJ'
// },
// lemma: 'contribution'
// },
// // ...
// ]
// }
});

// Promises are also supported by omitting callbacks.
document.annotate().then(function(data) {
var annotations = data[0];
});

// It's also possible to integrate with third-party Promise libraries.
var language = require('@google-cloud/language')({
promise: require('bluebird')
});
### Installation
```


## Authentication

It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Cloud services.

### On Google Cloud Platform

If you are running this client on Google Cloud Platform, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access.

``` js
var language = require('@google-cloud/language')();
// ...you're good to go!
$ npm install --save @google-cloud/language
```

### Elsewhere

If you are not running this client on Google Cloud Platform, you need a Google Developers service account. To create a service account:

1. Visit the [Google Developers Console][dev-console].
2. Create a new project or click on an existing project.
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services):
* Google Cloud Natural Language API
4. Navigate to **APIs & auth** > **Credentials** and then:
* If you want to use a new service account key, click on **Create credentials** and select **Service account key**. After the account key is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests.
* If you want to generate a new service account key for an existing service account, click on **Generate new JSON key** and download the JSON key file.

``` js
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'

var language = require('@google-cloud/language')({
projectId: projectId,

// The path to your key file:
keyFilename: '/path/to/keyfile.json'

// Or the contents of the key file:
credentials: require('./path/to/keyfile.json')
});

// ...you're good to go!
### Preview
#### LanguageServiceClient
```js
var language = require('@google-cloud/language');

var client = language({
// optional auth parameters.
});

var content = 'Hello, world!';
var type = language.v1.types.Document.Type.PLAIN_TEXT;
var document = {
content : content,
type : type
};
client.analyzeSentiment({document: document}).then(function(responses) {
var response = responses[0];
// doThingsWith(response)
})
.catch(function(err) {
console.error(err);
});
```

### Next Steps
- Read the [Client Library Documentation][] for Google Cloud Natural Language API to see other available methods on the client.
- Read the [Google Cloud Natural Language API Product documentation][Product Documentation] to learn more about the product and see How-to Guides.
- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/README.md) to see the full list of Cloud APIs that we cover.

[versioning]: https://github.com/GoogleCloudPlatform/google-cloud-node#versioning
[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node/
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
[dev-console]: https://console.developers.google.com/project
[gcloud-language-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/language
[cloud-language-docs]: https://cloud.google.com/natural-language/docs
[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/language
[Product Documentation]: https://cloud.google.com/language
33 changes: 12 additions & 21 deletions packages/google-cloud-language/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"repository": "GoogleCloudPlatform/google-cloud-node",
"name": "@google-cloud/language",
"version": "0.10.6",
"author": "Google Inc.",
"description": "Cloud Natural Language Client Library for Node.js",
"author": "Google Inc",
"description": "Google Cloud Natural Language API client for Node.js",
"contributors": [
{
"name": "Burcu Dogan",
Expand All @@ -29,14 +30,12 @@
"email": "sawchuk@gmail.com"
}
],
"main": "./src/index.js",
"main": "src/index.js",
"files": [
"src",
"AUTHORS",
"CONTRIBUTORS",
"COPYING"
],
"repository": "googlecloudplatform/google-cloud-node",
"keywords": [
"google apis client",
"google api client",
Expand All @@ -46,30 +45,22 @@
"google cloud platform",
"google cloud",
"cloud",
"google cloud natural language",
"google cloud language",
"natural language",
"language"
"google language",
"language",
"Google Cloud Natural Language API"
],
"dependencies": {
"@google-cloud/common": "^0.13.0",
"extend": "^3.0.0",
"google-gax": "^0.13.0",
"google-proto-files": "^0.12.0",
"is": "^3.0.1",
"string-format-obj": "^1.1.0"
"google-gax": "^0.13.2",
"extend": "^3.0.0"
},
"devDependencies": {
"@google-cloud/storage": "*",
"mocha": "^3.0.2",
"proxyquire": "^1.7.10",
"through2": "^2.0.1",
"uuid": "^3.0.1"
"mocha": "^3.2.0"
},
"scripts": {
"publish-module": "node ../../scripts/publish.js language",
"test": "mocha test/*.js",
"system-test": "mocha system-test/*.js --no-timeouts --bail"
"smoke-test": "mocha smoke-test/*.js --timeout 5000",
"test": "mocha test/*.js"
},
"license": "Apache-2.0",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2017, Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';

describe('LanguageServiceSmokeTest', function() {

it('successfully makes a call to the service', function(done) {
var language = require('../src');

var client = language.v1({
// optional auth parameters.
});

var content = 'Hello, world!';
var type = language.v1.types.Document.Type.PLAIN_TEXT;
var document = {
content : content,
type : type
};
client.analyzeSentiment({document: document}).then(function(responses) {
var response = responses[0];
console.log(response);
})
.then(done)
.catch(done);
});
});
Loading

0 comments on commit 9fc73d8

Please sign in to comment.