google-cloud-language-v1beta2 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,740 @@
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 {::Google::Cloud::Language::V1beta2::LanguageService::Rest::Client#analyze_entities AnalyzeEntities} in the text and analyzes
300
+ # sentiment associated with each entity and its mentions.
301
+ #
302
+ # @overload analyze_entity_sentiment(request, options = nil)
303
+ # Pass arguments to `analyze_entity_sentiment` via a request object, either of type
304
+ # {::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentRequest} or an equivalent Hash.
305
+ #
306
+ # @param request [::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentRequest, ::Hash]
307
+ # A request object representing the call parameters. Required. To specify no
308
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
309
+ # @param options [::Gapic::CallOptions, ::Hash]
310
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
311
+ #
312
+ # @overload analyze_entity_sentiment(document: nil, encoding_type: nil)
313
+ # Pass arguments to `analyze_entity_sentiment` via keyword arguments. Note that at
314
+ # least one keyword argument is required. To specify no parameters, or to keep all
315
+ # the default parameter values, pass an empty Hash as a request object (see above).
316
+ #
317
+ # @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash]
318
+ # Required. Input document.
319
+ # @param encoding_type [::Google::Cloud::Language::V1beta2::EncodingType]
320
+ # The encoding type used by the API to calculate offsets.
321
+ # @yield [result, operation] Access the result along with the TransportOperation object
322
+ # @yieldparam result [::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentResponse]
323
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
324
+ #
325
+ # @return [::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentResponse]
326
+ #
327
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
328
+ def analyze_entity_sentiment request, options = nil
329
+ raise ::ArgumentError, "request must be provided" if request.nil?
330
+
331
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentRequest
332
+
333
+ # Converts hash and nil to an options object
334
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
335
+
336
+ # Customize the options with defaults
337
+ call_metadata = @config.rpcs.analyze_entity_sentiment.metadata.to_h
338
+
339
+ # Set x-goog-api-client and x-goog-user-project headers
340
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
341
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
342
+ gapic_version: ::Google::Cloud::Language::V1beta2::VERSION,
343
+ transports_version_send: [:rest]
344
+
345
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
346
+
347
+ options.apply_defaults timeout: @config.rpcs.analyze_entity_sentiment.timeout,
348
+ metadata: call_metadata,
349
+ retry_policy: @config.rpcs.analyze_entity_sentiment.retry_policy
350
+
351
+ options.apply_defaults timeout: @config.timeout,
352
+ metadata: @config.metadata,
353
+ retry_policy: @config.retry_policy
354
+
355
+ @language_service_stub.analyze_entity_sentiment request, options do |result, operation|
356
+ yield result, operation if block_given?
357
+ return result
358
+ end
359
+ rescue ::Gapic::Rest::Error => e
360
+ raise ::Google::Cloud::Error.from_error(e)
361
+ end
362
+
363
+ ##
364
+ # Analyzes the syntax of the text and provides sentence boundaries and
365
+ # tokenization along with part of speech tags, dependency trees, and other
366
+ # properties.
367
+ #
368
+ # @overload analyze_syntax(request, options = nil)
369
+ # Pass arguments to `analyze_syntax` via a request object, either of type
370
+ # {::Google::Cloud::Language::V1beta2::AnalyzeSyntaxRequest} or an equivalent Hash.
371
+ #
372
+ # @param request [::Google::Cloud::Language::V1beta2::AnalyzeSyntaxRequest, ::Hash]
373
+ # A request object representing the call parameters. Required. To specify no
374
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
375
+ # @param options [::Gapic::CallOptions, ::Hash]
376
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
377
+ #
378
+ # @overload analyze_syntax(document: nil, encoding_type: nil)
379
+ # Pass arguments to `analyze_syntax` via keyword arguments. Note that at
380
+ # least one keyword argument is required. To specify no parameters, or to keep all
381
+ # the default parameter values, pass an empty Hash as a request object (see above).
382
+ #
383
+ # @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash]
384
+ # Required. Input document.
385
+ # @param encoding_type [::Google::Cloud::Language::V1beta2::EncodingType]
386
+ # The encoding type used by the API to calculate offsets.
387
+ # @yield [result, operation] Access the result along with the TransportOperation object
388
+ # @yieldparam result [::Google::Cloud::Language::V1beta2::AnalyzeSyntaxResponse]
389
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
390
+ #
391
+ # @return [::Google::Cloud::Language::V1beta2::AnalyzeSyntaxResponse]
392
+ #
393
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
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::V1beta2::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
+ call_metadata = @config.rpcs.analyze_syntax.metadata.to_h
404
+
405
+ # Set x-goog-api-client and x-goog-user-project headers
406
+ call_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::V1beta2::VERSION,
409
+ transports_version_send: [:rest]
410
+
411
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
412
+
413
+ options.apply_defaults timeout: @config.rpcs.analyze_syntax.timeout,
414
+ metadata: call_metadata,
415
+ retry_policy: @config.rpcs.analyze_syntax.retry_policy
416
+
417
+ options.apply_defaults timeout: @config.timeout,
418
+ metadata: @config.metadata,
419
+ retry_policy: @config.retry_policy
420
+
421
+ @language_service_stub.analyze_syntax request, options do |result, operation|
422
+ yield result, operation if block_given?
423
+ return result
424
+ end
425
+ rescue ::Gapic::Rest::Error => e
426
+ raise ::Google::Cloud::Error.from_error(e)
427
+ end
428
+
429
+ ##
430
+ # Classifies a document into categories.
431
+ #
432
+ # @overload classify_text(request, options = nil)
433
+ # Pass arguments to `classify_text` via a request object, either of type
434
+ # {::Google::Cloud::Language::V1beta2::ClassifyTextRequest} or an equivalent Hash.
435
+ #
436
+ # @param request [::Google::Cloud::Language::V1beta2::ClassifyTextRequest, ::Hash]
437
+ # A request object representing the call parameters. Required. To specify no
438
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
439
+ # @param options [::Gapic::CallOptions, ::Hash]
440
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
441
+ #
442
+ # @overload classify_text(document: nil, classification_model_options: nil)
443
+ # Pass arguments to `classify_text` via keyword arguments. Note that at
444
+ # least one keyword argument is required. To specify no parameters, or to keep all
445
+ # the default parameter values, pass an empty Hash as a request object (see above).
446
+ #
447
+ # @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash]
448
+ # Required. Input document.
449
+ # @param classification_model_options [::Google::Cloud::Language::V1beta2::ClassificationModelOptions, ::Hash]
450
+ # Model options to use for classification. Defaults to v1 options if not
451
+ # specified.
452
+ # @yield [result, operation] Access the result along with the TransportOperation object
453
+ # @yieldparam result [::Google::Cloud::Language::V1beta2::ClassifyTextResponse]
454
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
455
+ #
456
+ # @return [::Google::Cloud::Language::V1beta2::ClassifyTextResponse]
457
+ #
458
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
459
+ def classify_text request, options = nil
460
+ raise ::ArgumentError, "request must be provided" if request.nil?
461
+
462
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::ClassifyTextRequest
463
+
464
+ # Converts hash and nil to an options object
465
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
466
+
467
+ # Customize the options with defaults
468
+ call_metadata = @config.rpcs.classify_text.metadata.to_h
469
+
470
+ # Set x-goog-api-client and x-goog-user-project headers
471
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
472
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
473
+ gapic_version: ::Google::Cloud::Language::V1beta2::VERSION,
474
+ transports_version_send: [:rest]
475
+
476
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
477
+
478
+ options.apply_defaults timeout: @config.rpcs.classify_text.timeout,
479
+ metadata: call_metadata,
480
+ retry_policy: @config.rpcs.classify_text.retry_policy
481
+
482
+ options.apply_defaults timeout: @config.timeout,
483
+ metadata: @config.metadata,
484
+ retry_policy: @config.retry_policy
485
+
486
+ @language_service_stub.classify_text request, options do |result, operation|
487
+ yield result, operation if block_given?
488
+ return result
489
+ end
490
+ rescue ::Gapic::Rest::Error => e
491
+ raise ::Google::Cloud::Error.from_error(e)
492
+ end
493
+
494
+ ##
495
+ # A convenience method that provides all syntax, sentiment, entity, and
496
+ # classification features in one call.
497
+ #
498
+ # @overload annotate_text(request, options = nil)
499
+ # Pass arguments to `annotate_text` via a request object, either of type
500
+ # {::Google::Cloud::Language::V1beta2::AnnotateTextRequest} or an equivalent Hash.
501
+ #
502
+ # @param request [::Google::Cloud::Language::V1beta2::AnnotateTextRequest, ::Hash]
503
+ # A request object representing the call parameters. Required. To specify no
504
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
505
+ # @param options [::Gapic::CallOptions, ::Hash]
506
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
507
+ #
508
+ # @overload annotate_text(document: nil, features: nil, encoding_type: nil)
509
+ # Pass arguments to `annotate_text` via keyword arguments. Note that at
510
+ # least one keyword argument is required. To specify no parameters, or to keep all
511
+ # the default parameter values, pass an empty Hash as a request object (see above).
512
+ #
513
+ # @param document [::Google::Cloud::Language::V1beta2::Document, ::Hash]
514
+ # Required. Input document.
515
+ # @param features [::Google::Cloud::Language::V1beta2::AnnotateTextRequest::Features, ::Hash]
516
+ # Required. The enabled features.
517
+ # @param encoding_type [::Google::Cloud::Language::V1beta2::EncodingType]
518
+ # The encoding type used by the API to calculate offsets.
519
+ # @yield [result, operation] Access the result along with the TransportOperation object
520
+ # @yieldparam result [::Google::Cloud::Language::V1beta2::AnnotateTextResponse]
521
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
522
+ #
523
+ # @return [::Google::Cloud::Language::V1beta2::AnnotateTextResponse]
524
+ #
525
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
526
+ def annotate_text request, options = nil
527
+ raise ::ArgumentError, "request must be provided" if request.nil?
528
+
529
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1beta2::AnnotateTextRequest
530
+
531
+ # Converts hash and nil to an options object
532
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
533
+
534
+ # Customize the options with defaults
535
+ call_metadata = @config.rpcs.annotate_text.metadata.to_h
536
+
537
+ # Set x-goog-api-client and x-goog-user-project headers
538
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
539
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
540
+ gapic_version: ::Google::Cloud::Language::V1beta2::VERSION,
541
+ transports_version_send: [:rest]
542
+
543
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
544
+
545
+ options.apply_defaults timeout: @config.rpcs.annotate_text.timeout,
546
+ metadata: call_metadata,
547
+ retry_policy: @config.rpcs.annotate_text.retry_policy
548
+
549
+ options.apply_defaults timeout: @config.timeout,
550
+ metadata: @config.metadata,
551
+ retry_policy: @config.retry_policy
552
+
553
+ @language_service_stub.annotate_text request, options do |result, operation|
554
+ yield result, operation if block_given?
555
+ return result
556
+ end
557
+ rescue ::Gapic::Rest::Error => e
558
+ raise ::Google::Cloud::Error.from_error(e)
559
+ end
560
+
561
+ ##
562
+ # Configuration class for the LanguageService REST API.
563
+ #
564
+ # This class represents the configuration for LanguageService REST,
565
+ # providing control over timeouts, retry behavior, logging, transport
566
+ # parameters, and other low-level controls. Certain parameters can also be
567
+ # applied individually to specific RPCs. See
568
+ # {::Google::Cloud::Language::V1beta2::LanguageService::Rest::Client::Configuration::Rpcs}
569
+ # for a list of RPCs that can be configured independently.
570
+ #
571
+ # Configuration can be applied globally to all clients, or to a single client
572
+ # on construction.
573
+ #
574
+ # @example
575
+ #
576
+ # # Modify the global config, setting the timeout for
577
+ # # analyze_sentiment to 20 seconds,
578
+ # # and all remaining timeouts to 10 seconds.
579
+ # ::Google::Cloud::Language::V1beta2::LanguageService::Rest::Client.configure do |config|
580
+ # config.timeout = 10.0
581
+ # config.rpcs.analyze_sentiment.timeout = 20.0
582
+ # end
583
+ #
584
+ # # Apply the above configuration only to a new client.
585
+ # client = ::Google::Cloud::Language::V1beta2::LanguageService::Rest::Client.new do |config|
586
+ # config.timeout = 10.0
587
+ # config.rpcs.analyze_sentiment.timeout = 20.0
588
+ # end
589
+ #
590
+ # @!attribute [rw] endpoint
591
+ # The hostname or hostname:port of the service endpoint.
592
+ # Defaults to `"language.googleapis.com"`.
593
+ # @return [::String]
594
+ # @!attribute [rw] credentials
595
+ # Credentials to send with calls. You may provide any of the following types:
596
+ # * (`String`) The path to a service account key file in JSON format
597
+ # * (`Hash`) A service account key as a Hash
598
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
599
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
600
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
601
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
602
+ # * (`nil`) indicating no credentials
603
+ # @return [::Object]
604
+ # @!attribute [rw] scope
605
+ # The OAuth scopes
606
+ # @return [::Array<::String>]
607
+ # @!attribute [rw] lib_name
608
+ # The library name as recorded in instrumentation and logging
609
+ # @return [::String]
610
+ # @!attribute [rw] lib_version
611
+ # The library version as recorded in instrumentation and logging
612
+ # @return [::String]
613
+ # @!attribute [rw] timeout
614
+ # The call timeout in seconds.
615
+ # @return [::Numeric]
616
+ # @!attribute [rw] metadata
617
+ # Additional headers to be sent with the call.
618
+ # @return [::Hash{::Symbol=>::String}]
619
+ # @!attribute [rw] retry_policy
620
+ # The retry policy. The value is a hash with the following keys:
621
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
622
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
623
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
624
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
625
+ # trigger a retry.
626
+ # @return [::Hash]
627
+ # @!attribute [rw] quota_project
628
+ # A separate project against which to charge quota.
629
+ # @return [::String]
630
+ #
631
+ class Configuration
632
+ extend ::Gapic::Config
633
+
634
+ config_attr :endpoint, "language.googleapis.com", ::String
635
+ config_attr :credentials, nil do |value|
636
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
637
+ allowed.any? { |klass| klass === value }
638
+ end
639
+ config_attr :scope, nil, ::String, ::Array, nil
640
+ config_attr :lib_name, nil, ::String, nil
641
+ config_attr :lib_version, nil, ::String, nil
642
+ config_attr :timeout, nil, ::Numeric, nil
643
+ config_attr :metadata, nil, ::Hash, nil
644
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
645
+ config_attr :quota_project, nil, ::String, nil
646
+
647
+ # @private
648
+ def initialize parent_config = nil
649
+ @parent_config = parent_config unless parent_config.nil?
650
+
651
+ yield self if block_given?
652
+ end
653
+
654
+ ##
655
+ # Configurations for individual RPCs
656
+ # @return [Rpcs]
657
+ #
658
+ def rpcs
659
+ @rpcs ||= begin
660
+ parent_rpcs = nil
661
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
662
+ Rpcs.new parent_rpcs
663
+ end
664
+ end
665
+
666
+ ##
667
+ # Configuration RPC class for the LanguageService API.
668
+ #
669
+ # Includes fields providing the configuration for each RPC in this service.
670
+ # Each configuration object is of type `Gapic::Config::Method` and includes
671
+ # the following configuration fields:
672
+ #
673
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
674
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
675
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
676
+ # include the following keys:
677
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
678
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
679
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
680
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
681
+ # trigger a retry.
682
+ #
683
+ class Rpcs
684
+ ##
685
+ # RPC-specific configuration for `analyze_sentiment`
686
+ # @return [::Gapic::Config::Method]
687
+ #
688
+ attr_reader :analyze_sentiment
689
+ ##
690
+ # RPC-specific configuration for `analyze_entities`
691
+ # @return [::Gapic::Config::Method]
692
+ #
693
+ attr_reader :analyze_entities
694
+ ##
695
+ # RPC-specific configuration for `analyze_entity_sentiment`
696
+ # @return [::Gapic::Config::Method]
697
+ #
698
+ attr_reader :analyze_entity_sentiment
699
+ ##
700
+ # RPC-specific configuration for `analyze_syntax`
701
+ # @return [::Gapic::Config::Method]
702
+ #
703
+ attr_reader :analyze_syntax
704
+ ##
705
+ # RPC-specific configuration for `classify_text`
706
+ # @return [::Gapic::Config::Method]
707
+ #
708
+ attr_reader :classify_text
709
+ ##
710
+ # RPC-specific configuration for `annotate_text`
711
+ # @return [::Gapic::Config::Method]
712
+ #
713
+ attr_reader :annotate_text
714
+
715
+ # @private
716
+ def initialize parent_rpcs = nil
717
+ analyze_sentiment_config = parent_rpcs.analyze_sentiment if parent_rpcs.respond_to? :analyze_sentiment
718
+ @analyze_sentiment = ::Gapic::Config::Method.new analyze_sentiment_config
719
+ analyze_entities_config = parent_rpcs.analyze_entities if parent_rpcs.respond_to? :analyze_entities
720
+ @analyze_entities = ::Gapic::Config::Method.new analyze_entities_config
721
+ analyze_entity_sentiment_config = parent_rpcs.analyze_entity_sentiment if parent_rpcs.respond_to? :analyze_entity_sentiment
722
+ @analyze_entity_sentiment = ::Gapic::Config::Method.new analyze_entity_sentiment_config
723
+ analyze_syntax_config = parent_rpcs.analyze_syntax if parent_rpcs.respond_to? :analyze_syntax
724
+ @analyze_syntax = ::Gapic::Config::Method.new analyze_syntax_config
725
+ classify_text_config = parent_rpcs.classify_text if parent_rpcs.respond_to? :classify_text
726
+ @classify_text = ::Gapic::Config::Method.new classify_text_config
727
+ annotate_text_config = parent_rpcs.annotate_text if parent_rpcs.respond_to? :annotate_text
728
+ @annotate_text = ::Gapic::Config::Method.new annotate_text_config
729
+
730
+ yield self if block_given?
731
+ end
732
+ end
733
+ end
734
+ end
735
+ end
736
+ end
737
+ end
738
+ end
739
+ end
740
+ end