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