google-cloud-language 0.36.0 → 1.0.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/v1/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/v1/language_service_pb"
29
- require "google/cloud/language/v1/credentials"
30
- require "google/cloud/language/version"
31
-
32
- module Google
33
- module Cloud
34
- module Language
35
- module V1
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::V1::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-language",
60
- "https://www.googleapis.com/auth/cloud-platform"
61
- ].freeze
62
-
63
-
64
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
65
- # Provides the means for authenticating requests made by the client. This parameter can
66
- # be many types.
67
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
68
- # authenticating requests made by this client.
69
- # A `String` will be treated as the path to the keyfile to be used for the construction of
70
- # credentials for this client.
71
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
72
- # credentials for this client.
73
- # A `GRPC::Core::Channel` will be used to make calls through.
74
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
75
- # should already be composed with a `GRPC::Core::CallCredentials` object.
76
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
77
- # metadata for requests, generally, to give OAuth credentials.
78
- # @param scopes [Array<String>]
79
- # The OAuth scopes for this service. This parameter is ignored if
80
- # an updater_proc is supplied.
81
- # @param client_config [Hash]
82
- # A Hash for call options for each method. See
83
- # Google::Gax#construct_settings for the structure of
84
- # this data. Falls back to the default config if not specified
85
- # or the specified config is missing data points.
86
- # @param timeout [Numeric]
87
- # The default timeout, in seconds, for calls made through this client.
88
- # @param metadata [Hash]
89
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
90
- # @param service_address [String]
91
- # Override for the service hostname, or `nil` to leave as the default.
92
- # @param service_port [Integer]
93
- # Override for the service port, or `nil` to leave as the default.
94
- # @param exception_transformer [Proc]
95
- # An optional proc that intercepts any exceptions raised during an API call to inject
96
- # custom error handling.
97
- def initialize \
98
- credentials: nil,
99
- scopes: ALL_SCOPES,
100
- client_config: {},
101
- timeout: DEFAULT_TIMEOUT,
102
- metadata: nil,
103
- service_address: nil,
104
- service_port: nil,
105
- exception_transformer: nil,
106
- lib_name: nil,
107
- lib_version: ""
108
- # These require statements are intentionally placed here to initialize
109
- # the gRPC module only when it's required.
110
- # See https://github.com/googleapis/toolkit/issues/446
111
- require "google/gax/grpc"
112
- require "google/cloud/language/v1/language_service_services_pb"
113
-
114
- credentials ||= Google::Cloud::Language::V1::Credentials.default
115
-
116
- if credentials.is_a?(String) || credentials.is_a?(Hash)
117
- updater_proc = Google::Cloud::Language::V1::Credentials.new(credentials).updater_proc
118
- end
119
- if credentials.is_a?(GRPC::Core::Channel)
120
- channel = credentials
121
- end
122
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
123
- chan_creds = credentials
124
- end
125
- if credentials.is_a?(Proc)
126
- updater_proc = credentials
127
- end
128
- if credentials.is_a?(Google::Auth::Credentials)
129
- updater_proc = credentials.updater_proc
130
- end
131
-
132
- package_version = Google::Cloud::Language::VERSION
133
-
134
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
135
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
136
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
137
- google_api_client << " grpc/#{GRPC::VERSION}"
138
- google_api_client.freeze
139
-
140
- headers = { :"x-goog-api-client" => google_api_client }
141
- if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
142
- headers[:"x-goog-user-project"] = credentials.quota_project_id
143
- end
144
- headers.merge!(metadata) unless metadata.nil?
145
- client_config_file = Pathname.new(__dir__).join(
146
- "language_service_client_config.json"
147
- )
148
- defaults = client_config_file.open do |f|
149
- Google::Gax.construct_settings(
150
- "google.cloud.language.v1.LanguageService",
151
- JSON.parse(f.read),
152
- client_config,
153
- Google::Gax::Grpc::STATUS_CODE_NAMES,
154
- timeout,
155
- errors: Google::Gax::Grpc::API_ERRORS,
156
- metadata: headers
157
- )
158
- end
159
-
160
- # Allow overriding the service path/port in subclasses.
161
- service_path = service_address || self.class::SERVICE_ADDRESS
162
- port = service_port || self.class::DEFAULT_SERVICE_PORT
163
- interceptors = self.class::GRPC_INTERCEPTORS
164
- @language_service_stub = Google::Gax::Grpc.create_stub(
165
- service_path,
166
- port,
167
- chan_creds: chan_creds,
168
- channel: channel,
169
- updater_proc: updater_proc,
170
- scopes: scopes,
171
- interceptors: interceptors,
172
- &Google::Cloud::Language::V1::LanguageService::Stub.method(:new)
173
- )
174
-
175
- @analyze_sentiment = Google::Gax.create_api_call(
176
- @language_service_stub.method(:analyze_sentiment),
177
- defaults["analyze_sentiment"],
178
- exception_transformer: exception_transformer
179
- )
180
- @analyze_entities = Google::Gax.create_api_call(
181
- @language_service_stub.method(:analyze_entities),
182
- defaults["analyze_entities"],
183
- exception_transformer: exception_transformer
184
- )
185
- @analyze_entity_sentiment = Google::Gax.create_api_call(
186
- @language_service_stub.method(:analyze_entity_sentiment),
187
- defaults["analyze_entity_sentiment"],
188
- exception_transformer: exception_transformer
189
- )
190
- @analyze_syntax = Google::Gax.create_api_call(
191
- @language_service_stub.method(:analyze_syntax),
192
- defaults["analyze_syntax"],
193
- exception_transformer: exception_transformer
194
- )
195
- @classify_text = Google::Gax.create_api_call(
196
- @language_service_stub.method(:classify_text),
197
- defaults["classify_text"],
198
- exception_transformer: exception_transformer
199
- )
200
- @annotate_text = Google::Gax.create_api_call(
201
- @language_service_stub.method(:annotate_text),
202
- defaults["annotate_text"],
203
- exception_transformer: exception_transformer
204
- )
205
- end
206
-
207
- # Service calls
208
-
209
- # Analyzes the sentiment of the provided text.
210
- #
211
- # @param document [Google::Cloud::Language::V1::Document | Hash]
212
- # Input document.
213
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
214
- # can also be provided.
215
- # @param encoding_type [Google::Cloud::Language::V1::EncodingType]
216
- # The encoding type used by the API to calculate sentence offsets.
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::V1::AnalyzeSentimentResponse]
222
- # @yieldparam operation [GRPC::ActiveCall::Operation]
223
- # @return [Google::Cloud::Language::V1::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: :v1)
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::V1::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::V1::Document | Hash]
252
- # Input document.
253
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
254
- # can also be provided.
255
- # @param encoding_type [Google::Cloud::Language::V1::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::V1::AnalyzeEntitiesResponse]
262
- # @yieldparam operation [GRPC::ActiveCall::Operation]
263
- # @return [Google::Cloud::Language::V1::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: :v1)
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::V1::AnalyzeEntitiesRequest)
284
- @analyze_entities.call(req, options, &block)
285
- end
286
-
287
- # Finds entities, similar to {Google::Cloud::Language::V1::LanguageService::AnalyzeEntities AnalyzeEntities} in the text and analyzes
288
- # sentiment associated with each entity and its mentions.
289
- #
290
- # @param document [Google::Cloud::Language::V1::Document | Hash]
291
- # Input document.
292
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
293
- # can also be provided.
294
- # @param encoding_type [Google::Cloud::Language::V1::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::V1::AnalyzeEntitySentimentResponse]
301
- # @yieldparam operation [GRPC::ActiveCall::Operation]
302
- # @return [Google::Cloud::Language::V1::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: :v1)
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::V1::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::V1::Document | Hash]
331
- # Input document.
332
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
333
- # can also be provided.
334
- # @param encoding_type [Google::Cloud::Language::V1::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::V1::AnalyzeSyntaxResponse]
341
- # @yieldparam operation [GRPC::ActiveCall::Operation]
342
- # @return [Google::Cloud::Language::V1::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: :v1)
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::V1::AnalyzeSyntaxRequest)
363
- @analyze_syntax.call(req, options, &block)
364
- end
365
-
366
- # Classifies a document into categories.
367
- #
368
- # @param document [Google::Cloud::Language::V1::Document | Hash]
369
- # Input document.
370
- # A hash of the same form as `Google::Cloud::Language::V1::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::V1::ClassifyTextResponse]
377
- # @yieldparam operation [GRPC::ActiveCall::Operation]
378
- # @return [Google::Cloud::Language::V1::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: :v1)
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::V1::ClassifyTextRequest)
397
- @classify_text.call(req, options, &block)
398
- end
399
-
400
- # A convenience method that provides all the features that analyzeSentiment,
401
- # analyzeEntities, and analyzeSyntax provide in one call.
402
- #
403
- # @param document [Google::Cloud::Language::V1::Document | Hash]
404
- # Input document.
405
- # A hash of the same form as `Google::Cloud::Language::V1::Document`
406
- # can also be provided.
407
- # @param features [Google::Cloud::Language::V1::AnnotateTextRequest::Features | Hash]
408
- # The enabled features.
409
- # A hash of the same form as `Google::Cloud::Language::V1::AnnotateTextRequest::Features`
410
- # can also be provided.
411
- # @param encoding_type [Google::Cloud::Language::V1::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::V1::AnnotateTextResponse]
418
- # @yieldparam operation [GRPC::ActiveCall::Operation]
419
- # @return [Google::Cloud::Language::V1::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: :v1)
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::V1::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.v1.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": 20000,
17
- "rpc_timeout_multiplier": 1.0,
18
- "max_rpc_timeout_millis": 20000,
19
- "total_timeout_millis": 600000
20
- }
21
- },
22
- "methods": {
23
- "AnalyzeSentiment": {
24
- "timeout_millis": 60000,
25
- "retry_codes_name": "idempotent",
26
- "retry_params_name": "default"
27
- },
28
- "AnalyzeEntities": {
29
- "timeout_millis": 60000,
30
- "retry_codes_name": "idempotent",
31
- "retry_params_name": "default"
32
- },
33
- "AnalyzeEntitySentiment": {
34
- "timeout_millis": 60000,
35
- "retry_codes_name": "idempotent",
36
- "retry_params_name": "default"
37
- },
38
- "AnalyzeSyntax": {
39
- "timeout_millis": 60000,
40
- "retry_codes_name": "idempotent",
41
- "retry_params_name": "default"
42
- },
43
- "ClassifyText": {
44
- "timeout_millis": 60000,
45
- "retry_codes_name": "idempotent",
46
- "retry_params_name": "default"
47
- },
48
- "AnnotateText": {
49
- "timeout_millis": 60000,
50
- "retry_codes_name": "idempotent",
51
- "retry_params_name": "default"
52
- }
53
- }
54
- }
55
- }
56
- }