Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language Partial Veneer #2422

Merged
merged 8 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 12 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,107 +425,18 @@ var languageClient = language({
keyFilename: '/path/to/keyfile.json'
});

// Get the entities from a sentence.
languageClient.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 = languageClient.document('Contributions welcome!');

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

// 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'
// },
// // ...
// ]
// }
var content = 'Hello, world!';
var type = language.v1.types.Document.Type.PLAIN_TEXT;
var document = {
content : content,
type : type
};
languageClient.analyzeSentiment({document: document}).then(function(responses) {
var response = responses[0];
// doThingsWith(response)
})
.catch(function(err) {
console.error(err);
});
```

Expand Down
210 changes: 39 additions & 171 deletions packages/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
Loading