google-cloud-language 0.33.0 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,448 +0,0 @@
1
- # Copyright 2019 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
-
28
- require "google/cloud/language/v1/language_service_pb"
29
- require "google/cloud/language/v1/credentials"
30
- require "google/cloud/language/version"
31
-
32
- module Google
33
- module Cloud
34
- module Language
35
- module V1
36
- # Provides text analysis operations such as sentiment analysis and entity
37
- # recognition.
38
- #
39
- # @!attribute [r] language_service_stub
40
- # @return [Google::Cloud::Language::V1::LanguageService::Stub]
41
- class LanguageServiceClient
42
- # @private
43
- attr_reader :language_service_stub
44
-
45
- # The default address of the service.
46
- SERVICE_ADDRESS = "language.googleapis.com".freeze
47
-
48
- # The default port of the service.
49
- DEFAULT_SERVICE_PORT = 443
50
-
51
- # The default set of gRPC interceptors.
52
- GRPC_INTERCEPTORS = []
53
-
54
- DEFAULT_TIMEOUT = 30
55
-
56
- # The scopes needed to make gRPC calls to all of the methods defined in
57
- # this service.
58
- ALL_SCOPES = [
59
- "https://www.googleapis.com/auth/cloud-language",
60
- "https://www.googleapis.com/auth/cloud-platform"
61
- ].freeze
62
-
63
-
64
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
65
- # Provides the means for authenticating requests made by the client. This parameter can
66
- # be many types.
67
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
68
- # authenticating requests made by this client.
69
- # A `String` will be treated as the path to the keyfile to be used for the construction of
70
- # credentials for this client.
71
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
72
- # credentials for this client.
73
- # A `GRPC::Core::Channel` will be used to make calls through.
74
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
75
- # should already be composed with a `GRPC::Core::CallCredentials` object.
76
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
77
- # metadata for requests, generally, to give OAuth credentials.
78
- # @param scopes [Array<String>]
79
- # The OAuth scopes for this service. This parameter is ignored if
80
- # an updater_proc is supplied.
81
- # @param client_config [Hash]
82
- # A Hash for call options for each method. See
83
- # Google::Gax#construct_settings for the structure of
84
- # this data. Falls back to the default config if not specified
85
- # or the specified config is missing data points.
86
- # @param timeout [Numeric]
87
- # The default timeout, in seconds, for calls made through this client.
88
- # @param metadata [Hash]
89
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
90
- # @param service_address [String]
91
- # Override for the service hostname, or `nil` to leave as the default.
92
- # @param service_port [Integer]
93
- # Override for the service port, or `nil` to leave as the default.
94
- # @param exception_transformer [Proc]
95
- # An optional proc that intercepts any exceptions raised during an API call to inject
96
- # custom error handling.
97
- def initialize \
98
- credentials: nil,
99
- scopes: ALL_SCOPES,
100
- client_config: {},
101
- timeout: DEFAULT_TIMEOUT,
102
- metadata: nil,
103
- service_address: nil,
104
- service_port: nil,
105
- exception_transformer: nil,
106
- lib_name: nil,
107
- lib_version: ""
108
- # These require statements are intentionally placed here to initialize
109
- # the gRPC module only when it's required.
110
- # See https://github.com/googleapis/toolkit/issues/446
111
- require "google/gax/grpc"
112
- require "google/cloud/language/v1/language_service_services_pb"
113
-
114
- credentials ||= Google::Cloud::Language::V1::Credentials.default
115
-
116
- if credentials.is_a?(String) || credentials.is_a?(Hash)
117
- updater_proc = Google::Cloud::Language::V1::Credentials.new(credentials).updater_proc
118
- end
119
- if credentials.is_a?(GRPC::Core::Channel)
120
- channel = credentials
121
- end
122
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
123
- chan_creds = credentials
124
- end
125
- if credentials.is_a?(Proc)
126
- updater_proc = credentials
127
- end
128
- if credentials.is_a?(Google::Auth::Credentials)
129
- updater_proc = credentials.updater_proc
130
- end
131
-
132
- package_version = Google::Cloud::Language::VERSION
133
-
134
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
135
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
136
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
137
- google_api_client << " grpc/#{GRPC::VERSION}"
138
- google_api_client.freeze
139
-
140
- headers = { :"x-goog-api-client" => google_api_client }
141
- headers.merge!(metadata) unless metadata.nil?
142
- client_config_file = Pathname.new(__dir__).join(
143
- "language_service_client_config.json"
144
- )
145
- defaults = client_config_file.open do |f|
146
- Google::Gax.construct_settings(
147
- "google.cloud.language.v1.LanguageService",
148
- JSON.parse(f.read),
149
- client_config,
150
- Google::Gax::Grpc::STATUS_CODE_NAMES,
151
- timeout,
152
- errors: Google::Gax::Grpc::API_ERRORS,
153
- metadata: headers
154
- )
155
- end
156
-
157
- # Allow overriding the service path/port in subclasses.
158
- service_path = service_address || self.class::SERVICE_ADDRESS
159
- port = service_port || self.class::DEFAULT_SERVICE_PORT
160
- interceptors = self.class::GRPC_INTERCEPTORS
161
- @language_service_stub = Google::Gax::Grpc.create_stub(
162
- service_path,
163
- port,
164
- chan_creds: chan_creds,
165
- channel: channel,
166
- updater_proc: updater_proc,
167
- scopes: scopes,
168
- interceptors: interceptors,
169
- &Google::Cloud::Language::V1::LanguageService::Stub.method(:new)
170
- )
171
-
172
- @analyze_sentiment = Google::Gax.create_api_call(
173
- @language_service_stub.method(:analyze_sentiment),
174
- defaults["analyze_sentiment"],
175
- exception_transformer: exception_transformer
176
- )
177
- @analyze_entities = Google::Gax.create_api_call(
178
- @language_service_stub.method(:analyze_entities),
179
- defaults["analyze_entities"],
180
- exception_transformer: exception_transformer
181
- )
182
- @analyze_entity_sentiment = Google::Gax.create_api_call(
183
- @language_service_stub.method(:analyze_entity_sentiment),
184
- defaults["analyze_entity_sentiment"],
185
- exception_transformer: exception_transformer
186
- )
187
- @analyze_syntax = Google::Gax.create_api_call(
188
- @language_service_stub.method(:analyze_syntax),
189
- defaults["analyze_syntax"],
190
- exception_transformer: exception_transformer
191
- )
192
- @classify_text = Google::Gax.create_api_call(
193
- @language_service_stub.method(:classify_text),
194
- defaults["classify_text"],
195
- exception_transformer: exception_transformer
196
- )
197
- @annotate_text = Google::Gax.create_api_call(
198
- @language_service_stub.method(:annotate_text),
199
- defaults["annotate_text"],
200
- exception_transformer: exception_transformer
201
- )
202
- end
203
-
204
- # Service calls
205
-
206
- # Analyzes the sentiment of the provided text.
207
- #
208
- # @param document [Google::Cloud::Language::V1::Document | Hash]
209
- # Input document.
210
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
211
- # can also be provided.
212
- # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
213
- # The encoding type used by the API to calculate sentence offsets.
214
- # @param options [Google::Gax::CallOptions]
215
- # Overrides the default settings for this call, e.g, timeout,
216
- # retries, etc.
217
- # @yield [result, operation] Access the result along with the RPC operation
218
- # @yieldparam result [Google::Cloud::Language::V1::AnalyzeSentimentResponse]
219
- # @yieldparam operation [GRPC::ActiveCall::Operation]
220
- # @return [Google::Cloud::Language::V1::AnalyzeSentimentResponse]
221
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
222
- # @example
223
- # require "google/cloud/language"
224
- #
225
- # language_client = Google::Cloud::Language.new(version: :v1)
226
- #
227
- # # TODO: Initialize `document`:
228
- # document = {}
229
- # response = language_client.analyze_sentiment(document)
230
-
231
- def analyze_sentiment \
232
- document,
233
- encoding_type: nil,
234
- options: nil,
235
- &block
236
- req = {
237
- document: document,
238
- encoding_type: encoding_type
239
- }.delete_if { |_, v| v.nil? }
240
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1::AnalyzeSentimentRequest)
241
- @analyze_sentiment.call(req, options, &block)
242
- end
243
-
244
- # Finds named entities (currently proper names and common nouns) in the text
245
- # along with entity types, salience, mentions for each entity, and
246
- # other properties.
247
- #
248
- # @param document [Google::Cloud::Language::V1::Document | Hash]
249
- # Input document.
250
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
251
- # can also be provided.
252
- # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
253
- # The encoding type used by the API to calculate offsets.
254
- # @param options [Google::Gax::CallOptions]
255
- # Overrides the default settings for this call, e.g, timeout,
256
- # retries, etc.
257
- # @yield [result, operation] Access the result along with the RPC operation
258
- # @yieldparam result [Google::Cloud::Language::V1::AnalyzeEntitiesResponse]
259
- # @yieldparam operation [GRPC::ActiveCall::Operation]
260
- # @return [Google::Cloud::Language::V1::AnalyzeEntitiesResponse]
261
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
262
- # @example
263
- # require "google/cloud/language"
264
- #
265
- # language_client = Google::Cloud::Language.new(version: :v1)
266
- #
267
- # # TODO: Initialize `document`:
268
- # document = {}
269
- # response = language_client.analyze_entities(document)
270
-
271
- def analyze_entities \
272
- document,
273
- encoding_type: nil,
274
- options: nil,
275
- &block
276
- req = {
277
- document: document,
278
- encoding_type: encoding_type
279
- }.delete_if { |_, v| v.nil? }
280
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1::AnalyzeEntitiesRequest)
281
- @analyze_entities.call(req, options, &block)
282
- end
283
-
284
- # Finds entities, similar to {Google::Cloud::Language::V1::LanguageService::AnalyzeEntities AnalyzeEntities} in the text and analyzes
285
- # sentiment associated with each entity and its mentions.
286
- #
287
- # @param document [Google::Cloud::Language::V1::Document | Hash]
288
- # Input document.
289
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
290
- # can also be provided.
291
- # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
292
- # The encoding type used by the API to calculate offsets.
293
- # @param options [Google::Gax::CallOptions]
294
- # Overrides the default settings for this call, e.g, timeout,
295
- # retries, etc.
296
- # @yield [result, operation] Access the result along with the RPC operation
297
- # @yieldparam result [Google::Cloud::Language::V1::AnalyzeEntitySentimentResponse]
298
- # @yieldparam operation [GRPC::ActiveCall::Operation]
299
- # @return [Google::Cloud::Language::V1::AnalyzeEntitySentimentResponse]
300
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
301
- # @example
302
- # require "google/cloud/language"
303
- #
304
- # language_client = Google::Cloud::Language.new(version: :v1)
305
- #
306
- # # TODO: Initialize `document`:
307
- # document = {}
308
- # response = language_client.analyze_entity_sentiment(document)
309
-
310
- def analyze_entity_sentiment \
311
- document,
312
- encoding_type: nil,
313
- options: nil,
314
- &block
315
- req = {
316
- document: document,
317
- encoding_type: encoding_type
318
- }.delete_if { |_, v| v.nil? }
319
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1::AnalyzeEntitySentimentRequest)
320
- @analyze_entity_sentiment.call(req, options, &block)
321
- end
322
-
323
- # Analyzes the syntax of the text and provides sentence boundaries and
324
- # tokenization along with part of speech tags, dependency trees, and other
325
- # properties.
326
- #
327
- # @param document [Google::Cloud::Language::V1::Document | Hash]
328
- # Input document.
329
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
330
- # can also be provided.
331
- # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
332
- # The encoding type used by the API to calculate offsets.
333
- # @param options [Google::Gax::CallOptions]
334
- # Overrides the default settings for this call, e.g, timeout,
335
- # retries, etc.
336
- # @yield [result, operation] Access the result along with the RPC operation
337
- # @yieldparam result [Google::Cloud::Language::V1::AnalyzeSyntaxResponse]
338
- # @yieldparam operation [GRPC::ActiveCall::Operation]
339
- # @return [Google::Cloud::Language::V1::AnalyzeSyntaxResponse]
340
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
341
- # @example
342
- # require "google/cloud/language"
343
- #
344
- # language_client = Google::Cloud::Language.new(version: :v1)
345
- #
346
- # # TODO: Initialize `document`:
347
- # document = {}
348
- # response = language_client.analyze_syntax(document)
349
-
350
- def analyze_syntax \
351
- document,
352
- encoding_type: nil,
353
- options: nil,
354
- &block
355
- req = {
356
- document: document,
357
- encoding_type: encoding_type
358
- }.delete_if { |_, v| v.nil? }
359
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1::AnalyzeSyntaxRequest)
360
- @analyze_syntax.call(req, options, &block)
361
- end
362
-
363
- # Classifies a document into categories.
364
- #
365
- # @param document [Google::Cloud::Language::V1::Document | Hash]
366
- # Input document.
367
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
368
- # can also be provided.
369
- # @param options [Google::Gax::CallOptions]
370
- # Overrides the default settings for this call, e.g, timeout,
371
- # retries, etc.
372
- # @yield [result, operation] Access the result along with the RPC operation
373
- # @yieldparam result [Google::Cloud::Language::V1::ClassifyTextResponse]
374
- # @yieldparam operation [GRPC::ActiveCall::Operation]
375
- # @return [Google::Cloud::Language::V1::ClassifyTextResponse]
376
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
377
- # @example
378
- # require "google/cloud/language"
379
- #
380
- # language_client = Google::Cloud::Language.new(version: :v1)
381
- #
382
- # # TODO: Initialize `document`:
383
- # document = {}
384
- # response = language_client.classify_text(document)
385
-
386
- def classify_text \
387
- document,
388
- options: nil,
389
- &block
390
- req = {
391
- document: document
392
- }.delete_if { |_, v| v.nil? }
393
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1::ClassifyTextRequest)
394
- @classify_text.call(req, options, &block)
395
- end
396
-
397
- # A convenience method that provides all the features that analyzeSentiment,
398
- # analyzeEntities, and analyzeSyntax provide in one call.
399
- #
400
- # @param document [Google::Cloud::Language::V1::Document | Hash]
401
- # Input document.
402
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
403
- # can also be provided.
404
- # @param features [Google::Cloud::Language::V1::AnnotateTextRequest::Features | Hash]
405
- # The enabled features.
406
- # A hash of the same form as `Google::Cloud::Language::V1::AnnotateTextRequest::Features`
407
- # can also be provided.
408
- # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
409
- # The encoding type used by the API to calculate offsets.
410
- # @param options [Google::Gax::CallOptions]
411
- # Overrides the default settings for this call, e.g, timeout,
412
- # retries, etc.
413
- # @yield [result, operation] Access the result along with the RPC operation
414
- # @yieldparam result [Google::Cloud::Language::V1::AnnotateTextResponse]
415
- # @yieldparam operation [GRPC::ActiveCall::Operation]
416
- # @return [Google::Cloud::Language::V1::AnnotateTextResponse]
417
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
418
- # @example
419
- # require "google/cloud/language"
420
- #
421
- # language_client = Google::Cloud::Language.new(version: :v1)
422
- #
423
- # # TODO: Initialize `document`:
424
- # document = {}
425
- #
426
- # # TODO: Initialize `features`:
427
- # features = {}
428
- # response = language_client.annotate_text(document, features)
429
-
430
- def annotate_text \
431
- document,
432
- features,
433
- encoding_type: nil,
434
- options: nil,
435
- &block
436
- req = {
437
- document: document,
438
- features: features,
439
- encoding_type: encoding_type
440
- }.delete_if { |_, v| v.nil? }
441
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1::AnnotateTextRequest)
442
- @annotate_text.call(req, options, &block)
443
- end
444
- end
445
- end
446
- end
447
- end
448
- end
@@ -1,56 +0,0 @@
1
- {
2
- "interfaces": {
3
- "google.cloud.language.v1.LanguageService": {
4
- "retry_codes": {
5
- "idempotent": [
6
- "DEADLINE_EXCEEDED",
7
- "UNAVAILABLE"
8
- ],
9
- "non_idempotent": []
10
- },
11
- "retry_params": {
12
- "default": {
13
- "initial_retry_delay_millis": 100,
14
- "retry_delay_multiplier": 1.3,
15
- "max_retry_delay_millis": 60000,
16
- "initial_rpc_timeout_millis": 20000,
17
- "rpc_timeout_multiplier": 1.0,
18
- "max_rpc_timeout_millis": 20000,
19
- "total_timeout_millis": 600000
20
- }
21
- },
22
- "methods": {
23
- "AnalyzeSentiment": {
24
- "timeout_millis": 60000,
25
- "retry_codes_name": "idempotent",
26
- "retry_params_name": "default"
27
- },
28
- "AnalyzeEntities": {
29
- "timeout_millis": 60000,
30
- "retry_codes_name": "idempotent",
31
- "retry_params_name": "default"
32
- },
33
- "AnalyzeEntitySentiment": {
34
- "timeout_millis": 60000,
35
- "retry_codes_name": "idempotent",
36
- "retry_params_name": "default"
37
- },
38
- "AnalyzeSyntax": {
39
- "timeout_millis": 60000,
40
- "retry_codes_name": "idempotent",
41
- "retry_params_name": "default"
42
- },
43
- "ClassifyText": {
44
- "timeout_millis": 60000,
45
- "retry_codes_name": "idempotent",
46
- "retry_params_name": "default"
47
- },
48
- "AnnotateText": {
49
- "timeout_millis": 60000,
50
- "retry_codes_name": "idempotent",
51
- "retry_params_name": "default"
52
- }
53
- }
54
- }
55
- }
56
- }