google-cloud-language-v1beta2 0.1.0

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