Skip to content

Commit 9360f13

Browse files
Introduce Natural Language API (googleapis#1440)
* language: implement API
1 parent 60f2126 commit 9360f13

File tree

15 files changed

+3028
-9
lines changed

15 files changed

+3028
-9
lines changed

README.md

+92-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This client supports the following Google Cloud Platform services:
2121
* [Google Prediction API](#google-prediction-api)
2222
* [Google Translate API](#google-translate-api)
2323
* [Google Cloud Logging](#google-cloud-logging-beta) (Beta)
24+
* [Google Cloud Natural Language](#google-cloud-natural-language-beta) (Beta)
2425
* [Google Cloud Resource Manager](#google-cloud-resource-manager-beta) (Beta)
2526
* [Google Cloud Speech](#google-cloud-speech-limited-preview) (Limited Preview)
2627
* [Google Cloud Vision](#google-cloud-vision-beta) (Beta)
@@ -773,6 +774,90 @@ loggingClient.getEntries(function(err, entries) {
773774
```
774775

775776

777+
## Google Cloud Natural Language (Beta)
778+
779+
> **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.
780+
781+
- [API Documentation][gcloud-language-docs]
782+
- [Official Documentation][cloud-language-docs]
783+
784+
#### Using the all-in-one module
785+
786+
```
787+
$ npm install --save google-cloud
788+
```
789+
790+
```js
791+
var gcloud = require('google-cloud');
792+
var language = gcloud.language;
793+
```
794+
795+
#### Using the Natural Language API module
796+
797+
```
798+
$ npm install --save @google-cloud/language
799+
```
800+
801+
```js
802+
var language = require('@google-cloud/language');
803+
```
804+
805+
#### Preview
806+
807+
```js
808+
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
809+
// global basis (see Authorization section above).
810+
811+
var languageClient = language({
812+
projectId: 'grape-spaceship-123',
813+
keyFilename: '/path/to/keyfile.json'
814+
});
815+
816+
// Get the entities from a sentence.
817+
languageClient.detectEntities('Stephen of Michigan!', function(err, entities) {
818+
// entities = {
819+
// people: ['Stephen'],
820+
// places: ['Michigan']
821+
// }
822+
});
823+
824+
// Create a document if you plan to run multiple detections.
825+
var document = languageClient.document('Contributions welcome!');
826+
827+
// Analyze the sentiment of the document.
828+
document.detectSentiment(function(err, sentiment) {
829+
// sentiment = 100 // Large numbers represent more positive sentiments.
830+
});
831+
832+
// Parse the syntax of the document.
833+
document.annotate(function(err, annotations) {
834+
// annotations = {
835+
// language: 'en',
836+
// sentiment: 100,
837+
// entities: {},
838+
// sentences: ['Contributions welcome!'],
839+
// tokens: [
840+
// {
841+
// text: 'Contributions',
842+
// partOfSpeech: 'Noun (common and proper)',
843+
// partOfSpeechTag: 'NOUN'
844+
// },
845+
// {
846+
// text: 'welcome',
847+
// partOfSpeech: 'Verb (all tenses and modes)',
848+
// partOfSpeechTag: 'VERB'
849+
// },
850+
// {
851+
// text: '!',
852+
// partOfSpeech: 'Punctuation',
853+
// partOfSpeechTag: 'PUNCT'
854+
// }
855+
// ]
856+
// }
857+
});
858+
```
859+
860+
776861
## Google Cloud Resource Manager (Beta)
777862

778863
> **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.
@@ -804,8 +889,8 @@ var resource = require('@google-cloud/resource');
804889
#### Preview
805890

806891
```js
807-
// Authorizing on a per-API-basis. You don't need to do this if you auth on a
808-
// global basis (see Authorization section above).
892+
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
893+
// global basis (see Authentication section above).
809894

810895
var resourceClient = resource({
811896
projectId: 'grape-spaceship-123',
@@ -916,8 +1001,8 @@ var vision = require('@google-cloud/vision');
9161001
#### Preview
9171002

9181003
```js
919-
// Authorizing on a per-API-basis. You don't need to do this if you auth on a
920-
// global basis (see Authorization section above).
1004+
// Authenticating on a per-API-basis. You don't need to do this if you auth on a
1005+
// global basis (see Authentication section above).
9211006

9221007
var visionClient = vision({
9231008
projectId: 'grape-spaceship-123',
@@ -1033,6 +1118,7 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
10331118
[gcloud-compute-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/compute
10341119
[gcloud-datastore-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/datastore
10351120
[gcloud-dns-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/dns
1121+
[gcloud-language-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/language
10361122
[gcloud-logging-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/logging
10371123
[gcloud-prediction-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/prediction
10381124
[gcloud-pubsub-docs]: https://googlecloudplatform.github.io/gcloud-node/#/docs/pubsub
@@ -1070,6 +1156,8 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
10701156

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

1159+
[cloud-language-docs]: https://cloud.google.com/natural-language/docs
1160+
10731161
[cloud-logging-docs]: https://cloud.google.com/logging/docs
10741162

10751163
[cloud-prediction-docs]: https://cloud.google.com/prediction/docs

docs/json/master/language/.gitkeep

Whitespace-only changes.

docs/toc.json

+8
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@
137137
"title": "Transaction",
138138
"type": "datastore/transaction"
139139
}]
140+
}, {
141+
}, {
142+
"title": "Language",
143+
"type": "language",
144+
"nav": [{
145+
"title": "Document",
146+
"type": "language/document"
147+
}]
140148
}, {
141149
"title": "Logging",
142150
"type": "logging",

packages/common/src/service-object.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var util = require('./util.js');
5050
* @param {object} config - Configuration object.
5151
* @param {string} config.baseUrl - The base URL to make API requests to.
5252
* @param {string} config.createMethod - The method which creates this object.
53-
* @param {string} config.id - The identifier of the object. For example, the
53+
* @param {string=} config.id - The identifier of the object. For example, the
5454
* name of a Storage bucket or Pub/Sub topic.
5555
* @param {object=} config.methods - A map of each method name that should be
5656
* inherited.
@@ -308,7 +308,7 @@ ServiceObject.prototype.request = function(reqOpts, callback) {
308308

309309
var uriComponents = [
310310
this.baseUrl,
311-
this.id,
311+
this.id || '',
312312
reqOpts.uri
313313
];
314314

packages/common/test/service-object.js

+16
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,22 @@ describe('ServiceObject', function() {
606606
serviceObject.request(reqOpts, done);
607607
});
608608

609+
it('should not require a service object ID', function(done) {
610+
var expectedUri = [
611+
serviceObject.baseUrl,
612+
reqOpts.uri
613+
].join('/');
614+
615+
serviceObject.parent.request = function(reqOpts) {
616+
assert.strictEqual(reqOpts.uri, expectedUri);
617+
done();
618+
};
619+
620+
delete serviceObject.id;
621+
622+
serviceObject.request(reqOpts, assert.ifError);
623+
});
624+
609625
it('should support absolute uris', function(done) {
610626
var expectedUri = 'http://www.google.com';
611627

packages/google-cloud/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,20 @@
9393
"vision"
9494
],
9595
"dependencies": {
96+
"extend": "^3.0.0",
9697
"@google-cloud/bigquery": "0.1.0",
9798
"@google-cloud/bigtable": "0.1.0",
9899
"@google-cloud/compute": "0.1.0",
99100
"@google-cloud/datastore": "0.1.0",
100101
"@google-cloud/dns": "0.1.0",
101-
"@google-cloud/prediction": "0.1.0",
102+
"@google-cloud/language": "0.1.0",
102103
"@google-cloud/logging": "0.1.0",
104+
"@google-cloud/prediction": "0.1.0",
103105
"@google-cloud/pubsub": "0.1.0",
104106
"@google-cloud/resource": "0.1.0",
105107
"@google-cloud/storage": "0.1.0",
106108
"@google-cloud/translate": "0.1.0",
107-
"@google-cloud/vision": "0.1.0",
108-
"extend": "^3.0.0"
109+
"@google-cloud/vision": "0.1.0"
109110
},
110111
"devDependencies": {
111112
"proxyquire": "^1.7.10"

packages/google-cloud/src/index.js

+24
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,30 @@ var apis = {
127127
*/
128128
dns: require('@google-cloud/dns'),
129129

130+
/**
131+
* The [Google Cloud Natural Language](https://cloud.google.com/natural-language/docs)
132+
* API provides natural language understanding technologies to developers,
133+
* including sentiment analysis, entity recognition, and syntax analysis.
134+
*
135+
* <p class="notice">
136+
* **This is a Beta release of Google Cloud Natural Language.** This API is
137+
* not covered by any SLA or deprecation policy and may be subject to
138+
* backward-incompatible changes.
139+
* </p>
140+
*
141+
* @type {module:language}
142+
*
143+
* @return {module:language}
144+
*
145+
* @example
146+
* var gcloud = require('google-cloud');
147+
* var language = gcloud.language({
148+
* projectId: 'grape-spaceship-123',
149+
* keyFilename: '/path/to/keyfile.json'
150+
* });
151+
*/
152+
language: require('@google-cloud/language'),
153+
130154
/**
131155
* [Google Cloud Logging](https://cloud.google.com/logging/docs) collects and
132156
* stores logs from applications and services on the Google Cloud Platform:

packages/google-cloud/test/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var FakeBigtable = createFakeApi();
3737
var FakeCompute = createFakeApi();
3838
var FakeDatastore = createFakeApi();
3939
var FakeDNS = createFakeApi();
40+
var FakeLanguage = createFakeApi();
4041
var FakeLogging = createFakeApi();
4142
var FakePrediction = createFakeApi();
4243
var FakePubSub = createFakeApi();
@@ -56,6 +57,7 @@ describe('gcloud', function() {
5657
'@google-cloud/compute': FakeCompute,
5758
'@google-cloud/datastore': FakeDatastore,
5859
'@google-cloud/dns': FakeDNS,
60+
'@google-cloud/language': FakeLanguage,
5961
'@google-cloud/logging': FakeLogging,
6062
'@google-cloud/prediction': FakePrediction,
6163
'@google-cloud/pubsub': FakePubSub,
@@ -91,6 +93,10 @@ describe('gcloud', function() {
9193
assert.strictEqual(gcloud.dns, FakeDNS);
9294
});
9395

96+
it('should export static language', function() {
97+
assert.strictEqual(gcloud.language, FakeLanguage);
98+
});
99+
94100
it('should export static logging', function() {
95101
assert.strictEqual(gcloud.logging, FakeLogging);
96102
});
@@ -199,6 +205,15 @@ describe('gcloud', function() {
199205
});
200206
});
201207

208+
describe('language', function() {
209+
it('should create a new Language', function() {
210+
var language = localGcloud.language(options);
211+
212+
assert(language instanceof FakeLanguage);
213+
assert.strictEqual(language.calledWith_[0], options);
214+
});
215+
});
216+
202217
describe('logging', function() {
203218
it('should create a new Logging', function() {
204219
var logging = localGcloud.logging(options);

packages/language/package.json

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "@google-cloud/language",
3+
"version": "0.1.0",
4+
"author": "Google Inc.",
5+
"description": "Google Cloud Natural Language Client Library for Node.js",
6+
"contributors": [
7+
{
8+
"name": "Burcu Dogan",
9+
"email": "[email protected]"
10+
},
11+
{
12+
"name": "Johan Euphrosine",
13+
"email": "[email protected]"
14+
},
15+
{
16+
"name": "Patrick Costello",
17+
"email": "[email protected]"
18+
},
19+
{
20+
"name": "Ryan Seys",
21+
"email": "[email protected]"
22+
},
23+
{
24+
"name": "Silvano Luciani",
25+
"email": "[email protected]"
26+
},
27+
{
28+
"name": "Stephen Sawchuk",
29+
"email": "[email protected]"
30+
}
31+
],
32+
"main": "./src/index.js",
33+
"files": [
34+
"./src/*",
35+
"AUTHORS",
36+
"CONTRIBUTORS",
37+
"COPYING"
38+
],
39+
"repository": "googlecloudplatform/gcloud-node",
40+
"keywords": [
41+
"google apis client",
42+
"google api client",
43+
"google apis",
44+
"google api",
45+
"google",
46+
"google cloud platform",
47+
"google cloud",
48+
"cloud",
49+
"google cloud natural language",
50+
"google cloud language",
51+
"natural language",
52+
"language"
53+
],
54+
"dependencies": {
55+
"@google-cloud/common": "^0.1.0",
56+
"@google-cloud/storage": "^0.1.0",
57+
"arrify": "^1.0.1",
58+
"extend": "^3.0.0",
59+
"google-proto-files": "^0.4.0",
60+
"is": "^3.0.1",
61+
"propprop": "^0.3.1",
62+
"string-format-obj": "^1.0.0"
63+
},
64+
"devDependencies": {
65+
"mocha": "^2.1.0",
66+
"proxyquire": "^1.7.10"
67+
},
68+
"scripts": {
69+
"publish": "../../scripts/publish.sh",
70+
"test": "mocha test/*.js",
71+
"system-test": "mocha system-test/*.js --no-timeouts --bail"
72+
},
73+
"license": "Apache-2.0",
74+
"engines": {
75+
"node": ">=0.12.0"
76+
}
77+
}

0 commit comments

Comments
 (0)