-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Gapic-generated files for language API. (#1476)
- Loading branch information
1 parent
fe101d7
commit 8d40033
Showing
5 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*! | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
var languageServiceApi = require('./language_service_api'); | ||
var extend = require('extend'); | ||
var gax = require('google-gax'); | ||
|
||
function v1beta1(options) { | ||
options = extend({ | ||
scopes: v1beta1.ALL_SCOPES | ||
}, options); | ||
var gaxGrpc = gax.grpc(options); | ||
return languageServiceApi(gaxGrpc); | ||
} | ||
|
||
v1beta1.SERVICE_ADDRESS = languageServiceApi.SERVICE_ADDRESS; | ||
v1beta1.ALL_SCOPES = languageServiceApi.ALL_SCOPES; | ||
module.exports = v1beta1; |
251 changes: 251 additions & 0 deletions
251
packages/google-cloud-language/src/v1beta1/language_service_api.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
/* | ||
* Copyright 2016 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* EDITING INSTRUCTIONS | ||
* This file was generated from the file | ||
* https://github.com/googleapis/googleapis/blob/master/library.proto, | ||
* and updates to that file get reflected here through a refresh process. | ||
* For the short term, the refresh process will only be runnable by Google | ||
* engineers. | ||
* | ||
* The only allowed edits are to method and file documentation. A 3-way | ||
* merge preserves those additions if the generated source changes. | ||
*/ | ||
/* TODO: introduce line-wrapping so that it never exceeds the limit. */ | ||
/* jscs: disable maximumLineLength */ | ||
'use strict'; | ||
|
||
var arguejs = require('arguejs'); | ||
var configData = require('./language_service_client_config'); | ||
var extend = require('extend'); | ||
var gax = require('google-gax'); | ||
|
||
var SERVICE_ADDRESS = 'language.googleapis.com'; | ||
|
||
var DEFAULT_SERVICE_PORT = 443; | ||
|
||
var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; | ||
|
||
var DEFAULT_TIMEOUT = 30; | ||
|
||
/** | ||
* The scopes needed to make gRPC calls to all of the methods defined in | ||
* this service. | ||
*/ | ||
var ALL_SCOPES = [ | ||
'https://www.googleapis.com/auth/cloud-platform' | ||
]; | ||
|
||
/** | ||
* Provides text analysis operations such as sentiment analysis and entity | ||
* recognition. | ||
* | ||
* This will be created through a builder function which can be obtained by the module. | ||
* See the following example of how to initialize the module and how to access to the builder. | ||
* | ||
* @example | ||
* var languageV1beta1 = require('@google-cloud/language').v1beta1({ | ||
* // optional auth parameters. | ||
* }); | ||
* var api = languageV1beta1.languageServiceApi(); | ||
* | ||
* @class | ||
* @param {Object=} opts - The optional parameters. | ||
* @param {String=} opts.servicePath | ||
* The domain name of the API remote host. | ||
* @param {number=} opts.port | ||
* The port on which to connect to the remote host. | ||
* @param {grpc.ClientCredentials=} opts.sslCreds | ||
* A ClientCredentials for use with an SSL-enabled channel. | ||
* @param {Object=} opts.clientConfig | ||
* The customized config to build the call settings. See | ||
* {@link gax.constructSettings} for the format. | ||
* @param {number=} opts.timeout | ||
* The default timeout, in seconds, for calls made through this client. | ||
* @param {number=} opts.appName | ||
* The codename of the calling service. | ||
* @param {String=} opts.appVersion | ||
* The version of the calling service. | ||
*/ | ||
function LanguageServiceApi(gaxGrpc, grpcClient, opts) { | ||
opts = opts || {}; | ||
var servicePath = opts.servicePath || SERVICE_ADDRESS; | ||
var port = opts.port || DEFAULT_SERVICE_PORT; | ||
var sslCreds = opts.sslCreds || null; | ||
var clientConfig = opts.clientConfig || {}; | ||
var timeout = opts.timeout || DEFAULT_TIMEOUT; | ||
var appName = opts.appName || 'gax'; | ||
var appVersion = opts.appVersion || gax.Version; | ||
|
||
var googleApiClient = [ | ||
appName + '/' + appVersion, | ||
CODE_GEN_NAME_VERSION, | ||
'nodejs/' + process.version].join(' '); | ||
|
||
var defaults = gaxGrpc.constructSettings( | ||
'google.cloud.language.v1beta1.LanguageService', | ||
configData, | ||
clientConfig, | ||
timeout, | ||
null, | ||
null, | ||
{'x-goog-api-client': googleApiClient}); | ||
|
||
var stub = gaxGrpc.createStub( | ||
servicePath, | ||
port, | ||
grpcClient.google.cloud.language.v1beta1.LanguageService, | ||
{sslCreds: sslCreds}); | ||
var methods = [ | ||
'analyzeSentiment', | ||
'analyzeEntities', | ||
'annotateText' | ||
]; | ||
methods.forEach(function(methodName) { | ||
this['_' + methodName] = gax.createApiCall( | ||
stub.then(function(stub) { return stub[methodName].bind(stub); }), | ||
defaults[methodName]); | ||
}.bind(this)); | ||
} | ||
|
||
// Callback types | ||
|
||
/** | ||
* @callback APICallback | ||
* @param {?Error} error - the error object if something goes wrong. | ||
* Null if API succeeds. | ||
* @param {?T} response | ||
* The response object when API succeeds. | ||
* @template T | ||
*/ | ||
|
||
/** | ||
* @callback EmptyCallback | ||
* @param {?Error} error - the error object if something goes wrong. | ||
* Null if API succeeds. | ||
*/ | ||
|
||
// Service calls | ||
|
||
/** | ||
* Analyzes the sentiment of the provided text. | ||
* | ||
* @param {google.cloud.language.v1beta1.Document} document | ||
* Input document. Currently, `analyzeSentiment` only supports English text | ||
* ({@link Document.language}="EN"). | ||
* @param {gax.CallOptions=} options | ||
* Overrides the default settings for this call, e.g, timeout, | ||
* retries, etc. | ||
* @param {APICallback<google.cloud.language.v1beta1.AnalyzeSentimentResponse>=} callback | ||
* The function which will be called with the result of the API call. | ||
* @returns {gax.EventEmitter} - the event emitter to handle the call | ||
* status. | ||
* @throws an error if the RPC is aborted. | ||
*/ | ||
LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment() { | ||
var args = arguejs({ | ||
document: Object, | ||
options: [gax.CallOptions], | ||
callback: [Function] | ||
}, arguments); | ||
var req = { | ||
document: args.document | ||
}; | ||
return this._analyzeSentiment(req, args.options, args.callback); | ||
}; | ||
|
||
/** | ||
* Finds named entities (currently finds proper names) in the text, | ||
* entity types, salience, mentions for each entity, and other properties. | ||
* | ||
* @param {google.cloud.language.v1beta1.Document} document | ||
* Input document. | ||
* @param {google.cloud.language.v1beta1.EncodingType} encodingType | ||
* The encoding type used by the API to calculate offsets. | ||
* @param {gax.CallOptions=} options | ||
* Overrides the default settings for this call, e.g, timeout, | ||
* retries, etc. | ||
* @param {APICallback<google.cloud.language.v1beta1.AnalyzeEntitiesResponse>=} callback | ||
* The function which will be called with the result of the API call. | ||
* @returns {gax.EventEmitter} - the event emitter to handle the call | ||
* status. | ||
* @throws an error if the RPC is aborted. | ||
*/ | ||
LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities() { | ||
var args = arguejs({ | ||
document: Object, | ||
encodingType: Number, | ||
options: [gax.CallOptions], | ||
callback: [Function] | ||
}, arguments); | ||
var req = { | ||
document: args.document, | ||
encoding_type: args.encodingType | ||
}; | ||
return this._analyzeEntities(req, args.options, args.callback); | ||
}; | ||
|
||
/** | ||
* Advanced API that analyzes the document and provides a full set of text | ||
* annotations, including semantic, syntactic, and sentiment information. This | ||
* API is intended for users who are familiar with machine learning and need | ||
* in-depth text features to build upon. | ||
* | ||
* @param {google.cloud.language.v1beta1.Document} document | ||
* Input document. | ||
* @param {google.cloud.language.v1beta1.AnnotateTextRequest.Features} features | ||
* The enabled features. | ||
* @param {google.cloud.language.v1beta1.EncodingType} encodingType | ||
* The encoding type used by the API to calculate offsets. | ||
* @param {gax.CallOptions=} options | ||
* Overrides the default settings for this call, e.g, timeout, | ||
* retries, etc. | ||
* @param {APICallback<google.cloud.language.v1beta1.AnnotateTextResponse>=} callback | ||
* The function which will be called with the result of the API call. | ||
* @returns {gax.EventEmitter} - the event emitter to handle the call | ||
* status. | ||
* @throws an error if the RPC is aborted. | ||
*/ | ||
LanguageServiceApi.prototype.annotateText = function annotateText() { | ||
var args = arguejs({ | ||
document: Object, | ||
features: Object, | ||
encodingType: Number, | ||
options: [gax.CallOptions], | ||
callback: [Function] | ||
}, arguments); | ||
var req = { | ||
document: args.document, | ||
features: args.features, | ||
encoding_type: args.encodingType | ||
}; | ||
return this._annotateText(req, args.options, args.callback); | ||
}; | ||
|
||
module.exports = function build(gaxGrpc) { | ||
var grpcClient = gaxGrpc.load([{ | ||
root: require('google-proto-files')('..'), | ||
file: 'google/cloud/language/v1beta1/language_service.proto' | ||
}]); | ||
var built = grpcClient.google.cloud.language.v1beta1; | ||
|
||
built.languageServiceApi = function(opts) { | ||
return new LanguageServiceApi(gaxGrpc, grpcClient, opts); | ||
}; | ||
extend(built.languageServiceApi, LanguageServiceApi); | ||
return built; | ||
}; | ||
module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; | ||
module.exports.ALL_SCOPES = ALL_SCOPES; |
43 changes: 43 additions & 0 deletions
43
packages/google-cloud-language/src/v1beta1/language_service_client_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"interfaces": { | ||
"google.cloud.language.v1beta1.LanguageService": { | ||
"retry_codes": { | ||
"retry_codes_def": { | ||
"idempotent": [ | ||
"DEADLINE_EXCEEDED", | ||
"UNAVAILABLE" | ||
], | ||
"non_idempotent": [] | ||
} | ||
}, | ||
"retry_params": { | ||
"default": { | ||
"initial_retry_delay_millis": 100, | ||
"retry_delay_multiplier": 1.3, | ||
"max_retry_delay_millis": 60000, | ||
"initial_rpc_timeout_millis": 60000, | ||
"rpc_timeout_multiplier": 1.0, | ||
"max_rpc_timeout_millis": 60000, | ||
"total_timeout_millis": 600000 | ||
} | ||
}, | ||
"methods": { | ||
"AnalyzeSentiment": { | ||
"timeout_millis": 30000, | ||
"retry_codes_name": "idempotent", | ||
"retry_params_name": "default" | ||
}, | ||
"AnalyzeEntities": { | ||
"timeout_millis": 30000, | ||
"retry_codes_name": "idempotent", | ||
"retry_params_name": "default" | ||
}, | ||
"AnnotateText": { | ||
"timeout_millis": 30000, | ||
"retry_codes_name": "idempotent", | ||
"retry_params_name": "default" | ||
} | ||
} | ||
} | ||
} | ||
} |