google-cloud-language-v2 0.a → 0.2.0

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