Skip to content

Commit

Permalink
language: upgrade generated layer (#1723)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and sofisl committed Oct 13, 2022
1 parent 03e735c commit 5ce17c7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 88 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-language/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@google-cloud/common": "^0.7.0",
"arrify": "^1.0.1",
"extend": "^3.0.0",
"google-gax": "^0.7.0",
"google-gax": "^0.8.0",
"google-proto-files": "^0.8.3",
"is": "^3.0.1",
"propprop": "^0.3.1"
Expand Down
25 changes: 13 additions & 12 deletions packages/google-cloud-language/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,11 @@ Document.prototype.annotate = function(options, callback) {

var verbose = options.verbose === true;

var doc = this.document;
var encType = this.encodingType;

this.api.Language.annotateText(doc, features, encType, function(err, resp) {
this.api.Language.annotateText({
document: this.document,
features: features,
encodingType: this.encodingType
}, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
Expand Down Expand Up @@ -547,10 +548,10 @@ Document.prototype.detectEntities = function(options, callback) {

var verbose = options.verbose === true;

var doc = this.document;
var encType = this.encodingType;

this.api.Language.analyzeEntities(doc, encType, function(err, resp) {
this.api.Language.analyzeEntities({
document: this.document,
encodingType: this.encodingType
}, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
Expand Down Expand Up @@ -621,10 +622,10 @@ Document.prototype.detectSentiment = function(options, callback) {

var verbose = options.verbose === true;

var doc = this.document;
var encType = this.encodingType;

this.api.Language.analyzeSentiment(doc, encType, function(err, resp) {
this.api.Language.analyzeSentiment({
document: this.document,
encodingType: this.encodingType
}, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
Expand Down
99 changes: 42 additions & 57 deletions packages/google-cloud-language/src/v1beta1/language_service_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ function LanguageServiceApi(gaxGrpc, grpcClients, opts) {
/**
* Analyzes the sentiment of the provided text.
*
* @param {Object} document
* @param {Object} request
* The request object that will be sent.
* @param {Object} request.document
* Input document. Currently, `analyzeSentiment` only supports English text
* ({@link Document.language}="EN").
*
Expand All @@ -121,47 +123,41 @@ function LanguageServiceApi(gaxGrpc, grpcClients, opts) {
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [AnalyzeSentimentResponse]{@link AnalyzeSentimentResponse}
* @returns {gax.EventEmitter} - the event emitter to handle the call
* status.
* @returns {Promise} - The promise which resolves to the response object.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var api = languageV1beta1.languageServiceApi();
* var document = {};
* api.analyzeSentiment(document, function(err, response) {
* if (err) {
* console.error(err);
* return;
* }
* api.analyzeSentiment({document: document}).then(function(response) {
* // doThingsWith(response)
* }).catch(function(err) {
* console.error(err);
* });
*/
LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment(
document,
options,
callback) {
LanguageServiceApi.prototype.analyzeSentiment = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
var req = {
document: document
};
return this._analyzeSentiment(req, options, callback);
return this._analyzeSentiment(request, options, callback);
};

/**
* Finds named entities (currently finds proper names) in the text,
* entity types, salience, mentions for each entity, and other properties.
*
* @param {Object} document
* @param {Object} request
* The request object that will be sent.
* @param {Object} request.document
* Input document.
*
* This object should have the same structure as [Document]{@link Document}
* @param {number} encodingType
* @param {number} request.encodingType
* The encoding type used by the API to calculate offsets.
*
* The number should be among the values of [EncodingType]{@link EncodingType}
Expand All @@ -172,39 +168,33 @@ LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment(
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [AnalyzeEntitiesResponse]{@link AnalyzeEntitiesResponse}
* @returns {gax.EventEmitter} - the event emitter to handle the call
* status.
* @returns {Promise} - The promise which resolves to the response object.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var api = languageV1beta1.languageServiceApi();
* var document = {};
* var encodingType = EncodingType.NONE;
* api.analyzeEntities(document, encodingType, function(err, response) {
* if (err) {
* console.error(err);
* return;
* }
* var request = {
* document: document,
* encodingType: encodingType
* };
* api.analyzeEntities(request).then(function(response) {
* // doThingsWith(response)
* }).catch(function(err) {
* console.error(err);
* });
*/
LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities(
document,
encodingType,
options,
callback) {
LanguageServiceApi.prototype.analyzeEntities = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
var req = {
document: document,
encodingType: encodingType
};
return this._analyzeEntities(req, options, callback);
return this._analyzeEntities(request, options, callback);
};

/**
Expand All @@ -213,15 +203,17 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities(
* API is intended for users who are familiar with machine learning and need
* in-depth text features to build upon.
*
* @param {Object} document
* @param {Object} request
* The request object that will be sent.
* @param {Object} request.document
* Input document.
*
* This object should have the same structure as [Document]{@link Document}
* @param {Object} features
* @param {Object} request.features
* The enabled features.
*
* This object should have the same structure as [Features]{@link Features}
* @param {number} encodingType
* @param {number} request.encodingType
* The encoding type used by the API to calculate offsets.
*
* The number should be among the values of [EncodingType]{@link EncodingType}
Expand All @@ -232,42 +224,35 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities(
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is an object representing [AnnotateTextResponse]{@link AnnotateTextResponse}
* @returns {gax.EventEmitter} - the event emitter to handle the call
* status.
* @returns {Promise} - The promise which resolves to the response object.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var api = languageV1beta1.languageServiceApi();
* var document = {};
* var features = {};
* var encodingType = EncodingType.NONE;
* api.annotateText(document, features, encodingType, function(err, response) {
* if (err) {
* console.error(err);
* return;
* }
* var request = {
* document: document,
* features: features,
* encodingType: encodingType
* };
* api.annotateText(request).then(function(response) {
* // doThingsWith(response)
* }).catch(function(err) {
* console.error(err);
* });
*/
LanguageServiceApi.prototype.annotateText = function annotateText(
document,
features,
encodingType,
options,
callback) {
LanguageServiceApi.prototype.annotateText = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
var req = {
document: document,
features: features,
encodingType: encodingType
};
return this._annotateText(req, options, callback);
return this._annotateText(request, options, callback);
};

function LanguageServiceApiBuilder(gaxGrpc) {
Expand Down
36 changes: 18 additions & 18 deletions packages/google-cloud-language/test/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@ describe('Document', function() {
describe('annotate', function() {
it('should make the correct API request', function(done) {
document.api.Language = {
annotateText: function(doc, features, encType) {
assert.strictEqual(doc, document.document);
annotateText: function(reqOpts) {
assert.strictEqual(reqOpts.document, document.document);

assert.deepEqual(features, {
assert.deepEqual(reqOpts.features, {
extractDocumentSentiment: true,
extractEntities: true,
extractSyntax: true
});

assert.strictEqual(encType, document.encodingType);
assert.strictEqual(reqOpts.encodingType, document.encodingType);

done();
}
Expand All @@ -201,8 +201,8 @@ describe('Document', function() {

it('should allow specifying individual features', function(done) {
document.api.Language = {
annotateText: function(doc, features) {
assert.deepEqual(features, {
annotateText: function(reqOpts) {
assert.deepEqual(reqOpts.features, {
extractDocumentSentiment: false,
extractEntities: true,
extractSyntax: true
Expand All @@ -224,7 +224,7 @@ describe('Document', function() {

beforeEach(function() {
document.api.Language = {
annotateText: function(doc, features, encType, callback) {
annotateText: function(options, callback) {
callback(error, apiResponse);
}
};
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('Document', function() {
);

function createAnnotateTextWithResponse(apiResponse) {
return function(doc, features, encType, callback) {
return function(reqOpts, callback) {
callback(null, apiResponse);
};
}
Expand Down Expand Up @@ -436,9 +436,9 @@ describe('Document', function() {
describe('detectEntities', function() {
it('should make the correct API request', function(done) {
document.api.Language = {
analyzeEntities: function(doc, encType) {
assert.strictEqual(doc, document.document);
assert.strictEqual(encType, document.encodingType);
analyzeEntities: function(reqOpts) {
assert.strictEqual(reqOpts.document, document.document);
assert.strictEqual(reqOpts.encodingType, document.encodingType);
done();
}
};
Expand All @@ -453,7 +453,7 @@ describe('Document', function() {

beforeEach(function() {
document.api.Language = {
analyzeEntities: function(doc, encType, callback) {
analyzeEntities: function(reqOpts, callback) {
callback(error, apiResponse);
}
};
Expand All @@ -478,7 +478,7 @@ describe('Document', function() {

beforeEach(function() {
document.api.Language = {
analyzeEntities: function(doc, encType, callback) {
analyzeEntities: function(reqOpts, callback) {
callback(null, apiResponse);
}
};
Expand Down Expand Up @@ -525,9 +525,9 @@ describe('Document', function() {
describe('detectSentiment', function() {
it('should make the correct API request', function(done) {
document.api.Language = {
analyzeSentiment: function(doc, encType) {
assert.strictEqual(doc, document.document);
assert.strictEqual(encType, document.encodingType);
analyzeSentiment: function(reqOpts) {
assert.strictEqual(reqOpts.document, document.document);
assert.strictEqual(reqOpts.encodingType, document.encodingType);
done();
}
};
Expand All @@ -542,7 +542,7 @@ describe('Document', function() {

beforeEach(function() {
document.api.Language = {
analyzeSentiment: function(doc, encType, callback) {
analyzeSentiment: function(reqOpts, callback) {
callback(error, apiResponse);
}
};
Expand All @@ -569,7 +569,7 @@ describe('Document', function() {
Document.formatSentiment_ = util.noop;

document.api.Language = {
analyzeSentiment: function(doc, encType, callback) {
analyzeSentiment: function(reqOpts, callback) {
callback(null, apiResponse);
}
};
Expand Down

0 comments on commit 5ce17c7

Please sign in to comment.