google-cloud-language-v1beta2 0.6.0 → 0.8.0

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