gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
data/lib/gcloud/translate/api.rb
DELETED
@@ -1,241 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
-
# http://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
|
-
|
16
|
-
require "gcloud/translate/service"
|
17
|
-
require "gcloud/translate/translation"
|
18
|
-
require "gcloud/translate/detection"
|
19
|
-
require "gcloud/translate/language"
|
20
|
-
|
21
|
-
module Gcloud
|
22
|
-
module Translate
|
23
|
-
##
|
24
|
-
# # Api
|
25
|
-
#
|
26
|
-
# Represents top-level access to the Google Translate API. Each instance
|
27
|
-
# requires a public API access key. To create a key, follow the general
|
28
|
-
# instructions at [Identifying your application to
|
29
|
-
# Google](https://cloud.google.com/translate/v2/using_rest#auth), and the
|
30
|
-
# specific instructions for [Server
|
31
|
-
# keys](https://cloud.google.com/translate/v2/using_rest#creating-server-api-keys).
|
32
|
-
# See {Gcloud#translate}.
|
33
|
-
#
|
34
|
-
# @see https://cloud.google.com/translate/v2/getting_started Translate API
|
35
|
-
# Getting Started
|
36
|
-
#
|
37
|
-
# @example
|
38
|
-
# require "gcloud"
|
39
|
-
#
|
40
|
-
# gcloud = Gcloud.new
|
41
|
-
# translate = gcloud.translate
|
42
|
-
#
|
43
|
-
# translation = translate.translate "Hello world!", to: "la"
|
44
|
-
#
|
45
|
-
# puts translation #=> Salve mundi!
|
46
|
-
#
|
47
|
-
# translation.from #=> "en"
|
48
|
-
# translation.origin #=> "Hello world!"
|
49
|
-
# translation.to #=> "la"
|
50
|
-
# translation.text #=> "Salve mundi!"
|
51
|
-
#
|
52
|
-
class Api
|
53
|
-
##
|
54
|
-
# @private The Service object.
|
55
|
-
attr_accessor :service
|
56
|
-
|
57
|
-
##
|
58
|
-
# @private Creates a new Translate Api instance.
|
59
|
-
#
|
60
|
-
# See {Gcloud.translate}
|
61
|
-
def initialize service
|
62
|
-
@service = service
|
63
|
-
end
|
64
|
-
|
65
|
-
##
|
66
|
-
# Returns text translations from one language to another.
|
67
|
-
#
|
68
|
-
# @see https://cloud.google.com/translate/v2/using_rest#Translate
|
69
|
-
# Translate Text
|
70
|
-
#
|
71
|
-
# @param [String] text The text or texts to translate.
|
72
|
-
# @param [String] to The target language into which the text should be
|
73
|
-
# translated. This is required. The value must be an [ISO
|
74
|
-
# 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language
|
75
|
-
# code.
|
76
|
-
# @param [String] from The source language of the text or texts. This is
|
77
|
-
# an [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
78
|
-
# language code. This is optional.
|
79
|
-
# @param [String] format The format of the text. Possible values include
|
80
|
-
# `:text` and `:html`. This is optional. The Translate API default is
|
81
|
-
# `:html`.
|
82
|
-
# @param [String] cid The customization id for translate. This is
|
83
|
-
# optional.
|
84
|
-
#
|
85
|
-
# @return [Translation, Array<Translation>] A single {Translation} object
|
86
|
-
# if just one text was given, or an array of {Translation} objects if
|
87
|
-
# multiple texts were given.
|
88
|
-
#
|
89
|
-
# @example
|
90
|
-
# require "gcloud"
|
91
|
-
#
|
92
|
-
# gcloud = Gcloud.new
|
93
|
-
# translate = gcloud.translate
|
94
|
-
#
|
95
|
-
# translation = translate.translate "Hello world!", to: "la"
|
96
|
-
#
|
97
|
-
# puts translation #=> Salve mundi!
|
98
|
-
#
|
99
|
-
# translation.detected? #=> true
|
100
|
-
# translation.from #=> "en"
|
101
|
-
# translation.origin #=> "Hello world!"
|
102
|
-
# translation.to #=> "la"
|
103
|
-
# translation.text #=> "Salve mundi!"
|
104
|
-
#
|
105
|
-
# @example Setting the `from` language.
|
106
|
-
# require "gcloud"
|
107
|
-
#
|
108
|
-
# gcloud = Gcloud.new
|
109
|
-
# translate = gcloud.translate
|
110
|
-
#
|
111
|
-
# translation = translate.translate "Hello world!",
|
112
|
-
# from: :en, to: :la
|
113
|
-
# translation.detected? #=> false
|
114
|
-
# translation.text #=> "Salve mundi!"
|
115
|
-
#
|
116
|
-
# @example Retrieving multiple translations.
|
117
|
-
# require "gcloud"
|
118
|
-
#
|
119
|
-
# gcloud = Gcloud.new
|
120
|
-
# translate = gcloud.translate
|
121
|
-
#
|
122
|
-
# translations = translate.translate "Hello my friend.",
|
123
|
-
# "See you soon.",
|
124
|
-
# from: "en", to: "la"
|
125
|
-
# translations.count #=> 2
|
126
|
-
# translations[0].text #=> "Salve amice."
|
127
|
-
# translations[1].text #=> "Vide te mox."
|
128
|
-
#
|
129
|
-
# @example Preserving HTML tags.
|
130
|
-
# require "gcloud"
|
131
|
-
#
|
132
|
-
# gcloud = Gcloud.new
|
133
|
-
# translate = gcloud.translate
|
134
|
-
#
|
135
|
-
# translation = translate.translate "<strong>Hello</strong> world!",
|
136
|
-
# to: :la
|
137
|
-
# translation.text #=> "<strong>Salve</strong> mundi!"
|
138
|
-
#
|
139
|
-
def translate *text, to: nil, from: nil, format: nil, cid: nil
|
140
|
-
return nil if text.empty?
|
141
|
-
fail ArgumentError, "to is required" if to.nil?
|
142
|
-
to = to.to_s
|
143
|
-
from = from.to_s if from
|
144
|
-
format = format.to_s if format
|
145
|
-
text = Array(text).flatten
|
146
|
-
gapi = service.translate text, to: to, from: from,
|
147
|
-
format: format, cid: cid
|
148
|
-
Translation.from_gapi_list gapi, text, to, from
|
149
|
-
end
|
150
|
-
|
151
|
-
##
|
152
|
-
# Detect the most likely language or languages of a text or multiple
|
153
|
-
# texts.
|
154
|
-
#
|
155
|
-
# @see https://cloud.google.com/translate/v2/using_rest#detect-language
|
156
|
-
# Detect Language
|
157
|
-
#
|
158
|
-
# @param [String] text The text or texts upon which language detection
|
159
|
-
# should be performed.
|
160
|
-
#
|
161
|
-
# @return [Detection, Array<Detection>] A single {Detection} object if
|
162
|
-
# just one text was given, or an array of {Detection} objects if
|
163
|
-
# multiple texts were given.
|
164
|
-
#
|
165
|
-
# @example
|
166
|
-
# require "gcloud"
|
167
|
-
#
|
168
|
-
# gcloud = Gcloud.new
|
169
|
-
# translate = gcloud.translate
|
170
|
-
#
|
171
|
-
# detection = translate.detect "Hello world!"
|
172
|
-
# puts detection.language #=> en
|
173
|
-
# puts detection.confidence #=> 0.7100697
|
174
|
-
#
|
175
|
-
# @example Detecting multiple texts.
|
176
|
-
# require "gcloud"
|
177
|
-
#
|
178
|
-
# gcloud = Gcloud.new
|
179
|
-
# translate = gcloud.translate
|
180
|
-
#
|
181
|
-
# detections = translate.detect "Hello world!",
|
182
|
-
# "Bonjour le monde!"
|
183
|
-
# puts detections.count #=> 2
|
184
|
-
# puts detection.first.language #=> en
|
185
|
-
# puts detection.first.confidence #=> 0.7100697
|
186
|
-
# puts detection.last.language #=> fr
|
187
|
-
# puts detection.last.confidence #=> 0.40440267
|
188
|
-
#
|
189
|
-
def detect *text
|
190
|
-
return nil if text.empty?
|
191
|
-
text = Array(text).flatten
|
192
|
-
gapi = service.detect(text)
|
193
|
-
Detection.from_gapi gapi, text
|
194
|
-
end
|
195
|
-
|
196
|
-
##
|
197
|
-
# List the languages supported by the API. These are the languages to and
|
198
|
-
# from which text can be translated.
|
199
|
-
#
|
200
|
-
# @see https://cloud.google.com/translate/v2/using_rest#supported-languages
|
201
|
-
# Discover Supported Languages
|
202
|
-
#
|
203
|
-
# @param [String] language The language and collation in which the names
|
204
|
-
# of the languages are returned. If this is `nil` then no names are
|
205
|
-
# returned.
|
206
|
-
#
|
207
|
-
# @return [Array<Language>] An array of {Language} objects supported by
|
208
|
-
# the API.
|
209
|
-
#
|
210
|
-
# @example
|
211
|
-
# require "gcloud"
|
212
|
-
#
|
213
|
-
# gcloud = Gcloud.new
|
214
|
-
# translate = gcloud.translate
|
215
|
-
#
|
216
|
-
# languages = translate.languages
|
217
|
-
# languages.count #=> 104
|
218
|
-
#
|
219
|
-
# english = languages.detect { |l| l.code == "en" }
|
220
|
-
# english.name #=> nil
|
221
|
-
#
|
222
|
-
# @example Get all languages with their names in French.
|
223
|
-
# require "gcloud"
|
224
|
-
#
|
225
|
-
# gcloud = Gcloud.new
|
226
|
-
# translate = gcloud.translate
|
227
|
-
#
|
228
|
-
# languages = translate.languages "fr"
|
229
|
-
# languages.count #=> 104
|
230
|
-
#
|
231
|
-
# english = languages.detect { |l| l.code == "en" }
|
232
|
-
# english.name #=> "Anglais"
|
233
|
-
#
|
234
|
-
def languages language = nil
|
235
|
-
language = language.to_s if language
|
236
|
-
gapi = service.languages language
|
237
|
-
Array(gapi.languages).map { |g| Language.from_gapi g }
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
-
# http://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
|
-
|
16
|
-
module Gcloud
|
17
|
-
module Translate
|
18
|
-
##
|
19
|
-
# # Detection
|
20
|
-
#
|
21
|
-
# Represents a detect language query result. Returned by
|
22
|
-
# {Gcloud::Translate::Api#detect}.
|
23
|
-
#
|
24
|
-
# @see https://cloud.google.com/translate/v2/using_rest#detect-language
|
25
|
-
# Detect Language
|
26
|
-
#
|
27
|
-
# @example
|
28
|
-
# require "gcloud"
|
29
|
-
#
|
30
|
-
# gcloud = Gcloud.new
|
31
|
-
# translate = gcloud.translate
|
32
|
-
#
|
33
|
-
# detections = translate.detect "chien", "chat"
|
34
|
-
#
|
35
|
-
# detections.size #=> 2
|
36
|
-
# detections[0].text #=> "chien"
|
37
|
-
# detections[0].language #=> "fr"
|
38
|
-
# detections[0].confidence #=> 0.7109375
|
39
|
-
# detections[1].text #=> "chat"
|
40
|
-
# detections[1].language #=> "en"
|
41
|
-
# detections[1].confidence #=> 0.59922177
|
42
|
-
#
|
43
|
-
class Detection
|
44
|
-
##
|
45
|
-
# The text upon which the language detection was performed.
|
46
|
-
#
|
47
|
-
# @return [String]
|
48
|
-
attr_reader :text
|
49
|
-
|
50
|
-
##
|
51
|
-
# The list of detection results for the given text. The most likely
|
52
|
-
# language is listed first, and its attributes can be accessed through
|
53
|
-
# {#language} and {#confidence}.
|
54
|
-
#
|
55
|
-
# @return [Array<Detection::Result>]
|
56
|
-
attr_reader :results
|
57
|
-
|
58
|
-
##
|
59
|
-
# @private Create a new object.
|
60
|
-
def initialize text, results
|
61
|
-
@text = text
|
62
|
-
@results = results
|
63
|
-
end
|
64
|
-
|
65
|
-
##
|
66
|
-
# The confidence that the language detection result is correct. The closer
|
67
|
-
# this value is to 1, the higher the confidence in language detection.
|
68
|
-
#
|
69
|
-
# @return [Float] a value between 0 and 1
|
70
|
-
def confidence
|
71
|
-
return nil if results.empty?
|
72
|
-
results.first.confidence
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# The most likely language that was detected. This is an [ISO
|
77
|
-
# 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language
|
78
|
-
# code.
|
79
|
-
#
|
80
|
-
# @return [String] the language code
|
81
|
-
def language
|
82
|
-
return nil if results.empty?
|
83
|
-
results.first.language
|
84
|
-
end
|
85
|
-
|
86
|
-
##
|
87
|
-
# @private New Detection from a ListDetectionsResponse object as
|
88
|
-
# defined by the Google API Client object.
|
89
|
-
def self.from_gapi gapi, text
|
90
|
-
res = text.zip(Array(gapi.detections)).map do |txt, detections_gapi|
|
91
|
-
results = detections_gapi.map { |g| Result.from_gapi g }
|
92
|
-
new txt, results
|
93
|
-
end
|
94
|
-
return res.first if res.size == 1
|
95
|
-
res
|
96
|
-
end
|
97
|
-
|
98
|
-
##
|
99
|
-
# # Result
|
100
|
-
#
|
101
|
-
# Represents an individual result in a {Gcloud::Translate::Detection}
|
102
|
-
# result.
|
103
|
-
#
|
104
|
-
class Result
|
105
|
-
##
|
106
|
-
# The confidence that the language detection result is correct. The
|
107
|
-
# closer this value is to 1, the higher the confidence in language
|
108
|
-
# detection.
|
109
|
-
#
|
110
|
-
# @return [Float] a value between 0 and 1
|
111
|
-
attr_reader :confidence
|
112
|
-
|
113
|
-
##
|
114
|
-
# The language detected. This is an [ISO
|
115
|
-
# 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language
|
116
|
-
# code.
|
117
|
-
#
|
118
|
-
# @return [String] the language code
|
119
|
-
attr_reader :language
|
120
|
-
|
121
|
-
##
|
122
|
-
# @private Create a new object.
|
123
|
-
def initialize confidence, language
|
124
|
-
@confidence = confidence
|
125
|
-
@language = language
|
126
|
-
end
|
127
|
-
|
128
|
-
##
|
129
|
-
# @private New Detection::Result from a DetectionsResource object as
|
130
|
-
# defined by the Google API Client object.
|
131
|
-
def self.from_gapi gapi
|
132
|
-
new gapi.confidence, gapi.language
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
-
# http://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
|
-
|
16
|
-
module Gcloud
|
17
|
-
module Translate
|
18
|
-
##
|
19
|
-
# # Language
|
20
|
-
#
|
21
|
-
# Represents a supported languages query result. Returned by
|
22
|
-
# {Gcloud::Translate::Api#languages}.
|
23
|
-
#
|
24
|
-
# @see https://cloud.google.com/translate/v2/using_rest#supported-languages
|
25
|
-
# Discover Supported Languages
|
26
|
-
#
|
27
|
-
# @example
|
28
|
-
# require "gcloud"
|
29
|
-
#
|
30
|
-
# gcloud = Gcloud.new
|
31
|
-
# translate = gcloud.translate
|
32
|
-
#
|
33
|
-
# languages = translate.languages "en"
|
34
|
-
#
|
35
|
-
# languages.size #=> 104
|
36
|
-
# languages[0].code #=> "af"
|
37
|
-
# languages[0].name #=> "Afrikaans"
|
38
|
-
#
|
39
|
-
class Language
|
40
|
-
##
|
41
|
-
# The language code. This is an [ISO
|
42
|
-
# 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language
|
43
|
-
# code.
|
44
|
-
#
|
45
|
-
# @return [String]
|
46
|
-
attr_reader :code
|
47
|
-
|
48
|
-
##
|
49
|
-
# The localized name of the language, if available.
|
50
|
-
#
|
51
|
-
# @return [String]
|
52
|
-
attr_reader :name
|
53
|
-
|
54
|
-
##
|
55
|
-
# @private Create a new object.
|
56
|
-
def initialize code, name
|
57
|
-
@code = code
|
58
|
-
@name = name
|
59
|
-
end
|
60
|
-
|
61
|
-
##
|
62
|
-
# @private New Language from a LanguagesResource object as defined by the
|
63
|
-
# Google API Client object.
|
64
|
-
def self.from_gapi gapi
|
65
|
-
new gapi.language, gapi.name
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
-
# http://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
|
-
|
16
|
-
require "gcloud/version"
|
17
|
-
require "gcloud/errors"
|
18
|
-
require "google/apis/translate_v2"
|
19
|
-
|
20
|
-
module Gcloud
|
21
|
-
module Translate
|
22
|
-
##
|
23
|
-
# @private
|
24
|
-
# Represents the service to Translate, exposing the API calls.
|
25
|
-
class Service
|
26
|
-
##
|
27
|
-
# Alias to the Google Client API module
|
28
|
-
API = Google::Apis::TranslateV2
|
29
|
-
|
30
|
-
attr_accessor :credentials
|
31
|
-
|
32
|
-
##
|
33
|
-
# Creates a new Service instance.
|
34
|
-
def initialize key, retries: nil, timeout: nil
|
35
|
-
@service = API::TranslateService.new
|
36
|
-
@service.client_options.application_name = "gcloud-ruby"
|
37
|
-
@service.client_options.application_version = Gcloud::VERSION
|
38
|
-
@service.request_options.retries = retries || 3
|
39
|
-
@service.request_options.timeout_sec = timeout if timeout
|
40
|
-
@service.authorization = nil
|
41
|
-
@service.key = key
|
42
|
-
end
|
43
|
-
|
44
|
-
def service
|
45
|
-
return mocked_service if mocked_service
|
46
|
-
@service
|
47
|
-
end
|
48
|
-
attr_accessor :mocked_service
|
49
|
-
|
50
|
-
##
|
51
|
-
# Returns API::ListTranslationsResponse
|
52
|
-
def translate text, to: nil, from: nil, format: nil, cid: nil
|
53
|
-
service.list_translations Array(text), to, cid: cid, format: format,
|
54
|
-
source: from
|
55
|
-
rescue Google::Apis::Error => e
|
56
|
-
raise Gcloud::Error.from_error(e)
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# Returns API::ListDetectionsResponse
|
61
|
-
def detect text
|
62
|
-
service.list_detections Array(text)
|
63
|
-
rescue Google::Apis::Error => e
|
64
|
-
raise Gcloud::Error.from_error(e)
|
65
|
-
end
|
66
|
-
|
67
|
-
##
|
68
|
-
# Returns API::ListLanguagesResponse
|
69
|
-
def languages language = nil
|
70
|
-
service.list_languages target: language
|
71
|
-
rescue Google::Apis::Error => e
|
72
|
-
raise Gcloud::Error.from_error(e)
|
73
|
-
end
|
74
|
-
|
75
|
-
def inspect
|
76
|
-
"#{self.class}"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|