Skip to content

Commit c4c2039

Browse files
language: upgrade generated layer
1 parent fb13f28 commit c4c2039

4 files changed

Lines changed: 74 additions & 88 deletions

File tree

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@google-cloud/common": "^0.7.0",
5656
"arrify": "^1.0.1",
5757
"extend": "^3.0.0",
58-
"google-gax": "^0.7.0",
58+
"google-gax": "^0.8.0",
5959
"google-proto-files": "^0.8.3",
6060
"is": "^3.0.1",
6161
"propprop": "^0.3.1"

packages/language/src/document.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,11 @@ Document.prototype.annotate = function(options, callback) {
395395

396396
var verbose = options.verbose === true;
397397

398-
var doc = this.document;
399-
var encType = this.encodingType;
400-
401-
this.api.Language.annotateText(doc, features, encType, function(err, resp) {
398+
this.api.Language.annotateText({
399+
document: this.document,
400+
features: features,
401+
encodingType: this.encodingType
402+
}, function(err, resp) {
402403
if (err) {
403404
callback(err, null, resp);
404405
return;
@@ -547,10 +548,10 @@ Document.prototype.detectEntities = function(options, callback) {
547548

548549
var verbose = options.verbose === true;
549550

550-
var doc = this.document;
551-
var encType = this.encodingType;
552-
553-
this.api.Language.analyzeEntities(doc, encType, function(err, resp) {
551+
this.api.Language.analyzeEntities({
552+
document: this.document,
553+
encodingType: this.encodingType
554+
}, function(err, resp) {
554555
if (err) {
555556
callback(err, null, resp);
556557
return;
@@ -621,10 +622,10 @@ Document.prototype.detectSentiment = function(options, callback) {
621622

622623
var verbose = options.verbose === true;
623624

624-
var doc = this.document;
625-
var encType = this.encodingType;
626-
627-
this.api.Language.analyzeSentiment(doc, encType, function(err, resp) {
625+
this.api.Language.analyzeSentiment({
626+
document: this.document,
627+
encodingType: this.encodingType
628+
}, function(err, resp) {
628629
if (err) {
629630
callback(err, null, resp);
630631
return;

packages/language/src/v1beta1/language_service_api.js

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ function LanguageServiceApi(gaxGrpc, grpcClients, opts) {
109109
/**
110110
* Analyzes the sentiment of the provided text.
111111
*
112-
* @param {Object} document
112+
* @param {Object} request
113+
* The request object that will be sent.
114+
* @param {Object} request.document
113115
* Input document. Currently, `analyzeSentiment` only supports English text
114116
* ({@link Document.language}="EN").
115117
*
@@ -121,47 +123,41 @@ function LanguageServiceApi(gaxGrpc, grpcClients, opts) {
121123
* The function which will be called with the result of the API call.
122124
*
123125
* The second parameter to the callback is an object representing [AnalyzeSentimentResponse]{@link AnalyzeSentimentResponse}
124-
* @returns {gax.EventEmitter} - the event emitter to handle the call
125-
* status.
126+
* @returns {Promise} - The promise which resolves to the response object.
127+
* The promise has a method named "cancel" which cancels the ongoing API call.
126128
*
127129
* @example
128130
*
129131
* var api = languageV1beta1.languageServiceApi();
130132
* var document = {};
131-
* api.analyzeSentiment(document, function(err, response) {
132-
* if (err) {
133-
* console.error(err);
134-
* return;
135-
* }
133+
* api.analyzeSentiment({document: document}).then(function(response) {
136134
* // doThingsWith(response)
135+
* }).catch(function(err) {
136+
* console.error(err);
137137
* });
138138
*/
139-
LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment(
140-
document,
141-
options,
142-
callback) {
139+
LanguageServiceApi.prototype.analyzeSentiment = function(request, options, callback) {
143140
if (options instanceof Function && callback === undefined) {
144141
callback = options;
145142
options = {};
146143
}
147144
if (options === undefined) {
148145
options = {};
149146
}
150-
var req = {
151-
document: document
152-
};
153-
return this._analyzeSentiment(req, options, callback);
147+
return this._analyzeSentiment(request, options, callback);
154148
};
155149

156150
/**
157151
* Finds named entities (currently finds proper names) in the text,
158152
* entity types, salience, mentions for each entity, and other properties.
159153
*
160-
* @param {Object} document
154+
* @param {Object} request
155+
* The request object that will be sent.
156+
* @param {Object} request.document
161157
* Input document.
162158
*
163159
* This object should have the same structure as [Document]{@link Document}
164-
* @param {number} encodingType
160+
* @param {number} request.encodingType
165161
* The encoding type used by the API to calculate offsets.
166162
*
167163
* The number should be among the values of [EncodingType]{@link EncodingType}
@@ -172,39 +168,33 @@ LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment(
172168
* The function which will be called with the result of the API call.
173169
*
174170
* The second parameter to the callback is an object representing [AnalyzeEntitiesResponse]{@link AnalyzeEntitiesResponse}
175-
* @returns {gax.EventEmitter} - the event emitter to handle the call
176-
* status.
171+
* @returns {Promise} - The promise which resolves to the response object.
172+
* The promise has a method named "cancel" which cancels the ongoing API call.
177173
*
178174
* @example
179175
*
180176
* var api = languageV1beta1.languageServiceApi();
181177
* var document = {};
182178
* var encodingType = EncodingType.NONE;
183-
* api.analyzeEntities(document, encodingType, function(err, response) {
184-
* if (err) {
185-
* console.error(err);
186-
* return;
187-
* }
179+
* var request = {
180+
* document: document,
181+
* encodingType: encodingType
182+
* };
183+
* api.analyzeEntities(request).then(function(response) {
188184
* // doThingsWith(response)
185+
* }).catch(function(err) {
186+
* console.error(err);
189187
* });
190188
*/
191-
LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities(
192-
document,
193-
encodingType,
194-
options,
195-
callback) {
189+
LanguageServiceApi.prototype.analyzeEntities = function(request, options, callback) {
196190
if (options instanceof Function && callback === undefined) {
197191
callback = options;
198192
options = {};
199193
}
200194
if (options === undefined) {
201195
options = {};
202196
}
203-
var req = {
204-
document: document,
205-
encodingType: encodingType
206-
};
207-
return this._analyzeEntities(req, options, callback);
197+
return this._analyzeEntities(request, options, callback);
208198
};
209199

210200
/**
@@ -213,15 +203,17 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities(
213203
* API is intended for users who are familiar with machine learning and need
214204
* in-depth text features to build upon.
215205
*
216-
* @param {Object} document
206+
* @param {Object} request
207+
* The request object that will be sent.
208+
* @param {Object} request.document
217209
* Input document.
218210
*
219211
* This object should have the same structure as [Document]{@link Document}
220-
* @param {Object} features
212+
* @param {Object} request.features
221213
* The enabled features.
222214
*
223215
* This object should have the same structure as [Features]{@link Features}
224-
* @param {number} encodingType
216+
* @param {number} request.encodingType
225217
* The encoding type used by the API to calculate offsets.
226218
*
227219
* The number should be among the values of [EncodingType]{@link EncodingType}
@@ -232,42 +224,35 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities(
232224
* The function which will be called with the result of the API call.
233225
*
234226
* The second parameter to the callback is an object representing [AnnotateTextResponse]{@link AnnotateTextResponse}
235-
* @returns {gax.EventEmitter} - the event emitter to handle the call
236-
* status.
227+
* @returns {Promise} - The promise which resolves to the response object.
228+
* The promise has a method named "cancel" which cancels the ongoing API call.
237229
*
238230
* @example
239231
*
240232
* var api = languageV1beta1.languageServiceApi();
241233
* var document = {};
242234
* var features = {};
243235
* var encodingType = EncodingType.NONE;
244-
* api.annotateText(document, features, encodingType, function(err, response) {
245-
* if (err) {
246-
* console.error(err);
247-
* return;
248-
* }
236+
* var request = {
237+
* document: document,
238+
* features: features,
239+
* encodingType: encodingType
240+
* };
241+
* api.annotateText(request).then(function(response) {
249242
* // doThingsWith(response)
243+
* }).catch(function(err) {
244+
* console.error(err);
250245
* });
251246
*/
252-
LanguageServiceApi.prototype.annotateText = function annotateText(
253-
document,
254-
features,
255-
encodingType,
256-
options,
257-
callback) {
247+
LanguageServiceApi.prototype.annotateText = function(request, options, callback) {
258248
if (options instanceof Function && callback === undefined) {
259249
callback = options;
260250
options = {};
261251
}
262252
if (options === undefined) {
263253
options = {};
264254
}
265-
var req = {
266-
document: document,
267-
features: features,
268-
encodingType: encodingType
269-
};
270-
return this._annotateText(req, options, callback);
255+
return this._annotateText(request, options, callback);
271256
};
272257

273258
function LanguageServiceApiBuilder(gaxGrpc) {

packages/language/test/document.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,16 @@ describe('Document', function() {
180180
describe('annotate', function() {
181181
it('should make the correct API request', function(done) {
182182
document.api.Language = {
183-
annotateText: function(doc, features, encType) {
184-
assert.strictEqual(doc, document.document);
183+
annotateText: function(reqOpts) {
184+
assert.strictEqual(reqOpts.document, document.document);
185185

186-
assert.deepEqual(features, {
186+
assert.deepEqual(reqOpts.features, {
187187
extractDocumentSentiment: true,
188188
extractEntities: true,
189189
extractSyntax: true
190190
});
191191

192-
assert.strictEqual(encType, document.encodingType);
192+
assert.strictEqual(reqOpts.encodingType, document.encodingType);
193193

194194
done();
195195
}
@@ -201,8 +201,8 @@ describe('Document', function() {
201201

202202
it('should allow specifying individual features', function(done) {
203203
document.api.Language = {
204-
annotateText: function(doc, features) {
205-
assert.deepEqual(features, {
204+
annotateText: function(reqOpts) {
205+
assert.deepEqual(reqOpts.features, {
206206
extractDocumentSentiment: false,
207207
extractEntities: true,
208208
extractSyntax: true
@@ -224,7 +224,7 @@ describe('Document', function() {
224224

225225
beforeEach(function() {
226226
document.api.Language = {
227-
annotateText: function(doc, features, encType, callback) {
227+
annotateText: function(options, callback) {
228228
callback(error, apiResponse);
229229
}
230230
};
@@ -271,7 +271,7 @@ describe('Document', function() {
271271
);
272272

273273
function createAnnotateTextWithResponse(apiResponse) {
274-
return function(doc, features, encType, callback) {
274+
return function(reqOpts, callback) {
275275
callback(null, apiResponse);
276276
};
277277
}
@@ -436,9 +436,9 @@ describe('Document', function() {
436436
describe('detectEntities', function() {
437437
it('should make the correct API request', function(done) {
438438
document.api.Language = {
439-
analyzeEntities: function(doc, encType) {
440-
assert.strictEqual(doc, document.document);
441-
assert.strictEqual(encType, document.encodingType);
439+
analyzeEntities: function(reqOpts) {
440+
assert.strictEqual(reqOpts.document, document.document);
441+
assert.strictEqual(reqOpts.encodingType, document.encodingType);
442442
done();
443443
}
444444
};
@@ -453,7 +453,7 @@ describe('Document', function() {
453453

454454
beforeEach(function() {
455455
document.api.Language = {
456-
analyzeEntities: function(doc, encType, callback) {
456+
analyzeEntities: function(reqOpts, callback) {
457457
callback(error, apiResponse);
458458
}
459459
};
@@ -478,7 +478,7 @@ describe('Document', function() {
478478

479479
beforeEach(function() {
480480
document.api.Language = {
481-
analyzeEntities: function(doc, encType, callback) {
481+
analyzeEntities: function(reqOpts, callback) {
482482
callback(null, apiResponse);
483483
}
484484
};
@@ -525,9 +525,9 @@ describe('Document', function() {
525525
describe('detectSentiment', function() {
526526
it('should make the correct API request', function(done) {
527527
document.api.Language = {
528-
analyzeSentiment: function(doc, encType) {
529-
assert.strictEqual(doc, document.document);
530-
assert.strictEqual(encType, document.encodingType);
528+
analyzeSentiment: function(reqOpts) {
529+
assert.strictEqual(reqOpts.document, document.document);
530+
assert.strictEqual(reqOpts.encodingType, document.encodingType);
531531
done();
532532
}
533533
};
@@ -542,7 +542,7 @@ describe('Document', function() {
542542

543543
beforeEach(function() {
544544
document.api.Language = {
545-
analyzeSentiment: function(doc, encType, callback) {
545+
analyzeSentiment: function(reqOpts, callback) {
546546
callback(error, apiResponse);
547547
}
548548
};
@@ -569,7 +569,7 @@ describe('Document', function() {
569569
Document.formatSentiment_ = util.noop;
570570

571571
document.api.Language = {
572-
analyzeSentiment: function(doc, encType, callback) {
572+
analyzeSentiment: function(reqOpts, callback) {
573573
callback(null, apiResponse);
574574
}
575575
};

0 commit comments

Comments
 (0)