Skip to content

Commit

Permalink
language: implement API
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Aug 4, 2016
1 parent 806dec3 commit a59a816
Show file tree
Hide file tree
Showing 14 changed files with 3,045 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"before": true,
"after": true,
"beforeEach": true,
"afterEach": true
"afterEach": true,
"exec": true
}
}
114 changes: 102 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This client supports the following Google Cloud Platform services:
* [Google Prediction API](#google-prediction-api)
* [Google Translate API](#google-translate-api)
* [Google Cloud Logging](#google-cloud-logging-beta) (Beta)
* [Google Cloud Natural Language](#google-cloud-natural-language-beta) (Beta)
* [Google Cloud Resource Manager](#google-cloud-resource-manager-beta) (Beta)
* [Google Cloud Vision](#google-cloud-vision-beta) (Beta)

Expand Down Expand Up @@ -142,7 +143,7 @@ var bigquery = require('@google-cloud/bigquery');
// global basis (see Authentication section above).

var bigqueryClient = bigquery({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -199,7 +200,7 @@ var bigtable = require('@google-cloud/bigtable');
// global basis (see Authentication section above).

var bigtableClient = bigtable({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json',
zone: 'my-zone',
cluster: 'my-cluster'
Expand Down Expand Up @@ -271,7 +272,7 @@ var datastore = require('@google-cloud/datastore');
// global basis (see Authentication section above).

var datastoreClient = datastore({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -343,7 +344,7 @@ var dns = require('@google-cloud/dns');
// global basis (see Authentication section above).

var dnsClient = dns({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -402,7 +403,7 @@ var pubsub = require('@google-cloud/pubsub');
// auth on a global basis (see Authentication section above).

var pubsubClient = pubsub({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -467,7 +468,7 @@ var fs = require('fs');
// global basis (see Authentication section above).

var gcs = storage({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -537,7 +538,7 @@ var compute = require('@google-cloud/compute');
// global basis (see Authentication section above).

var gce = compute({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -590,7 +591,7 @@ var prediction = require('@google-cloud/prediction');
// global basis (see Authentication section above).

var predictionClient = prediction({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -731,7 +732,7 @@ var logging = require('@google-cloud/logging');
// basis (see Authentication section above).

var loggingClient = logging({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -768,6 +769,92 @@ loggingClient.getEntries(function(err, entries) {
```


## Google Cloud Natural Language (Beta)

> **This is a Beta release of Google Cloud Natural Language.** This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
- [API Documentation][gcloud-language-docs]
- [Official Documentation][cloud-language-docs]

#### Using the all-in-one module

```
$ npm install --save google-cloud
```

```js
var gcloud = require('google-cloud');
var language = gcloud.language;
```

#### Using the Natural Language API module

```
$ npm install --save @google-cloud/language
```

```js
var language = require('@google-cloud/language');
```

#### Preview

```js
var gcloud = require('google-cloud');

// Authorizing on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authorization section above).

var languageClient = language({
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

// Get the entities from a sentence.
languageClient.detectEntities('Stephen of Michigan!', function(err, entities) {
// entities = {
// people: ['Stephen'],
// places: ['Michigan']
// }
});

// 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, positiveSentiment) {
// positiveSentiment = true
});

// Parse the syntax of the document.
document.annotate(function(err, annotations) {
// annotations = {
// language: 'en',
// sentiment: true,
// entities: {},
// sentences: ['Contributions welcome!'],
// tokens: [
// {
// text: 'Contributions',
// partOfSpeech: 'Noun (common and proper)',
// partOfSpeechTag: 'NOUN'
// },
// {
// text: 'welcome',
// partOfSpeech: 'Verb (all tenses and modes)',
// partOfSpeechTag: 'VERB'
// },
// {
// text: '!',
// partOfSpeech: 'Punctuation',
// partOfSpeechTag: 'PUNCT'
// }
// ]
// }
});
```


## Google Cloud Resource Manager (Beta)

> **This is a Beta release of Google Cloud Resource Manager.** This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.
Expand Down Expand Up @@ -803,7 +890,7 @@ var resource = require('@google-cloud/resource');
// global basis (see Authorization section above).

var resourceClient = resource({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand All @@ -814,7 +901,7 @@ resourceClient.getProjects(function(err, projects) {
}
});

// Get the metadata from your project. (defaults to `my-project`)
// Get the metadata from your project. (defaults to `grape-spaceship-123`)
var project = resourceClient.project();

project.getMetadata(function(err, metadata) {
Expand Down Expand Up @@ -858,7 +945,7 @@ var vision = require('@google-cloud/vision');
// global basis (see Authorization section above).

var visionClient = vision({
projectId: 'my-project',
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});

Expand Down Expand Up @@ -971,6 +1058,7 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
[gcloud-compute-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/compute
[gcloud-datastore-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/datastore
[gcloud-dns-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/dns
[gcloud-language-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/language
[gcloud-logging-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/logging
[gcloud-prediction-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/prediction
[gcloud-pubsub-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/pubsub
Expand Down Expand Up @@ -1007,6 +1095,8 @@ Apache 2.0 - See [COPYING](COPYING) for more information.

[cloud-dns-docs]: https://cloud.google.com/dns/docs

[cloud-language-docs]: https://cloud.google.com/natural-language/docs

[cloud-logging-docs]: https://cloud.google.com/logging/docs

[cloud-prediction-docs]: https://cloud.google.com/prediction/docs
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions docs/toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
"title": "Transaction",
"type": "datastore/transaction"
}]
}, {
}, {
"title": "Language",
"type": "language",
"nav": [{
"title": "Document",
"type": "language/document"
}]
}, {
"title": "Logging",
"type": "logging",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/service-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ ServiceObject.prototype.request = function(reqOpts, callback) {

var uriComponents = [
this.baseUrl,
this.id,
this.id || '',
reqOpts.uri
];

Expand Down
54 changes: 39 additions & 15 deletions packages/google-cloud/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,28 @@ var apis = {
dns: require('@google-cloud/dns'),

/**
* The [Google Prediction API](https://cloud.google.com/prediction/docs/getting-started)
* provides pattern-matching and machine learning capabilities. Given a set of
* data examples to train against, you can create applications that can
* perform the following tasks:
* The [Google Cloud Natural Language](https://cloud.google.com/natural-language/docs)
* API provides natural language understanding technologies to developers,
* including sentiment analysis, entity recognition, and syntax analysis.
*
* - Given a user's past viewing habits, predict what other movies or
* products a user might like.
* - Categorize emails as spam or non-spam.
* - Analyze posted comments about your product to determine whether they
* have a positive or negative tone.
* - Guess how much a user might spend on a given day, given his spending
* history.
* <p class="notice">
* **This is a Beta release of Google Cloud Natural Language.** This API is
* not covered by any SLA or deprecation policy and may be subject to
* backward-incompatible changes.
* </p>
*
* @type {module:prediction}
* @type {module:language}
*
* @return {module:prediction}
* @return {module:language}
*
* @example
* var gcloud = require('google-cloud');
* var dns = gcloud.prediction({
* var language = gcloud.language({
* projectId: 'grape-spaceship-123',
* keyFilename: '/path/to/keyfile.json'
* });
*/
prediction: require('@google-cloud/prediction'),
language: require('@google-cloud/language'),

/**
* [Google Cloud Logging](https://cloud.google.com/logging/docs) collects and
Expand Down Expand Up @@ -182,6 +179,33 @@ var apis = {
*/
logging: require('@google-cloud/logging'),

/**
* The [Google Prediction API](https://cloud.google.com/prediction/docs/getting-started)
* provides pattern-matching and machine learning capabilities. Given a set of
* data examples to train against, you can create applications that can
* perform the following tasks:
*
* - Given a user's past viewing habits, predict what other movies or
* products a user might like.
* - Categorize emails as spam or non-spam.
* - Analyze posted comments about your product to determine whether they
* have a positive or negative tone.
* - Guess how much a user might spend on a given day, given his spending
* history.
*
* @type {module:prediction}
*
* @return {module:prediction}
*
* @example
* var gcloud = require('google-cloud');
* var prediction = gcloud.prediction({
* projectId: 'grape-spaceship-123',
* keyFilename: '/path/to/keyfile.json'
* });
*/
prediction: require('@google-cloud/prediction'),

/**
* [Google Cloud Pub/Sub](https://developers.google.com/pubsub/overview) is a
* reliable, many-to-many, asynchronous messaging service from Google Cloud
Expand Down
Loading

0 comments on commit a59a816

Please sign in to comment.