google-cloud-language 0.36.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,451 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
-
28
- require "google/cloud/language/v1beta2/language_service_pb"
29
- require "google/cloud/language/v1beta2/credentials"
30
- require "google/cloud/language/version"
31
-
32
- module Google
33
- module Cloud
34
- module Language
35
- module V1beta2
36
- # Provides text analysis operations such as sentiment analysis and entity
37
- # recognition.
38
- #
39
- # @!attribute [r] language_service_stub
40
- # @return [Google::Cloud::Language::V1beta2::LanguageService::Stub]
41
- class LanguageServiceClient
42
- # @private
43
- attr_reader :language_service_stub
44
-
45
- # The default address of the service.
46
- SERVICE_ADDRESS = "language.googleapis.com".freeze
47
-
48
- # The default port of the service.
49
- DEFAULT_SERVICE_PORT = 443
50
-
51
- # The default set of gRPC interceptors.
52
- GRPC_INTERCEPTORS = []
53
-
54
- DEFAULT_TIMEOUT = 30
55
-
56
- # The scopes needed to make gRPC calls to all of the methods defined in
57
- # this service.
58
- ALL_SCOPES = [
59
- "https://www.googleapis.com/auth/cloud-platform"
60
- ].freeze
61
-
62
-
63
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
64
- # Provides the means for authenticating requests made by the client. This parameter can
65
- # be many types.
66
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
67
- # authenticating requests made by this client.
68
- # A `String` will be treated as the path to the keyfile to be used for the construction of
69
- # credentials for this client.
70
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
71
- # credentials for this client.
72
- # A `GRPC::Core::Channel` will be used to make calls through.
73
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
74
- # should already be composed with a `GRPC::Core::CallCredentials` object.
75
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
76
- # metadata for requests, generally, to give OAuth credentials.
77
- # @param scopes [Array<String>]
78
- # The OAuth scopes for this service. This parameter is ignored if
79
- # an updater_proc is supplied.
80
- # @param client_config [Hash]
81
- # A Hash for call options for each method. See
82
- # Google::Gax#construct_settings for the structure of
83
- # this data. Falls back to the default config if not specified
84
- # or the specified config is missing data points.
85
- # @param timeout [Numeric]
86
- # The default timeout, in seconds, for calls made through this client.
87
- # @param metadata [Hash]
88
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
89
- # @param service_address [String]
90
- # Override for the service hostname, or `nil` to leave as the default.
91
- # @param service_port [Integer]
92
- # Override for the service port, or `nil` to leave as the default.
93
- # @param exception_transformer [Proc]
94
- # An optional proc that intercepts any exceptions raised during an API call to inject
95
- # custom error handling.
96
- def initialize \
97
- credentials: nil,
98
- scopes: ALL_SCOPES,
99
- client_config: {},
100
- timeout: DEFAULT_TIMEOUT,
101
- metadata: nil,
102
- service_address: nil,
103
- service_port: nil,
104
- exception_transformer: nil,
105
- lib_name: nil,
106
- lib_version: ""
107
- # These require statements are intentionally placed here to initialize
108
- # the gRPC module only when it's required.
109
- # See https://github.com/googleapis/toolkit/issues/446
110
- require "google/gax/grpc"
111
- require "google/cloud/language/v1beta2/language_service_services_pb"
112
-
113
- credentials ||= Google::Cloud::Language::V1beta2::Credentials.default
114
-
115
- if credentials.is_a?(String) || credentials.is_a?(Hash)
116
- updater_proc = Google::Cloud::Language::V1beta2::Credentials.new(credentials).updater_proc
117
- end
118
- if credentials.is_a?(GRPC::Core::Channel)
119
- channel = credentials
120
- end
121
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
122
- chan_creds = credentials
123
- end
124
- if credentials.is_a?(Proc)
125
- updater_proc = credentials
126
- end
127
- if credentials.is_a?(Google::Auth::Credentials)
128
- updater_proc = credentials.updater_proc
129
- end
130
-
131
- package_version = Google::Cloud::Language::VERSION
132
-
133
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
134
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
135
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
136
- google_api_client << " grpc/#{GRPC::VERSION}"
137
- google_api_client.freeze
138
-
139
- headers = { :"x-goog-api-client" => google_api_client }
140
- if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
141
- headers[:"x-goog-user-project"] = credentials.quota_project_id
142
- end
143
- headers.merge!(metadata) unless metadata.nil?
144
- client_config_file = Pathname.new(__dir__).join(
145
- "language_service_client_config.json"
146
- )
147
- defaults = client_config_file.open do |f|
148
- Google::Gax.construct_settings(
149
- "google.cloud.language.v1beta2.LanguageService",
150
- JSON.parse(f.read),
151
- client_config,
152
- Google::Gax::Grpc::STATUS_CODE_NAMES,
153
- timeout,
154
- errors: Google::Gax::Grpc::API_ERRORS,
155
- metadata: headers
156
- )
157
- end
158
-
159
- # Allow overriding the service path/port in subclasses.
160
- service_path = service_address || self.class::SERVICE_ADDRESS
161
- port = service_port || self.class::DEFAULT_SERVICE_PORT
162
- interceptors = self.class::GRPC_INTERCEPTORS
163
- @language_service_stub = Google::Gax::Grpc.create_stub(
164
- service_path,
165
- port,
166
- chan_creds: chan_creds,
167
- channel: channel,
168
- updater_proc: updater_proc,
169
- scopes: scopes,
170
- interceptors: interceptors,
171
- &Google::Cloud::Language::V1beta2::LanguageService::Stub.method(:new)
172
- )
173
-
174
- @analyze_sentiment = Google::Gax.create_api_call(
175
- @language_service_stub.method(:analyze_sentiment),
176
- defaults["analyze_sentiment"],
177
- exception_transformer: exception_transformer
178
- )
179
- @analyze_entities = Google::Gax.create_api_call(
180
- @language_service_stub.method(:analyze_entities),
181
- defaults["analyze_entities"],
182
- exception_transformer: exception_transformer
183
- )
184
- @analyze_entity_sentiment = Google::Gax.create_api_call(
185
- @language_service_stub.method(:analyze_entity_sentiment),
186
- defaults["analyze_entity_sentiment"],
187
- exception_transformer: exception_transformer
188
- )
189
- @analyze_syntax = Google::Gax.create_api_call(
190
- @language_service_stub.method(:analyze_syntax),
191
- defaults["analyze_syntax"],
192
- exception_transformer: exception_transformer
193
- )
194
- @classify_text = Google::Gax.create_api_call(
195
- @language_service_stub.method(:classify_text),
196
- defaults["classify_text"],
197
- exception_transformer: exception_transformer
198
- )
199
- @annotate_text = Google::Gax.create_api_call(
200
- @language_service_stub.method(:annotate_text),
201
- defaults["annotate_text"],
202
- exception_transformer: exception_transformer
203
- )
204
- end
205
-
206
- # Service calls
207
-
208
- # Analyzes the sentiment of the provided text.
209
- #
210
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
211
- # Required. Input document.
212
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
213
- # can also be provided.
214
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
215
- # The encoding type used by the API to calculate sentence offsets for the
216
- # sentence sentiment.
217
- # @param options [Google::Gax::CallOptions]
218
- # Overrides the default settings for this call, e.g, timeout,
219
- # retries, etc.
220
- # @yield [result, operation] Access the result along with the RPC operation
221
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnalyzeSentimentResponse]
222
- # @yieldparam operation [GRPC::ActiveCall::Operation]
223
- # @return [Google::Cloud::Language::V1beta2::AnalyzeSentimentResponse]
224
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
225
- # @example
226
- # require "google/cloud/language"
227
- #
228
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
229
- #
230
- # # TODO: Initialize `document`:
231
- # document = {}
232
- # response = language_client.analyze_sentiment(document)
233
-
234
- def analyze_sentiment \
235
- document,
236
- encoding_type: nil,
237
- options: nil,
238
- &block
239
- req = {
240
- document: document,
241
- encoding_type: encoding_type
242
- }.delete_if { |_, v| v.nil? }
243
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnalyzeSentimentRequest)
244
- @analyze_sentiment.call(req, options, &block)
245
- end
246
-
247
- # Finds named entities (currently proper names and common nouns) in the text
248
- # along with entity types, salience, mentions for each entity, and
249
- # other properties.
250
- #
251
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
252
- # Required. Input document.
253
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
254
- # can also be provided.
255
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
256
- # The encoding type used by the API to calculate offsets.
257
- # @param options [Google::Gax::CallOptions]
258
- # Overrides the default settings for this call, e.g, timeout,
259
- # retries, etc.
260
- # @yield [result, operation] Access the result along with the RPC operation
261
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnalyzeEntitiesResponse]
262
- # @yieldparam operation [GRPC::ActiveCall::Operation]
263
- # @return [Google::Cloud::Language::V1beta2::AnalyzeEntitiesResponse]
264
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
265
- # @example
266
- # require "google/cloud/language"
267
- #
268
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
269
- #
270
- # # TODO: Initialize `document`:
271
- # document = {}
272
- # response = language_client.analyze_entities(document)
273
-
274
- def analyze_entities \
275
- document,
276
- encoding_type: nil,
277
- options: nil,
278
- &block
279
- req = {
280
- document: document,
281
- encoding_type: encoding_type
282
- }.delete_if { |_, v| v.nil? }
283
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnalyzeEntitiesRequest)
284
- @analyze_entities.call(req, options, &block)
285
- end
286
-
287
- # Finds entities, similar to {Google::Cloud::Language::V1beta2::LanguageService::AnalyzeEntities AnalyzeEntities} in the text and analyzes
288
- # sentiment associated with each entity and its mentions.
289
- #
290
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
291
- # Required. Input document.
292
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
293
- # can also be provided.
294
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
295
- # The encoding type used by the API to calculate offsets.
296
- # @param options [Google::Gax::CallOptions]
297
- # Overrides the default settings for this call, e.g, timeout,
298
- # retries, etc.
299
- # @yield [result, operation] Access the result along with the RPC operation
300
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentResponse]
301
- # @yieldparam operation [GRPC::ActiveCall::Operation]
302
- # @return [Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentResponse]
303
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
304
- # @example
305
- # require "google/cloud/language"
306
- #
307
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
308
- #
309
- # # TODO: Initialize `document`:
310
- # document = {}
311
- # response = language_client.analyze_entity_sentiment(document)
312
-
313
- def analyze_entity_sentiment \
314
- document,
315
- encoding_type: nil,
316
- options: nil,
317
- &block
318
- req = {
319
- document: document,
320
- encoding_type: encoding_type
321
- }.delete_if { |_, v| v.nil? }
322
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentRequest)
323
- @analyze_entity_sentiment.call(req, options, &block)
324
- end
325
-
326
- # Analyzes the syntax of the text and provides sentence boundaries and
327
- # tokenization along with part-of-speech tags, dependency trees, and other
328
- # properties.
329
- #
330
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
331
- # Required. Input document.
332
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
333
- # can also be provided.
334
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
335
- # The encoding type used by the API to calculate offsets.
336
- # @param options [Google::Gax::CallOptions]
337
- # Overrides the default settings for this call, e.g, timeout,
338
- # retries, etc.
339
- # @yield [result, operation] Access the result along with the RPC operation
340
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnalyzeSyntaxResponse]
341
- # @yieldparam operation [GRPC::ActiveCall::Operation]
342
- # @return [Google::Cloud::Language::V1beta2::AnalyzeSyntaxResponse]
343
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
344
- # @example
345
- # require "google/cloud/language"
346
- #
347
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
348
- #
349
- # # TODO: Initialize `document`:
350
- # document = {}
351
- # response = language_client.analyze_syntax(document)
352
-
353
- def analyze_syntax \
354
- document,
355
- encoding_type: nil,
356
- options: nil,
357
- &block
358
- req = {
359
- document: document,
360
- encoding_type: encoding_type
361
- }.delete_if { |_, v| v.nil? }
362
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnalyzeSyntaxRequest)
363
- @analyze_syntax.call(req, options, &block)
364
- end
365
-
366
- # Classifies a document into categories.
367
- #
368
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
369
- # Required. Input document.
370
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
371
- # can also be provided.
372
- # @param options [Google::Gax::CallOptions]
373
- # Overrides the default settings for this call, e.g, timeout,
374
- # retries, etc.
375
- # @yield [result, operation] Access the result along with the RPC operation
376
- # @yieldparam result [Google::Cloud::Language::V1beta2::ClassifyTextResponse]
377
- # @yieldparam operation [GRPC::ActiveCall::Operation]
378
- # @return [Google::Cloud::Language::V1beta2::ClassifyTextResponse]
379
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
380
- # @example
381
- # require "google/cloud/language"
382
- #
383
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
384
- #
385
- # # TODO: Initialize `document`:
386
- # document = {}
387
- # response = language_client.classify_text(document)
388
-
389
- def classify_text \
390
- document,
391
- options: nil,
392
- &block
393
- req = {
394
- document: document
395
- }.delete_if { |_, v| v.nil? }
396
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::ClassifyTextRequest)
397
- @classify_text.call(req, options, &block)
398
- end
399
-
400
- # A convenience method that provides all syntax, sentiment, entity, and
401
- # classification features in one call.
402
- #
403
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
404
- # Required. Input document.
405
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
406
- # can also be provided.
407
- # @param features [Google::Cloud::Language::V1beta2::AnnotateTextRequest::Features | Hash]
408
- # Required. The enabled features.
409
- # A hash of the same form as `Google::Cloud::Language::V1beta2::AnnotateTextRequest::Features`
410
- # can also be provided.
411
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
412
- # The encoding type used by the API to calculate offsets.
413
- # @param options [Google::Gax::CallOptions]
414
- # Overrides the default settings for this call, e.g, timeout,
415
- # retries, etc.
416
- # @yield [result, operation] Access the result along with the RPC operation
417
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnnotateTextResponse]
418
- # @yieldparam operation [GRPC::ActiveCall::Operation]
419
- # @return [Google::Cloud::Language::V1beta2::AnnotateTextResponse]
420
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
421
- # @example
422
- # require "google/cloud/language"
423
- #
424
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
425
- #
426
- # # TODO: Initialize `document`:
427
- # document = {}
428
- #
429
- # # TODO: Initialize `features`:
430
- # features = {}
431
- # response = language_client.annotate_text(document, features)
432
-
433
- def annotate_text \
434
- document,
435
- features,
436
- encoding_type: nil,
437
- options: nil,
438
- &block
439
- req = {
440
- document: document,
441
- features: features,
442
- encoding_type: encoding_type
443
- }.delete_if { |_, v| v.nil? }
444
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnnotateTextRequest)
445
- @annotate_text.call(req, options, &block)
446
- end
447
- end
448
- end
449
- end
450
- end
451
- end
@@ -1,56 +0,0 @@
1
- {
2
- "interfaces": {
3
- "google.cloud.language.v1beta2.LanguageService": {
4
- "retry_codes": {
5
- "idempotent": [
6
- "DEADLINE_EXCEEDED",
7
- "UNAVAILABLE"
8
- ],
9
- "non_idempotent": []
10
- },
11
- "retry_params": {
12
- "default": {
13
- "initial_retry_delay_millis": 100,
14
- "retry_delay_multiplier": 1.3,
15
- "max_retry_delay_millis": 60000,
16
- "initial_rpc_timeout_millis": 60000,
17
- "rpc_timeout_multiplier": 1.0,
18
- "max_rpc_timeout_millis": 60000,
19
- "total_timeout_millis": 600000
20
- }
21
- },
22
- "methods": {
23
- "AnalyzeSentiment": {
24
- "timeout_millis": 30000,
25
- "retry_codes_name": "idempotent",
26
- "retry_params_name": "default"
27
- },
28
- "AnalyzeEntities": {
29
- "timeout_millis": 30000,
30
- "retry_codes_name": "idempotent",
31
- "retry_params_name": "default"
32
- },
33
- "AnalyzeEntitySentiment": {
34
- "timeout_millis": 30000,
35
- "retry_codes_name": "idempotent",
36
- "retry_params_name": "default"
37
- },
38
- "AnalyzeSyntax": {
39
- "timeout_millis": 30000,
40
- "retry_codes_name": "idempotent",
41
- "retry_params_name": "default"
42
- },
43
- "ClassifyText": {
44
- "timeout_millis": 30000,
45
- "retry_codes_name": "idempotent",
46
- "retry_params_name": "default"
47
- },
48
- "AnnotateText": {
49
- "timeout_millis": 30000,
50
- "retry_codes_name": "idempotent",
51
- "retry_params_name": "default"
52
- }
53
- }
54
- }
55
- }
56
- }