google-cloud-language-v1 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,739 @@
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/v1/language_service_pb"
21
+ require "google/cloud/language/v1/language_service/rest/service_stub"
22
+
23
+ module Google
24
+ module Cloud
25
+ module Language
26
+ module V1
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::V1::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::V1::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", "V1"]
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: [4, 14]
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: [4, 14]
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: [4, 14]
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: [4, 14]
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: [4, 14]
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: [4, 14]
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::V1::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::V1::LanguageService::Rest::Client.new
131
+ #
132
+ # # Create a client using a custom configuration
133
+ # client = ::Google::Cloud::Language::V1::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::V1::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::V1::AnalyzeSentimentRequest} or an equivalent Hash.
173
+ #
174
+ # @param request [::Google::Cloud::Language::V1::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::V1::Document, ::Hash]
186
+ # Required. Input document.
187
+ # @param encoding_type [::Google::Cloud::Language::V1::EncodingType]
188
+ # The encoding type used by the API to calculate sentence offsets.
189
+ # @yield [result, operation] Access the result along with the TransportOperation object
190
+ # @yieldparam result [::Google::Cloud::Language::V1::AnalyzeSentimentResponse]
191
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
192
+ #
193
+ # @return [::Google::Cloud::Language::V1::AnalyzeSentimentResponse]
194
+ #
195
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
196
+ def analyze_sentiment request, options = nil
197
+ raise ::ArgumentError, "request must be provided" if request.nil?
198
+
199
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1::AnalyzeSentimentRequest
200
+
201
+ # Converts hash and nil to an options object
202
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
203
+
204
+ # Customize the options with defaults
205
+ call_metadata = @config.rpcs.analyze_sentiment.metadata.to_h
206
+
207
+ # Set x-goog-api-client and x-goog-user-project headers
208
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
209
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
210
+ gapic_version: ::Google::Cloud::Language::V1::VERSION,
211
+ transports_version_send: [:rest]
212
+
213
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
214
+
215
+ options.apply_defaults timeout: @config.rpcs.analyze_sentiment.timeout,
216
+ metadata: call_metadata,
217
+ retry_policy: @config.rpcs.analyze_sentiment.retry_policy
218
+
219
+ options.apply_defaults timeout: @config.timeout,
220
+ metadata: @config.metadata,
221
+ retry_policy: @config.retry_policy
222
+
223
+ @language_service_stub.analyze_sentiment request, options do |result, operation|
224
+ yield result, operation if block_given?
225
+ return result
226
+ end
227
+ rescue ::Gapic::Rest::Error => e
228
+ raise ::Google::Cloud::Error.from_error(e)
229
+ end
230
+
231
+ ##
232
+ # Finds named entities (currently proper names and common nouns) in the text
233
+ # along with entity types, salience, mentions for each entity, and
234
+ # other properties.
235
+ #
236
+ # @overload analyze_entities(request, options = nil)
237
+ # Pass arguments to `analyze_entities` via a request object, either of type
238
+ # {::Google::Cloud::Language::V1::AnalyzeEntitiesRequest} or an equivalent Hash.
239
+ #
240
+ # @param request [::Google::Cloud::Language::V1::AnalyzeEntitiesRequest, ::Hash]
241
+ # A request object representing the call parameters. Required. To specify no
242
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
243
+ # @param options [::Gapic::CallOptions, ::Hash]
244
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
245
+ #
246
+ # @overload analyze_entities(document: nil, encoding_type: nil)
247
+ # Pass arguments to `analyze_entities` via keyword arguments. Note that at
248
+ # least one keyword argument is required. To specify no parameters, or to keep all
249
+ # the default parameter values, pass an empty Hash as a request object (see above).
250
+ #
251
+ # @param document [::Google::Cloud::Language::V1::Document, ::Hash]
252
+ # Required. Input document.
253
+ # @param encoding_type [::Google::Cloud::Language::V1::EncodingType]
254
+ # The encoding type used by the API to calculate offsets.
255
+ # @yield [result, operation] Access the result along with the TransportOperation object
256
+ # @yieldparam result [::Google::Cloud::Language::V1::AnalyzeEntitiesResponse]
257
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
258
+ #
259
+ # @return [::Google::Cloud::Language::V1::AnalyzeEntitiesResponse]
260
+ #
261
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
262
+ def analyze_entities request, options = nil
263
+ raise ::ArgumentError, "request must be provided" if request.nil?
264
+
265
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1::AnalyzeEntitiesRequest
266
+
267
+ # Converts hash and nil to an options object
268
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
269
+
270
+ # Customize the options with defaults
271
+ call_metadata = @config.rpcs.analyze_entities.metadata.to_h
272
+
273
+ # Set x-goog-api-client and x-goog-user-project headers
274
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
275
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
276
+ gapic_version: ::Google::Cloud::Language::V1::VERSION,
277
+ transports_version_send: [:rest]
278
+
279
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
280
+
281
+ options.apply_defaults timeout: @config.rpcs.analyze_entities.timeout,
282
+ metadata: call_metadata,
283
+ retry_policy: @config.rpcs.analyze_entities.retry_policy
284
+
285
+ options.apply_defaults timeout: @config.timeout,
286
+ metadata: @config.metadata,
287
+ retry_policy: @config.retry_policy
288
+
289
+ @language_service_stub.analyze_entities request, options do |result, operation|
290
+ yield result, operation if block_given?
291
+ return result
292
+ end
293
+ rescue ::Gapic::Rest::Error => e
294
+ raise ::Google::Cloud::Error.from_error(e)
295
+ end
296
+
297
+ ##
298
+ # Finds entities, similar to {::Google::Cloud::Language::V1::LanguageService::Rest::Client#analyze_entities AnalyzeEntities} in the text and analyzes
299
+ # sentiment associated with each entity and its mentions.
300
+ #
301
+ # @overload analyze_entity_sentiment(request, options = nil)
302
+ # Pass arguments to `analyze_entity_sentiment` via a request object, either of type
303
+ # {::Google::Cloud::Language::V1::AnalyzeEntitySentimentRequest} or an equivalent Hash.
304
+ #
305
+ # @param request [::Google::Cloud::Language::V1::AnalyzeEntitySentimentRequest, ::Hash]
306
+ # A request object representing the call parameters. Required. To specify no
307
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
308
+ # @param options [::Gapic::CallOptions, ::Hash]
309
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
310
+ #
311
+ # @overload analyze_entity_sentiment(document: nil, encoding_type: nil)
312
+ # Pass arguments to `analyze_entity_sentiment` via keyword arguments. Note that at
313
+ # least one keyword argument is required. To specify no parameters, or to keep all
314
+ # the default parameter values, pass an empty Hash as a request object (see above).
315
+ #
316
+ # @param document [::Google::Cloud::Language::V1::Document, ::Hash]
317
+ # Required. Input document.
318
+ # @param encoding_type [::Google::Cloud::Language::V1::EncodingType]
319
+ # The encoding type used by the API to calculate offsets.
320
+ # @yield [result, operation] Access the result along with the TransportOperation object
321
+ # @yieldparam result [::Google::Cloud::Language::V1::AnalyzeEntitySentimentResponse]
322
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
323
+ #
324
+ # @return [::Google::Cloud::Language::V1::AnalyzeEntitySentimentResponse]
325
+ #
326
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
327
+ def analyze_entity_sentiment request, options = nil
328
+ raise ::ArgumentError, "request must be provided" if request.nil?
329
+
330
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1::AnalyzeEntitySentimentRequest
331
+
332
+ # Converts hash and nil to an options object
333
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
334
+
335
+ # Customize the options with defaults
336
+ call_metadata = @config.rpcs.analyze_entity_sentiment.metadata.to_h
337
+
338
+ # Set x-goog-api-client and x-goog-user-project headers
339
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
340
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
341
+ gapic_version: ::Google::Cloud::Language::V1::VERSION,
342
+ transports_version_send: [:rest]
343
+
344
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
345
+
346
+ options.apply_defaults timeout: @config.rpcs.analyze_entity_sentiment.timeout,
347
+ metadata: call_metadata,
348
+ retry_policy: @config.rpcs.analyze_entity_sentiment.retry_policy
349
+
350
+ options.apply_defaults timeout: @config.timeout,
351
+ metadata: @config.metadata,
352
+ retry_policy: @config.retry_policy
353
+
354
+ @language_service_stub.analyze_entity_sentiment request, options do |result, operation|
355
+ yield result, operation if block_given?
356
+ return result
357
+ end
358
+ rescue ::Gapic::Rest::Error => e
359
+ raise ::Google::Cloud::Error.from_error(e)
360
+ end
361
+
362
+ ##
363
+ # Analyzes the syntax of the text and provides sentence boundaries and
364
+ # tokenization along with part of speech tags, dependency trees, and other
365
+ # properties.
366
+ #
367
+ # @overload analyze_syntax(request, options = nil)
368
+ # Pass arguments to `analyze_syntax` via a request object, either of type
369
+ # {::Google::Cloud::Language::V1::AnalyzeSyntaxRequest} or an equivalent Hash.
370
+ #
371
+ # @param request [::Google::Cloud::Language::V1::AnalyzeSyntaxRequest, ::Hash]
372
+ # A request object representing the call parameters. Required. To specify no
373
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
374
+ # @param options [::Gapic::CallOptions, ::Hash]
375
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
376
+ #
377
+ # @overload analyze_syntax(document: nil, encoding_type: nil)
378
+ # Pass arguments to `analyze_syntax` via keyword arguments. Note that at
379
+ # least one keyword argument is required. To specify no parameters, or to keep all
380
+ # the default parameter values, pass an empty Hash as a request object (see above).
381
+ #
382
+ # @param document [::Google::Cloud::Language::V1::Document, ::Hash]
383
+ # Required. Input document.
384
+ # @param encoding_type [::Google::Cloud::Language::V1::EncodingType]
385
+ # The encoding type used by the API to calculate offsets.
386
+ # @yield [result, operation] Access the result along with the TransportOperation object
387
+ # @yieldparam result [::Google::Cloud::Language::V1::AnalyzeSyntaxResponse]
388
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
389
+ #
390
+ # @return [::Google::Cloud::Language::V1::AnalyzeSyntaxResponse]
391
+ #
392
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
393
+ def analyze_syntax request, options = nil
394
+ raise ::ArgumentError, "request must be provided" if request.nil?
395
+
396
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1::AnalyzeSyntaxRequest
397
+
398
+ # Converts hash and nil to an options object
399
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
400
+
401
+ # Customize the options with defaults
402
+ call_metadata = @config.rpcs.analyze_syntax.metadata.to_h
403
+
404
+ # Set x-goog-api-client and x-goog-user-project headers
405
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
406
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
407
+ gapic_version: ::Google::Cloud::Language::V1::VERSION,
408
+ transports_version_send: [:rest]
409
+
410
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
411
+
412
+ options.apply_defaults timeout: @config.rpcs.analyze_syntax.timeout,
413
+ metadata: call_metadata,
414
+ retry_policy: @config.rpcs.analyze_syntax.retry_policy
415
+
416
+ options.apply_defaults timeout: @config.timeout,
417
+ metadata: @config.metadata,
418
+ retry_policy: @config.retry_policy
419
+
420
+ @language_service_stub.analyze_syntax request, options do |result, operation|
421
+ yield result, operation if block_given?
422
+ return result
423
+ end
424
+ rescue ::Gapic::Rest::Error => e
425
+ raise ::Google::Cloud::Error.from_error(e)
426
+ end
427
+
428
+ ##
429
+ # Classifies a document into categories.
430
+ #
431
+ # @overload classify_text(request, options = nil)
432
+ # Pass arguments to `classify_text` via a request object, either of type
433
+ # {::Google::Cloud::Language::V1::ClassifyTextRequest} or an equivalent Hash.
434
+ #
435
+ # @param request [::Google::Cloud::Language::V1::ClassifyTextRequest, ::Hash]
436
+ # A request object representing the call parameters. Required. To specify no
437
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
438
+ # @param options [::Gapic::CallOptions, ::Hash]
439
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
440
+ #
441
+ # @overload classify_text(document: nil, classification_model_options: nil)
442
+ # Pass arguments to `classify_text` via keyword arguments. Note that at
443
+ # least one keyword argument is required. To specify no parameters, or to keep all
444
+ # the default parameter values, pass an empty Hash as a request object (see above).
445
+ #
446
+ # @param document [::Google::Cloud::Language::V1::Document, ::Hash]
447
+ # Required. Input document.
448
+ # @param classification_model_options [::Google::Cloud::Language::V1::ClassificationModelOptions, ::Hash]
449
+ # Model options to use for classification. Defaults to v1 options if not
450
+ # specified.
451
+ # @yield [result, operation] Access the result along with the TransportOperation object
452
+ # @yieldparam result [::Google::Cloud::Language::V1::ClassifyTextResponse]
453
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
454
+ #
455
+ # @return [::Google::Cloud::Language::V1::ClassifyTextResponse]
456
+ #
457
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
458
+ def classify_text request, options = nil
459
+ raise ::ArgumentError, "request must be provided" if request.nil?
460
+
461
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1::ClassifyTextRequest
462
+
463
+ # Converts hash and nil to an options object
464
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
465
+
466
+ # Customize the options with defaults
467
+ call_metadata = @config.rpcs.classify_text.metadata.to_h
468
+
469
+ # Set x-goog-api-client and x-goog-user-project headers
470
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
471
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
472
+ gapic_version: ::Google::Cloud::Language::V1::VERSION,
473
+ transports_version_send: [:rest]
474
+
475
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
476
+
477
+ options.apply_defaults timeout: @config.rpcs.classify_text.timeout,
478
+ metadata: call_metadata,
479
+ retry_policy: @config.rpcs.classify_text.retry_policy
480
+
481
+ options.apply_defaults timeout: @config.timeout,
482
+ metadata: @config.metadata,
483
+ retry_policy: @config.retry_policy
484
+
485
+ @language_service_stub.classify_text request, options do |result, operation|
486
+ yield result, operation if block_given?
487
+ return result
488
+ end
489
+ rescue ::Gapic::Rest::Error => e
490
+ raise ::Google::Cloud::Error.from_error(e)
491
+ end
492
+
493
+ ##
494
+ # A convenience method that provides all the features that analyzeSentiment,
495
+ # analyzeEntities, and analyzeSyntax provide in one call.
496
+ #
497
+ # @overload annotate_text(request, options = nil)
498
+ # Pass arguments to `annotate_text` via a request object, either of type
499
+ # {::Google::Cloud::Language::V1::AnnotateTextRequest} or an equivalent Hash.
500
+ #
501
+ # @param request [::Google::Cloud::Language::V1::AnnotateTextRequest, ::Hash]
502
+ # A request object representing the call parameters. Required. To specify no
503
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
504
+ # @param options [::Gapic::CallOptions, ::Hash]
505
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
506
+ #
507
+ # @overload annotate_text(document: nil, features: nil, encoding_type: nil)
508
+ # Pass arguments to `annotate_text` via keyword arguments. Note that at
509
+ # least one keyword argument is required. To specify no parameters, or to keep all
510
+ # the default parameter values, pass an empty Hash as a request object (see above).
511
+ #
512
+ # @param document [::Google::Cloud::Language::V1::Document, ::Hash]
513
+ # Required. Input document.
514
+ # @param features [::Google::Cloud::Language::V1::AnnotateTextRequest::Features, ::Hash]
515
+ # Required. The enabled features.
516
+ # @param encoding_type [::Google::Cloud::Language::V1::EncodingType]
517
+ # The encoding type used by the API to calculate offsets.
518
+ # @yield [result, operation] Access the result along with the TransportOperation object
519
+ # @yieldparam result [::Google::Cloud::Language::V1::AnnotateTextResponse]
520
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
521
+ #
522
+ # @return [::Google::Cloud::Language::V1::AnnotateTextResponse]
523
+ #
524
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
525
+ def annotate_text request, options = nil
526
+ raise ::ArgumentError, "request must be provided" if request.nil?
527
+
528
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Language::V1::AnnotateTextRequest
529
+
530
+ # Converts hash and nil to an options object
531
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
532
+
533
+ # Customize the options with defaults
534
+ call_metadata = @config.rpcs.annotate_text.metadata.to_h
535
+
536
+ # Set x-goog-api-client and x-goog-user-project headers
537
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
538
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
539
+ gapic_version: ::Google::Cloud::Language::V1::VERSION,
540
+ transports_version_send: [:rest]
541
+
542
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
543
+
544
+ options.apply_defaults timeout: @config.rpcs.annotate_text.timeout,
545
+ metadata: call_metadata,
546
+ retry_policy: @config.rpcs.annotate_text.retry_policy
547
+
548
+ options.apply_defaults timeout: @config.timeout,
549
+ metadata: @config.metadata,
550
+ retry_policy: @config.retry_policy
551
+
552
+ @language_service_stub.annotate_text request, options do |result, operation|
553
+ yield result, operation if block_given?
554
+ return result
555
+ end
556
+ rescue ::Gapic::Rest::Error => e
557
+ raise ::Google::Cloud::Error.from_error(e)
558
+ end
559
+
560
+ ##
561
+ # Configuration class for the LanguageService REST API.
562
+ #
563
+ # This class represents the configuration for LanguageService REST,
564
+ # providing control over timeouts, retry behavior, logging, transport
565
+ # parameters, and other low-level controls. Certain parameters can also be
566
+ # applied individually to specific RPCs. See
567
+ # {::Google::Cloud::Language::V1::LanguageService::Rest::Client::Configuration::Rpcs}
568
+ # for a list of RPCs that can be configured independently.
569
+ #
570
+ # Configuration can be applied globally to all clients, or to a single client
571
+ # on construction.
572
+ #
573
+ # @example
574
+ #
575
+ # # Modify the global config, setting the timeout for
576
+ # # analyze_sentiment to 20 seconds,
577
+ # # and all remaining timeouts to 10 seconds.
578
+ # ::Google::Cloud::Language::V1::LanguageService::Rest::Client.configure do |config|
579
+ # config.timeout = 10.0
580
+ # config.rpcs.analyze_sentiment.timeout = 20.0
581
+ # end
582
+ #
583
+ # # Apply the above configuration only to a new client.
584
+ # client = ::Google::Cloud::Language::V1::LanguageService::Rest::Client.new do |config|
585
+ # config.timeout = 10.0
586
+ # config.rpcs.analyze_sentiment.timeout = 20.0
587
+ # end
588
+ #
589
+ # @!attribute [rw] endpoint
590
+ # The hostname or hostname:port of the service endpoint.
591
+ # Defaults to `"language.googleapis.com"`.
592
+ # @return [::String]
593
+ # @!attribute [rw] credentials
594
+ # Credentials to send with calls. You may provide any of the following types:
595
+ # * (`String`) The path to a service account key file in JSON format
596
+ # * (`Hash`) A service account key as a Hash
597
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
598
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
599
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
600
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
601
+ # * (`nil`) indicating no credentials
602
+ # @return [::Object]
603
+ # @!attribute [rw] scope
604
+ # The OAuth scopes
605
+ # @return [::Array<::String>]
606
+ # @!attribute [rw] lib_name
607
+ # The library name as recorded in instrumentation and logging
608
+ # @return [::String]
609
+ # @!attribute [rw] lib_version
610
+ # The library version as recorded in instrumentation and logging
611
+ # @return [::String]
612
+ # @!attribute [rw] timeout
613
+ # The call timeout in seconds.
614
+ # @return [::Numeric]
615
+ # @!attribute [rw] metadata
616
+ # Additional headers to be sent with the call.
617
+ # @return [::Hash{::Symbol=>::String}]
618
+ # @!attribute [rw] retry_policy
619
+ # The retry policy. The value is a hash with the following keys:
620
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
621
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
622
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
623
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
624
+ # trigger a retry.
625
+ # @return [::Hash]
626
+ # @!attribute [rw] quota_project
627
+ # A separate project against which to charge quota.
628
+ # @return [::String]
629
+ #
630
+ class Configuration
631
+ extend ::Gapic::Config
632
+
633
+ config_attr :endpoint, "language.googleapis.com", ::String
634
+ config_attr :credentials, nil do |value|
635
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
636
+ allowed.any? { |klass| klass === value }
637
+ end
638
+ config_attr :scope, nil, ::String, ::Array, nil
639
+ config_attr :lib_name, nil, ::String, nil
640
+ config_attr :lib_version, nil, ::String, nil
641
+ config_attr :timeout, nil, ::Numeric, nil
642
+ config_attr :metadata, nil, ::Hash, nil
643
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
644
+ config_attr :quota_project, nil, ::String, nil
645
+
646
+ # @private
647
+ def initialize parent_config = nil
648
+ @parent_config = parent_config unless parent_config.nil?
649
+
650
+ yield self if block_given?
651
+ end
652
+
653
+ ##
654
+ # Configurations for individual RPCs
655
+ # @return [Rpcs]
656
+ #
657
+ def rpcs
658
+ @rpcs ||= begin
659
+ parent_rpcs = nil
660
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
661
+ Rpcs.new parent_rpcs
662
+ end
663
+ end
664
+
665
+ ##
666
+ # Configuration RPC class for the LanguageService API.
667
+ #
668
+ # Includes fields providing the configuration for each RPC in this service.
669
+ # Each configuration object is of type `Gapic::Config::Method` and includes
670
+ # the following configuration fields:
671
+ #
672
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
673
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
674
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
675
+ # include the following keys:
676
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
677
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
678
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
679
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
680
+ # trigger a retry.
681
+ #
682
+ class Rpcs
683
+ ##
684
+ # RPC-specific configuration for `analyze_sentiment`
685
+ # @return [::Gapic::Config::Method]
686
+ #
687
+ attr_reader :analyze_sentiment
688
+ ##
689
+ # RPC-specific configuration for `analyze_entities`
690
+ # @return [::Gapic::Config::Method]
691
+ #
692
+ attr_reader :analyze_entities
693
+ ##
694
+ # RPC-specific configuration for `analyze_entity_sentiment`
695
+ # @return [::Gapic::Config::Method]
696
+ #
697
+ attr_reader :analyze_entity_sentiment
698
+ ##
699
+ # RPC-specific configuration for `analyze_syntax`
700
+ # @return [::Gapic::Config::Method]
701
+ #
702
+ attr_reader :analyze_syntax
703
+ ##
704
+ # RPC-specific configuration for `classify_text`
705
+ # @return [::Gapic::Config::Method]
706
+ #
707
+ attr_reader :classify_text
708
+ ##
709
+ # RPC-specific configuration for `annotate_text`
710
+ # @return [::Gapic::Config::Method]
711
+ #
712
+ attr_reader :annotate_text
713
+
714
+ # @private
715
+ def initialize parent_rpcs = nil
716
+ analyze_sentiment_config = parent_rpcs.analyze_sentiment if parent_rpcs.respond_to? :analyze_sentiment
717
+ @analyze_sentiment = ::Gapic::Config::Method.new analyze_sentiment_config
718
+ analyze_entities_config = parent_rpcs.analyze_entities if parent_rpcs.respond_to? :analyze_entities
719
+ @analyze_entities = ::Gapic::Config::Method.new analyze_entities_config
720
+ analyze_entity_sentiment_config = parent_rpcs.analyze_entity_sentiment if parent_rpcs.respond_to? :analyze_entity_sentiment
721
+ @analyze_entity_sentiment = ::Gapic::Config::Method.new analyze_entity_sentiment_config
722
+ analyze_syntax_config = parent_rpcs.analyze_syntax if parent_rpcs.respond_to? :analyze_syntax
723
+ @analyze_syntax = ::Gapic::Config::Method.new analyze_syntax_config
724
+ classify_text_config = parent_rpcs.classify_text if parent_rpcs.respond_to? :classify_text
725
+ @classify_text = ::Gapic::Config::Method.new classify_text_config
726
+ annotate_text_config = parent_rpcs.annotate_text if parent_rpcs.respond_to? :annotate_text
727
+ @annotate_text = ::Gapic::Config::Method.new annotate_text_config
728
+
729
+ yield self if block_given?
730
+ end
731
+ end
732
+ end
733
+ end
734
+ end
735
+ end
736
+ end
737
+ end
738
+ end
739
+ end