google-cloud-language 0.33.0 → 1.2.3

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.
@@ -1,450 +0,0 @@
1
- # Copyright 2019 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
- headers.merge!(metadata) unless metadata.nil?
141
- client_config_file = Pathname.new(__dir__).join(
142
- "language_service_client_config.json"
143
- )
144
- defaults = client_config_file.open do |f|
145
- Google::Gax.construct_settings(
146
- "google.cloud.language.v1beta2.LanguageService",
147
- JSON.parse(f.read),
148
- client_config,
149
- Google::Gax::Grpc::STATUS_CODE_NAMES,
150
- timeout,
151
- errors: Google::Gax::Grpc::API_ERRORS,
152
- metadata: headers
153
- )
154
- end
155
-
156
- # Allow overriding the service path/port in subclasses.
157
- service_path = service_address || self.class::SERVICE_ADDRESS
158
- port = service_port || self.class::DEFAULT_SERVICE_PORT
159
- interceptors = self.class::GRPC_INTERCEPTORS
160
- @language_service_stub = Google::Gax::Grpc.create_stub(
161
- service_path,
162
- port,
163
- chan_creds: chan_creds,
164
- channel: channel,
165
- updater_proc: updater_proc,
166
- scopes: scopes,
167
- interceptors: interceptors,
168
- &Google::Cloud::Language::V1beta2::LanguageService::Stub.method(:new)
169
- )
170
-
171
- @analyze_sentiment = Google::Gax.create_api_call(
172
- @language_service_stub.method(:analyze_sentiment),
173
- defaults["analyze_sentiment"],
174
- exception_transformer: exception_transformer
175
- )
176
- @analyze_entities = Google::Gax.create_api_call(
177
- @language_service_stub.method(:analyze_entities),
178
- defaults["analyze_entities"],
179
- exception_transformer: exception_transformer
180
- )
181
- @analyze_entity_sentiment = Google::Gax.create_api_call(
182
- @language_service_stub.method(:analyze_entity_sentiment),
183
- defaults["analyze_entity_sentiment"],
184
- exception_transformer: exception_transformer
185
- )
186
- @analyze_syntax = Google::Gax.create_api_call(
187
- @language_service_stub.method(:analyze_syntax),
188
- defaults["analyze_syntax"],
189
- exception_transformer: exception_transformer
190
- )
191
- @classify_text = Google::Gax.create_api_call(
192
- @language_service_stub.method(:classify_text),
193
- defaults["classify_text"],
194
- exception_transformer: exception_transformer
195
- )
196
- @annotate_text = Google::Gax.create_api_call(
197
- @language_service_stub.method(:annotate_text),
198
- defaults["annotate_text"],
199
- exception_transformer: exception_transformer
200
- )
201
- end
202
-
203
- # Service calls
204
-
205
- # Analyzes the sentiment of the provided text.
206
- #
207
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
208
- # Input document.
209
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
210
- # can also be provided.
211
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
212
- # The encoding type used by the API to calculate sentence offsets for the
213
- # sentence sentiment.
214
- # @param options [Google::Gax::CallOptions]
215
- # Overrides the default settings for this call, e.g, timeout,
216
- # retries, etc.
217
- # @yield [result, operation] Access the result along with the RPC operation
218
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnalyzeSentimentResponse]
219
- # @yieldparam operation [GRPC::ActiveCall::Operation]
220
- # @return [Google::Cloud::Language::V1beta2::AnalyzeSentimentResponse]
221
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
222
- # @example
223
- # require "google/cloud/language"
224
- #
225
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
226
- #
227
- # # TODO: Initialize `document`:
228
- # document = {}
229
- # response = language_client.analyze_sentiment(document)
230
-
231
- def analyze_sentiment \
232
- document,
233
- encoding_type: nil,
234
- options: nil,
235
- &block
236
- req = {
237
- document: document,
238
- encoding_type: encoding_type
239
- }.delete_if { |_, v| v.nil? }
240
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnalyzeSentimentRequest)
241
- @analyze_sentiment.call(req, options, &block)
242
- end
243
-
244
- # Finds named entities (currently proper names and common nouns) in the text
245
- # along with entity types, salience, mentions for each entity, and
246
- # other properties.
247
- #
248
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
249
- # Input document.
250
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
251
- # can also be provided.
252
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
253
- # The encoding type used by the API to calculate offsets.
254
- # @param options [Google::Gax::CallOptions]
255
- # Overrides the default settings for this call, e.g, timeout,
256
- # retries, etc.
257
- # @yield [result, operation] Access the result along with the RPC operation
258
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnalyzeEntitiesResponse]
259
- # @yieldparam operation [GRPC::ActiveCall::Operation]
260
- # @return [Google::Cloud::Language::V1beta2::AnalyzeEntitiesResponse]
261
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
262
- # @example
263
- # require "google/cloud/language"
264
- #
265
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
266
- #
267
- # # TODO: Initialize `document`:
268
- # document = {}
269
- # response = language_client.analyze_entities(document)
270
-
271
- def analyze_entities \
272
- document,
273
- encoding_type: nil,
274
- options: nil,
275
- &block
276
- req = {
277
- document: document,
278
- encoding_type: encoding_type
279
- }.delete_if { |_, v| v.nil? }
280
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnalyzeEntitiesRequest)
281
- @analyze_entities.call(req, options, &block)
282
- end
283
-
284
- # Finds entities, similar to
285
- # {Google::Cloud::Language::V1beta2::LanguageService::AnalyzeEntities AnalyzeEntities}
286
- # in the text and analyzes sentiment associated with each entity and its
287
- # mentions.
288
- #
289
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
290
- # Input document.
291
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
292
- # can also be provided.
293
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
294
- # The encoding type used by the API to calculate offsets.
295
- # @param options [Google::Gax::CallOptions]
296
- # Overrides the default settings for this call, e.g, timeout,
297
- # retries, etc.
298
- # @yield [result, operation] Access the result along with the RPC operation
299
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentResponse]
300
- # @yieldparam operation [GRPC::ActiveCall::Operation]
301
- # @return [Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentResponse]
302
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
303
- # @example
304
- # require "google/cloud/language"
305
- #
306
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
307
- #
308
- # # TODO: Initialize `document`:
309
- # document = {}
310
- # response = language_client.analyze_entity_sentiment(document)
311
-
312
- def analyze_entity_sentiment \
313
- document,
314
- encoding_type: nil,
315
- options: nil,
316
- &block
317
- req = {
318
- document: document,
319
- encoding_type: encoding_type
320
- }.delete_if { |_, v| v.nil? }
321
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnalyzeEntitySentimentRequest)
322
- @analyze_entity_sentiment.call(req, options, &block)
323
- end
324
-
325
- # Analyzes the syntax of the text and provides sentence boundaries and
326
- # tokenization along with part of speech tags, dependency trees, and other
327
- # properties.
328
- #
329
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
330
- # Input document.
331
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
332
- # can also be provided.
333
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
334
- # The encoding type used by the API to calculate offsets.
335
- # @param options [Google::Gax::CallOptions]
336
- # Overrides the default settings for this call, e.g, timeout,
337
- # retries, etc.
338
- # @yield [result, operation] Access the result along with the RPC operation
339
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnalyzeSyntaxResponse]
340
- # @yieldparam operation [GRPC::ActiveCall::Operation]
341
- # @return [Google::Cloud::Language::V1beta2::AnalyzeSyntaxResponse]
342
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
343
- # @example
344
- # require "google/cloud/language"
345
- #
346
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
347
- #
348
- # # TODO: Initialize `document`:
349
- # document = {}
350
- # response = language_client.analyze_syntax(document)
351
-
352
- def analyze_syntax \
353
- document,
354
- encoding_type: nil,
355
- options: nil,
356
- &block
357
- req = {
358
- document: document,
359
- encoding_type: encoding_type
360
- }.delete_if { |_, v| v.nil? }
361
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnalyzeSyntaxRequest)
362
- @analyze_syntax.call(req, options, &block)
363
- end
364
-
365
- # Classifies a document into categories.
366
- #
367
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
368
- # Input document.
369
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
370
- # can also be provided.
371
- # @param options [Google::Gax::CallOptions]
372
- # Overrides the default settings for this call, e.g, timeout,
373
- # retries, etc.
374
- # @yield [result, operation] Access the result along with the RPC operation
375
- # @yieldparam result [Google::Cloud::Language::V1beta2::ClassifyTextResponse]
376
- # @yieldparam operation [GRPC::ActiveCall::Operation]
377
- # @return [Google::Cloud::Language::V1beta2::ClassifyTextResponse]
378
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
379
- # @example
380
- # require "google/cloud/language"
381
- #
382
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
383
- #
384
- # # TODO: Initialize `document`:
385
- # document = {}
386
- # response = language_client.classify_text(document)
387
-
388
- def classify_text \
389
- document,
390
- options: nil,
391
- &block
392
- req = {
393
- document: document
394
- }.delete_if { |_, v| v.nil? }
395
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::ClassifyTextRequest)
396
- @classify_text.call(req, options, &block)
397
- end
398
-
399
- # A convenience method that provides all syntax, sentiment, entity, and
400
- # classification features in one call.
401
- #
402
- # @param document [Google::Cloud::Language::V1beta2::Document | Hash]
403
- # Input document.
404
- # A hash of the same form as `Google::Cloud::Language::V1beta2::Document`
405
- # can also be provided.
406
- # @param features [Google::Cloud::Language::V1beta2::AnnotateTextRequest::Features | Hash]
407
- # The enabled features.
408
- # A hash of the same form as `Google::Cloud::Language::V1beta2::AnnotateTextRequest::Features`
409
- # can also be provided.
410
- # @param encoding_type [Google::Cloud::Language::V1beta2::EncodingType]
411
- # The encoding type used by the API to calculate offsets.
412
- # @param options [Google::Gax::CallOptions]
413
- # Overrides the default settings for this call, e.g, timeout,
414
- # retries, etc.
415
- # @yield [result, operation] Access the result along with the RPC operation
416
- # @yieldparam result [Google::Cloud::Language::V1beta2::AnnotateTextResponse]
417
- # @yieldparam operation [GRPC::ActiveCall::Operation]
418
- # @return [Google::Cloud::Language::V1beta2::AnnotateTextResponse]
419
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
420
- # @example
421
- # require "google/cloud/language"
422
- #
423
- # language_client = Google::Cloud::Language.new(version: :v1beta2)
424
- #
425
- # # TODO: Initialize `document`:
426
- # document = {}
427
- #
428
- # # TODO: Initialize `features`:
429
- # features = {}
430
- # response = language_client.annotate_text(document, features)
431
-
432
- def annotate_text \
433
- document,
434
- features,
435
- encoding_type: nil,
436
- options: nil,
437
- &block
438
- req = {
439
- document: document,
440
- features: features,
441
- encoding_type: encoding_type
442
- }.delete_if { |_, v| v.nil? }
443
- req = Google::Gax::to_proto(req, Google::Cloud::Language::V1beta2::AnnotateTextRequest)
444
- @annotate_text.call(req, options, &block)
445
- end
446
- end
447
- end
448
- end
449
- end
450
- 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
- }