google-cloud-language-v1 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,734 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "gapic/common"
20
+ require "gapic/config"
21
+ require "gapic/config/method"
22
+
23
+ require "google/cloud/errors"
24
+ require "google/cloud/language/v1/version"
25
+ require "google/cloud/language/v1/language_service_pb"
26
+ require "google/cloud/language/v1/language_service/credentials"
27
+
28
+
29
+ module Google
30
+ module Cloud
31
+ module Language
32
+ module V1
33
+ module LanguageService
34
+ # Service that implements LanguageService API.
35
+ class Client
36
+ # @private
37
+ attr_reader :language_service_stub
38
+
39
+ ##
40
+ # Configure the LanguageService Client class.
41
+ #
42
+ # See {Google::Cloud::Language::V1::LanguageService::Client::Configuration}
43
+ # for a description of the configuration fields.
44
+ #
45
+ # ## Example
46
+ #
47
+ # To modify the configuration for all LanguageService clients:
48
+ #
49
+ # Google::Cloud::Language::V1::LanguageService::Client.configure do |config|
50
+ # config.timeout = 10_000
51
+ # end
52
+ #
53
+ # @yield [config] Configure the Client client.
54
+ # @yieldparam config [Client::Configuration]
55
+ #
56
+ # @return [Client::Configuration]
57
+ #
58
+ def self.configure
59
+ @configure ||= begin
60
+ namespace = ["Google", "Cloud", "Language", "V1"]
61
+ parent_config = while namespace.any?
62
+ parent_name = namespace.join "::"
63
+ parent_const = const_get parent_name
64
+ break parent_const.configure if parent_const&.respond_to? :configure
65
+ namespace.pop
66
+ end
67
+ default_config = Client::Configuration.new parent_config
68
+
69
+ default_config.rpcs.analyze_sentiment.timeout = 600.0
70
+ default_config.rpcs.analyze_sentiment.retry_policy = {
71
+ initial_delay: 0.1,
72
+ max_delay: 60.0,
73
+ multiplier: 1.3,
74
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
75
+ }
76
+
77
+ default_config.rpcs.analyze_entities.timeout = 600.0
78
+ default_config.rpcs.analyze_entities.retry_policy = {
79
+ initial_delay: 0.1,
80
+ max_delay: 60.0,
81
+ multiplier: 1.3,
82
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
83
+ }
84
+
85
+ default_config.rpcs.analyze_entity_sentiment.timeout = 600.0
86
+ default_config.rpcs.analyze_entity_sentiment.retry_policy = {
87
+ initial_delay: 0.1,
88
+ max_delay: 60.0,
89
+ multiplier: 1.3,
90
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
91
+ }
92
+
93
+ default_config.rpcs.analyze_syntax.timeout = 600.0
94
+ default_config.rpcs.analyze_syntax.retry_policy = {
95
+ initial_delay: 0.1,
96
+ max_delay: 60.0,
97
+ multiplier: 1.3,
98
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
99
+ }
100
+
101
+ default_config.rpcs.classify_text.timeout = 600.0
102
+ default_config.rpcs.classify_text.retry_policy = {
103
+ initial_delay: 0.1,
104
+ max_delay: 60.0,
105
+ multiplier: 1.3,
106
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
107
+ }
108
+
109
+ default_config.rpcs.annotate_text.timeout = 600.0
110
+ default_config.rpcs.annotate_text.retry_policy = {
111
+ initial_delay: 0.1,
112
+ max_delay: 60.0,
113
+ multiplier: 1.3,
114
+ retry_codes: ["DEADLINE_EXCEEDED", "UNAVAILABLE"]
115
+ }
116
+
117
+ default_config
118
+ end
119
+ yield @configure if block_given?
120
+ @configure
121
+ end
122
+
123
+ ##
124
+ # Configure the LanguageService Client instance.
125
+ #
126
+ # The configuration is set to the derived mode, meaning that values can be changed,
127
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
128
+ # should be made on {Client.configure}.
129
+ #
130
+ # See {Google::Cloud::Language::V1::LanguageService::Client::Configuration}
131
+ # for a description of the configuration fields.
132
+ #
133
+ # @yield [config] Configure the Client client.
134
+ # @yieldparam config [Client::Configuration]
135
+ #
136
+ # @return [Client::Configuration]
137
+ #
138
+ def configure
139
+ yield @config if block_given?
140
+ @config
141
+ end
142
+
143
+ ##
144
+ # Create a new LanguageService client object.
145
+ #
146
+ # ## Examples
147
+ #
148
+ # To create a new LanguageService client with the default
149
+ # configuration:
150
+ #
151
+ # client = Google::Cloud::Language::V1::LanguageService::Client.new
152
+ #
153
+ # To create a new LanguageService client with a custom
154
+ # configuration:
155
+ #
156
+ # client = Google::Cloud::Language::V1::LanguageService::Client.new do |config|
157
+ # config.timeout = 10_000
158
+ # end
159
+ #
160
+ # @yield [config] Configure the LanguageService client.
161
+ # @yieldparam config [Client::Configuration]
162
+ #
163
+ def initialize
164
+ # These require statements are intentionally placed here to initialize
165
+ # the gRPC module only when it's required.
166
+ # See https://github.com/googleapis/toolkit/issues/446
167
+ require "gapic/grpc"
168
+ require "google/cloud/language/v1/language_service_services_pb"
169
+
170
+ # Create the configuration object
171
+ @config = Configuration.new Client.configure
172
+
173
+ # Yield the configuration if needed
174
+ yield @config if block_given?
175
+
176
+ # Create credentials
177
+ credentials = @config.credentials
178
+ credentials ||= Credentials.default scope: @config.scope
179
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
180
+ credentials = Credentials.new credentials, scope: @config.scope
181
+ end
182
+ @quota_project_id = credentials.respond_to?(:quota_project_id) ? credentials.quota_project_id : nil
183
+
184
+ @language_service_stub = Gapic::ServiceStub.new(
185
+ Google::Cloud::Language::V1::LanguageService::Stub,
186
+ credentials: credentials,
187
+ endpoint: @config.endpoint,
188
+ channel_args: @config.channel_args,
189
+ interceptors: @config.interceptors
190
+ )
191
+ end
192
+
193
+ # Service calls
194
+
195
+ ##
196
+ # Analyzes the sentiment of the provided text.
197
+ #
198
+ # @overload analyze_sentiment(request, options = nil)
199
+ # @param request [Google::Cloud::Language::V1::AnalyzeSentimentRequest | Hash]
200
+ # Analyzes the sentiment of the provided text.
201
+ # @param options [Gapic::CallOptions, Hash]
202
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
203
+ #
204
+ # @overload analyze_sentiment(document: nil, encoding_type: nil)
205
+ # @param document [Google::Cloud::Language::V1::Document | Hash]
206
+ # Input document.
207
+ # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
208
+ # The encoding type used by the API to calculate sentence offsets.
209
+ #
210
+ #
211
+ # @yield [response, operation] Access the result along with the RPC operation
212
+ # @yieldparam response [Google::Cloud::Language::V1::AnalyzeSentimentResponse]
213
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
214
+ #
215
+ # @return [Google::Cloud::Language::V1::AnalyzeSentimentResponse]
216
+ #
217
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
218
+ #
219
+ def analyze_sentiment request, options = nil
220
+ raise ArgumentError, "request must be provided" if request.nil?
221
+
222
+ request = Gapic::Protobuf.coerce request, to: Google::Cloud::Language::V1::AnalyzeSentimentRequest
223
+
224
+ # Converts hash and nil to an options object
225
+ options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
226
+
227
+ # Customize the options with defaults
228
+ metadata = @config.rpcs.analyze_sentiment.metadata.to_h
229
+
230
+ # Set x-goog-api-client and x-goog-user-project headers
231
+ metadata[:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \
232
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
233
+ gapic_version: ::Google::Cloud::Language::V1::VERSION
234
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
235
+
236
+ options.apply_defaults timeout: @config.rpcs.analyze_sentiment.timeout,
237
+ metadata: metadata,
238
+ retry_policy: @config.rpcs.analyze_sentiment.retry_policy
239
+ options.apply_defaults metadata: @config.metadata,
240
+ retry_policy: @config.retry_policy
241
+
242
+ @language_service_stub.call_rpc :analyze_sentiment, request, options: options do |response, operation|
243
+ yield response, operation if block_given?
244
+ return response
245
+ end
246
+ rescue GRPC::BadStatus => e
247
+ raise Google::Cloud::Error.from_error(e)
248
+ end
249
+
250
+ ##
251
+ # Finds named entities (currently proper names and common nouns) in the text
252
+ # along with entity types, salience, mentions for each entity, and
253
+ # other properties.
254
+ #
255
+ # @overload analyze_entities(request, options = nil)
256
+ # @param request [Google::Cloud::Language::V1::AnalyzeEntitiesRequest | Hash]
257
+ # Finds named entities (currently proper names and common nouns) in the text
258
+ # along with entity types, salience, mentions for each entity, and
259
+ # other properties.
260
+ # @param options [Gapic::CallOptions, Hash]
261
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
262
+ #
263
+ # @overload analyze_entities(document: nil, encoding_type: nil)
264
+ # @param document [Google::Cloud::Language::V1::Document | Hash]
265
+ # Input document.
266
+ # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
267
+ # The encoding type used by the API to calculate offsets.
268
+ #
269
+ #
270
+ # @yield [response, operation] Access the result along with the RPC operation
271
+ # @yieldparam response [Google::Cloud::Language::V1::AnalyzeEntitiesResponse]
272
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
273
+ #
274
+ # @return [Google::Cloud::Language::V1::AnalyzeEntitiesResponse]
275
+ #
276
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
277
+ #
278
+ def analyze_entities request, options = nil
279
+ raise ArgumentError, "request must be provided" if request.nil?
280
+
281
+ request = Gapic::Protobuf.coerce request, to: Google::Cloud::Language::V1::AnalyzeEntitiesRequest
282
+
283
+ # Converts hash and nil to an options object
284
+ options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
285
+
286
+ # Customize the options with defaults
287
+ metadata = @config.rpcs.analyze_entities.metadata.to_h
288
+
289
+ # Set x-goog-api-client and x-goog-user-project headers
290
+ metadata[:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \
291
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
292
+ gapic_version: ::Google::Cloud::Language::V1::VERSION
293
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
294
+
295
+ options.apply_defaults timeout: @config.rpcs.analyze_entities.timeout,
296
+ metadata: metadata,
297
+ retry_policy: @config.rpcs.analyze_entities.retry_policy
298
+ options.apply_defaults metadata: @config.metadata,
299
+ retry_policy: @config.retry_policy
300
+
301
+ @language_service_stub.call_rpc :analyze_entities, request, options: options do |response, operation|
302
+ yield response, operation if block_given?
303
+ return response
304
+ end
305
+ rescue GRPC::BadStatus => e
306
+ raise Google::Cloud::Error.from_error(e)
307
+ end
308
+
309
+ ##
310
+ # Finds entities, similar to {Google::Cloud::Language::V1::LanguageService::Client#analyze_entities AnalyzeEntities} in the text and analyzes
311
+ # sentiment associated with each entity and its mentions.
312
+ #
313
+ # @overload analyze_entity_sentiment(request, options = nil)
314
+ # @param request [Google::Cloud::Language::V1::AnalyzeEntitySentimentRequest | Hash]
315
+ # Finds entities, similar to {Google::Cloud::Language::V1::LanguageService::Client#analyze_entities AnalyzeEntities} in the text and analyzes
316
+ # sentiment associated with each entity and its mentions.
317
+ # @param options [Gapic::CallOptions, Hash]
318
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
319
+ #
320
+ # @overload analyze_entity_sentiment(document: nil, encoding_type: nil)
321
+ # @param document [Google::Cloud::Language::V1::Document | Hash]
322
+ # Input document.
323
+ # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
324
+ # The encoding type used by the API to calculate offsets.
325
+ #
326
+ #
327
+ # @yield [response, operation] Access the result along with the RPC operation
328
+ # @yieldparam response [Google::Cloud::Language::V1::AnalyzeEntitySentimentResponse]
329
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
330
+ #
331
+ # @return [Google::Cloud::Language::V1::AnalyzeEntitySentimentResponse]
332
+ #
333
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
334
+ #
335
+ def analyze_entity_sentiment request, options = nil
336
+ raise ArgumentError, "request must be provided" if request.nil?
337
+
338
+ request = Gapic::Protobuf.coerce request, to: Google::Cloud::Language::V1::AnalyzeEntitySentimentRequest
339
+
340
+ # Converts hash and nil to an options object
341
+ options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
342
+
343
+ # Customize the options with defaults
344
+ metadata = @config.rpcs.analyze_entity_sentiment.metadata.to_h
345
+
346
+ # Set x-goog-api-client and x-goog-user-project headers
347
+ metadata[:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \
348
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
349
+ gapic_version: ::Google::Cloud::Language::V1::VERSION
350
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
351
+
352
+ options.apply_defaults timeout: @config.rpcs.analyze_entity_sentiment.timeout,
353
+ metadata: metadata,
354
+ retry_policy: @config.rpcs.analyze_entity_sentiment.retry_policy
355
+ options.apply_defaults metadata: @config.metadata,
356
+ retry_policy: @config.retry_policy
357
+
358
+ @language_service_stub.call_rpc :analyze_entity_sentiment, request, options: options do |response, operation|
359
+ yield response, operation if block_given?
360
+ return response
361
+ end
362
+ rescue GRPC::BadStatus => e
363
+ raise Google::Cloud::Error.from_error(e)
364
+ end
365
+
366
+ ##
367
+ # Analyzes the syntax of the text and provides sentence boundaries and
368
+ # tokenization along with part of speech tags, dependency trees, and other
369
+ # properties.
370
+ #
371
+ # @overload analyze_syntax(request, options = nil)
372
+ # @param request [Google::Cloud::Language::V1::AnalyzeSyntaxRequest | Hash]
373
+ # Analyzes the syntax of the text and provides sentence boundaries and
374
+ # tokenization along with part of speech tags, dependency trees, and other
375
+ # properties.
376
+ # @param options [Gapic::CallOptions, Hash]
377
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
378
+ #
379
+ # @overload analyze_syntax(document: nil, encoding_type: nil)
380
+ # @param document [Google::Cloud::Language::V1::Document | Hash]
381
+ # Input document.
382
+ # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
383
+ # The encoding type used by the API to calculate offsets.
384
+ #
385
+ #
386
+ # @yield [response, operation] Access the result along with the RPC operation
387
+ # @yieldparam response [Google::Cloud::Language::V1::AnalyzeSyntaxResponse]
388
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
389
+ #
390
+ # @return [Google::Cloud::Language::V1::AnalyzeSyntaxResponse]
391
+ #
392
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
393
+ #
394
+ def analyze_syntax request, options = nil
395
+ raise ArgumentError, "request must be provided" if request.nil?
396
+
397
+ request = Gapic::Protobuf.coerce request, to: Google::Cloud::Language::V1::AnalyzeSyntaxRequest
398
+
399
+ # Converts hash and nil to an options object
400
+ options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
401
+
402
+ # Customize the options with defaults
403
+ metadata = @config.rpcs.analyze_syntax.metadata.to_h
404
+
405
+ # Set x-goog-api-client and x-goog-user-project headers
406
+ metadata[:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \
407
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
408
+ gapic_version: ::Google::Cloud::Language::V1::VERSION
409
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
410
+
411
+ options.apply_defaults timeout: @config.rpcs.analyze_syntax.timeout,
412
+ metadata: metadata,
413
+ retry_policy: @config.rpcs.analyze_syntax.retry_policy
414
+ options.apply_defaults metadata: @config.metadata,
415
+ retry_policy: @config.retry_policy
416
+
417
+ @language_service_stub.call_rpc :analyze_syntax, request, options: options do |response, operation|
418
+ yield response, operation if block_given?
419
+ return response
420
+ end
421
+ rescue GRPC::BadStatus => e
422
+ raise Google::Cloud::Error.from_error(e)
423
+ end
424
+
425
+ ##
426
+ # Classifies a document into categories.
427
+ #
428
+ # @overload classify_text(request, options = nil)
429
+ # @param request [Google::Cloud::Language::V1::ClassifyTextRequest | Hash]
430
+ # Classifies a document into categories.
431
+ # @param options [Gapic::CallOptions, Hash]
432
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
433
+ #
434
+ # @overload classify_text(document: nil)
435
+ # @param document [Google::Cloud::Language::V1::Document | Hash]
436
+ # Input document.
437
+ #
438
+ #
439
+ # @yield [response, operation] Access the result along with the RPC operation
440
+ # @yieldparam response [Google::Cloud::Language::V1::ClassifyTextResponse]
441
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
442
+ #
443
+ # @return [Google::Cloud::Language::V1::ClassifyTextResponse]
444
+ #
445
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
446
+ #
447
+ def classify_text request, options = nil
448
+ raise ArgumentError, "request must be provided" if request.nil?
449
+
450
+ request = Gapic::Protobuf.coerce request, to: Google::Cloud::Language::V1::ClassifyTextRequest
451
+
452
+ # Converts hash and nil to an options object
453
+ options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
454
+
455
+ # Customize the options with defaults
456
+ metadata = @config.rpcs.classify_text.metadata.to_h
457
+
458
+ # Set x-goog-api-client and x-goog-user-project headers
459
+ metadata[:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \
460
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
461
+ gapic_version: ::Google::Cloud::Language::V1::VERSION
462
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
463
+
464
+ options.apply_defaults timeout: @config.rpcs.classify_text.timeout,
465
+ metadata: metadata,
466
+ retry_policy: @config.rpcs.classify_text.retry_policy
467
+ options.apply_defaults metadata: @config.metadata,
468
+ retry_policy: @config.retry_policy
469
+
470
+ @language_service_stub.call_rpc :classify_text, request, options: options do |response, operation|
471
+ yield response, operation if block_given?
472
+ return response
473
+ end
474
+ rescue GRPC::BadStatus => e
475
+ raise Google::Cloud::Error.from_error(e)
476
+ end
477
+
478
+ ##
479
+ # A convenience method that provides all the features that analyzeSentiment,
480
+ # analyzeEntities, and analyzeSyntax provide in one call.
481
+ #
482
+ # @overload annotate_text(request, options = nil)
483
+ # @param request [Google::Cloud::Language::V1::AnnotateTextRequest | Hash]
484
+ # A convenience method that provides all the features that analyzeSentiment,
485
+ # analyzeEntities, and analyzeSyntax provide in one call.
486
+ # @param options [Gapic::CallOptions, Hash]
487
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
488
+ #
489
+ # @overload annotate_text(document: nil, features: nil, encoding_type: nil)
490
+ # @param document [Google::Cloud::Language::V1::Document | Hash]
491
+ # Input document.
492
+ # @param features [Google::Cloud::Language::V1::AnnotateTextRequest::Features | Hash]
493
+ # The enabled features.
494
+ # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
495
+ # The encoding type used by the API to calculate offsets.
496
+ #
497
+ #
498
+ # @yield [response, operation] Access the result along with the RPC operation
499
+ # @yieldparam response [Google::Cloud::Language::V1::AnnotateTextResponse]
500
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
501
+ #
502
+ # @return [Google::Cloud::Language::V1::AnnotateTextResponse]
503
+ #
504
+ # @raise [Google::Cloud::Error] if the RPC is aborted.
505
+ #
506
+ def annotate_text request, options = nil
507
+ raise ArgumentError, "request must be provided" if request.nil?
508
+
509
+ request = Gapic::Protobuf.coerce request, to: Google::Cloud::Language::V1::AnnotateTextRequest
510
+
511
+ # Converts hash and nil to an options object
512
+ options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
513
+
514
+ # Customize the options with defaults
515
+ metadata = @config.rpcs.annotate_text.metadata.to_h
516
+
517
+ # Set x-goog-api-client and x-goog-user-project headers
518
+ metadata[:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \
519
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
520
+ gapic_version: ::Google::Cloud::Language::V1::VERSION
521
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
522
+
523
+ options.apply_defaults timeout: @config.rpcs.annotate_text.timeout,
524
+ metadata: metadata,
525
+ retry_policy: @config.rpcs.annotate_text.retry_policy
526
+ options.apply_defaults metadata: @config.metadata,
527
+ retry_policy: @config.retry_policy
528
+
529
+ @language_service_stub.call_rpc :annotate_text, request, options: options do |response, operation|
530
+ yield response, operation if block_given?
531
+ return response
532
+ end
533
+ rescue GRPC::BadStatus => e
534
+ raise Google::Cloud::Error.from_error(e)
535
+ end
536
+
537
+ ##
538
+ # Configuration class for the LanguageService API.
539
+ #
540
+ # This class represents the configuration for LanguageService,
541
+ # providing control over timeouts, retry behavior, logging, transport
542
+ # parameters, and other low-level controls. Certain parameters can also be
543
+ # applied individually to specific RPCs. See
544
+ # {Google::Cloud::Language::V1::LanguageService::Client::Configuration::Rpcs}
545
+ # for a list of RPCs that can be configured independently.
546
+ #
547
+ # Configuration can be applied globally to all clients, or to a single client
548
+ # on construction.
549
+ #
550
+ # # Examples
551
+ #
552
+ # To modify the global config, setting the timeout for analyze_sentiment
553
+ # to 20 seconds, and all remaining timeouts to 10 seconds:
554
+ #
555
+ # Google::Cloud::Language::V1::LanguageService::Client.configure do |config|
556
+ # config.timeout = 10_000
557
+ # config.rpcs.analyze_sentiment.timeout = 20_000
558
+ # end
559
+ #
560
+ # To apply the above configuration only to a new client:
561
+ #
562
+ # client = Google::Cloud::Language::V1::LanguageService::Client.new do |config|
563
+ # config.timeout = 10_000
564
+ # config.rpcs.analyze_sentiment.timeout = 20_000
565
+ # end
566
+ #
567
+ # @!attribute [rw] endpoint
568
+ # The hostname or hostname:port of the service endpoint.
569
+ # Defaults to `"language.googleapis.com"`.
570
+ # @return [String]
571
+ # @!attribute [rw] credentials
572
+ # Credentials to send with calls. You may provide any of the following types:
573
+ # * (`String`) The path to a service account key file in JSON format
574
+ # * (`Hash`) A service account key as a Hash
575
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
576
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
577
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
578
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
579
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
580
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
581
+ # * (`nil`) indicating no credentials
582
+ # @return [Object]
583
+ # @!attribute [rw] scope
584
+ # The OAuth scopes
585
+ # @return [Array<String>]
586
+ # @!attribute [rw] lib_name
587
+ # The library name as recorded in instrumentation and logging
588
+ # @return [String]
589
+ # @!attribute [rw] lib_version
590
+ # The library version as recorded in instrumentation and logging
591
+ # @return [String]
592
+ # @!attribute [rw] channel_args
593
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
594
+ # `GRPC::Core::Channel` object is provided as the credential.
595
+ # @return [Hash]
596
+ # @!attribute [rw] interceptors
597
+ # An array of interceptors that are run before calls are executed.
598
+ # @return [Array<GRPC::ClientInterceptor>]
599
+ # @!attribute [rw] timeout
600
+ # The call timeout in milliseconds.
601
+ # @return [Numeric]
602
+ # @!attribute [rw] metadata
603
+ # Additional gRPC headers to be sent with the call.
604
+ # @return [Hash{Symbol=>String}]
605
+ # @!attribute [rw] retry_policy
606
+ # The retry policy. The value is a hash with the following keys:
607
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
608
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
609
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
610
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
611
+ # trigger a retry.
612
+ # @return [Hash]
613
+ #
614
+ class Configuration
615
+ extend Gapic::Config
616
+
617
+ config_attr :endpoint, "language.googleapis.com", String
618
+ config_attr :credentials, nil do |value|
619
+ allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
620
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
621
+ allowed.any? { |klass| klass === value }
622
+ end
623
+ config_attr :scope, nil, String, Array, nil
624
+ config_attr :lib_name, nil, String, nil
625
+ config_attr :lib_version, nil, String, nil
626
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution"=>1 }, Hash, nil)
627
+ config_attr :interceptors, nil, Array, nil
628
+ config_attr :timeout, nil, Numeric, nil
629
+ config_attr :metadata, nil, Hash, nil
630
+ config_attr :retry_policy, nil, Hash, Proc, nil
631
+
632
+ # @private
633
+ def initialize parent_config = nil
634
+ @parent_config = parent_config unless parent_config.nil?
635
+
636
+ yield self if block_given?
637
+ end
638
+
639
+ ##
640
+ # Configurations for individual RPCs
641
+ # @return [Rpcs]
642
+ #
643
+ def rpcs
644
+ @rpcs ||= begin
645
+ parent_rpcs = nil
646
+ parent_rpcs = @parent_config.rpcs if @parent_config&.respond_to? :rpcs
647
+ Rpcs.new parent_rpcs
648
+ end
649
+ end
650
+
651
+ ##
652
+ # Configuration RPC class for the LanguageService API.
653
+ #
654
+ # Includes fields providing the configuration for each RPC in this service.
655
+ # Each configuration object is of type `Gapic::Config::Method` and includes
656
+ # the following configuration fields:
657
+ #
658
+ # * `timeout` (*type:* `Numeric`) - The call timeout in milliseconds
659
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
660
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
661
+ # include the following keys:
662
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
663
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
664
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
665
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
666
+ # trigger a retry.
667
+ #
668
+ class Rpcs
669
+ ##
670
+ # RPC-specific configuration for `analyze_sentiment`
671
+ # @return [Gapic::Config::Method]
672
+ #
673
+ attr_reader :analyze_sentiment
674
+ ##
675
+ # RPC-specific configuration for `analyze_entities`
676
+ # @return [Gapic::Config::Method]
677
+ #
678
+ attr_reader :analyze_entities
679
+ ##
680
+ # RPC-specific configuration for `analyze_entity_sentiment`
681
+ # @return [Gapic::Config::Method]
682
+ #
683
+ attr_reader :analyze_entity_sentiment
684
+ ##
685
+ # RPC-specific configuration for `analyze_syntax`
686
+ # @return [Gapic::Config::Method]
687
+ #
688
+ attr_reader :analyze_syntax
689
+ ##
690
+ # RPC-specific configuration for `classify_text`
691
+ # @return [Gapic::Config::Method]
692
+ #
693
+ attr_reader :classify_text
694
+ ##
695
+ # RPC-specific configuration for `annotate_text`
696
+ # @return [Gapic::Config::Method]
697
+ #
698
+ attr_reader :annotate_text
699
+
700
+ # @private
701
+ def initialize parent_rpcs = nil
702
+ analyze_sentiment_config = parent_rpcs&.analyze_sentiment if parent_rpcs&.respond_to? :analyze_sentiment
703
+ @analyze_sentiment = Gapic::Config::Method.new analyze_sentiment_config
704
+ analyze_entities_config = parent_rpcs&.analyze_entities if parent_rpcs&.respond_to? :analyze_entities
705
+ @analyze_entities = Gapic::Config::Method.new analyze_entities_config
706
+ analyze_entity_sentiment_config = parent_rpcs&.analyze_entity_sentiment if parent_rpcs&.respond_to? :analyze_entity_sentiment
707
+ @analyze_entity_sentiment = Gapic::Config::Method.new analyze_entity_sentiment_config
708
+ analyze_syntax_config = parent_rpcs&.analyze_syntax if parent_rpcs&.respond_to? :analyze_syntax
709
+ @analyze_syntax = Gapic::Config::Method.new analyze_syntax_config
710
+ classify_text_config = parent_rpcs&.classify_text if parent_rpcs&.respond_to? :classify_text
711
+ @classify_text = Gapic::Config::Method.new classify_text_config
712
+ annotate_text_config = parent_rpcs&.annotate_text if parent_rpcs&.respond_to? :annotate_text
713
+ @annotate_text = Gapic::Config::Method.new annotate_text_config
714
+
715
+ yield self if block_given?
716
+ end
717
+ end
718
+ end
719
+ end
720
+ end
721
+ end
722
+ end
723
+ end
724
+ end
725
+
726
+ # rubocop:disable Lint/HandleExceptions
727
+
728
+ # Once client is loaded, load helpers.rb if it exists.
729
+ begin
730
+ require "google/cloud/language/v1/language_service/helpers"
731
+ rescue LoadError
732
+ end
733
+
734
+ # rubocop:enable Lint/HandleExceptions