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
@@ -1,112 +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
|
-
# # Translation
|
20
|
-
#
|
21
|
-
# Represents a translation query result. Returned by
|
22
|
-
# {Gcloud::Translate::Api#translate}.
|
23
|
-
#
|
24
|
-
# @see https://cloud.google.com/translate/v2/using_rest#Translate Translate
|
25
|
-
# Text
|
26
|
-
#
|
27
|
-
# @example
|
28
|
-
# require "gcloud"
|
29
|
-
#
|
30
|
-
# gcloud = Gcloud.new
|
31
|
-
# translate = gcloud.translate
|
32
|
-
#
|
33
|
-
# translation = translate.translate "Hello world!", to: "la"
|
34
|
-
#
|
35
|
-
# puts translation #=> Salve mundi!
|
36
|
-
#
|
37
|
-
# translation.from #=> "en"
|
38
|
-
# translation.origin #=> "Hello world!"
|
39
|
-
# translation.to #=> "la"
|
40
|
-
# translation.text #=> "Salve mundi!"
|
41
|
-
#
|
42
|
-
class Translation
|
43
|
-
##
|
44
|
-
# The translated result.
|
45
|
-
#
|
46
|
-
# @return [String]
|
47
|
-
attr_reader :text
|
48
|
-
alias_method :to_s, :text
|
49
|
-
alias_method :to_str, :text
|
50
|
-
|
51
|
-
##
|
52
|
-
# The original query text that was translated.
|
53
|
-
#
|
54
|
-
# @return [String]
|
55
|
-
attr_reader :origin
|
56
|
-
|
57
|
-
##
|
58
|
-
# The target language into which the text was translated.
|
59
|
-
#
|
60
|
-
# @return [String]
|
61
|
-
attr_reader :to
|
62
|
-
alias_method :language, :to
|
63
|
-
alias_method :target, :to
|
64
|
-
|
65
|
-
##
|
66
|
-
# The source language from which the text was translated.
|
67
|
-
attr_reader :from
|
68
|
-
alias_method :source, :from
|
69
|
-
|
70
|
-
##
|
71
|
-
# @private Create a new object.
|
72
|
-
def initialize text, to, origin, from, detected
|
73
|
-
@text = text
|
74
|
-
@to = to
|
75
|
-
@origin = origin
|
76
|
-
@from = from
|
77
|
-
@detected = detected
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# Determines if the source language was detected by the Google Cloud
|
82
|
-
# Translate API.
|
83
|
-
#
|
84
|
-
# @return [Boolean] `true` if the source language was detected by the
|
85
|
-
# Translate service, `false` if the source language was provided in the
|
86
|
-
# request
|
87
|
-
def detected?
|
88
|
-
@detected
|
89
|
-
end
|
90
|
-
|
91
|
-
##
|
92
|
-
# @private New Translation from a TranslationsListResponse object as
|
93
|
-
# defined by the Google API Client object.
|
94
|
-
def self.from_gapi_list gapi, text, to, from
|
95
|
-
res = text.zip(Array(gapi.translations)).map do |origin, g|
|
96
|
-
from_gapi g, to, origin, from
|
97
|
-
end
|
98
|
-
return res.first if res.size == 1
|
99
|
-
res
|
100
|
-
end
|
101
|
-
|
102
|
-
##
|
103
|
-
# @private New Translation from a TranslationsResource object as defined
|
104
|
-
# by the Google API Client object.
|
105
|
-
def self.from_gapi gapi, to, origin, from
|
106
|
-
from ||= gapi.detected_source_language
|
107
|
-
detected = !gapi.detected_source_language.nil?
|
108
|
-
new gapi.translated_text, to, origin, from, detected
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,224 +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/vision/image"
|
17
|
-
require "google/apis/vision_v1"
|
18
|
-
|
19
|
-
module Gcloud
|
20
|
-
module Vision
|
21
|
-
##
|
22
|
-
# # Annotate
|
23
|
-
#
|
24
|
-
# Accumulates configuration for an image annotation request. Users describe
|
25
|
-
# the type of Google Cloud Vision API tasks to perform over images by
|
26
|
-
# configuring features such as `faces`, `landmarks`, `text`, etc. This
|
27
|
-
# configuration captures the Cloud Vision API vertical to operate on and the
|
28
|
-
# number of top-scoring results to return.
|
29
|
-
#
|
30
|
-
# See {Project#annotate}.
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# require "gcloud"
|
34
|
-
#
|
35
|
-
# gcloud = Gcloud.new
|
36
|
-
# vision = gcloud.vision
|
37
|
-
#
|
38
|
-
# face_image = vision.image "path/to/face.jpg"
|
39
|
-
# landmark_image = vision.image "path/to/landmark.jpg"
|
40
|
-
#
|
41
|
-
# annotation = vision.annotate do |annotate|
|
42
|
-
# annotate.annotate face_image, faces: true, labels: true
|
43
|
-
# annotate.annotate landmark_image, landmarks: true
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# annotation.faces.count #=> 1
|
47
|
-
# annotation.labels.count #=> 4
|
48
|
-
# annotation.landmarks.count #=> 1
|
49
|
-
#
|
50
|
-
class Annotate
|
51
|
-
# @private
|
52
|
-
attr_accessor :requests
|
53
|
-
|
54
|
-
##
|
55
|
-
# @private Creates a new Annotate instance.
|
56
|
-
def initialize project
|
57
|
-
@project = project
|
58
|
-
@requests = []
|
59
|
-
end
|
60
|
-
|
61
|
-
##
|
62
|
-
# Performs detection of Cloud Vision [features](https://cloud.google.com/vision/reference/rest/v1/images/annotate#Feature)
|
63
|
-
# on the given images. If no options for features are provided, **all**
|
64
|
-
# image detection features will be performed, with a default of `100`
|
65
|
-
# results for faces, landmarks, logos, and labels. If any feature option
|
66
|
-
# is provided, only the specified feature detections will be performed.
|
67
|
-
# Please review [Pricing](https://cloud.google.com/vision/docs/pricing)
|
68
|
-
# before use, as a separate charge is incurred for each feature performed
|
69
|
-
# on an image.
|
70
|
-
#
|
71
|
-
# Cloud Vision sets upper limits on file size as well as on the total
|
72
|
-
# combined size of all images in a request. Reducing your file size can
|
73
|
-
# significantly improve throughput; however, be careful not to reduce
|
74
|
-
# image quality in the process. See [Best Practices - Image
|
75
|
-
# Sizing](https://cloud.google.com/vision/docs/image-best-practices#image_sizing)
|
76
|
-
# for current file size limits.
|
77
|
-
#
|
78
|
-
# See {Project#annotate} for requests that do not involve multiple feature
|
79
|
-
# configurations.
|
80
|
-
#
|
81
|
-
# @see https://cloud.google.com/vision/docs/requests-and-responses Cloud
|
82
|
-
# Vision API Requests and Responses
|
83
|
-
# @see https://cloud.google.com/vision/reference/rest/v1/images/annotate#AnnotateImageRequest
|
84
|
-
# AnnotateImageRequest
|
85
|
-
# @see https://cloud.google.com/vision/docs/pricing Cloud Vision Pricing
|
86
|
-
#
|
87
|
-
# @param [Image, Object] images The image or images to annotate. This can
|
88
|
-
# be an {Image} instance, or any other type that converts to an {Image}.
|
89
|
-
# See {#image} for details.
|
90
|
-
# @param [Boolean, Integer] faces Whether to perform the facial detection
|
91
|
-
# feature. The maximum number of results is configured in
|
92
|
-
# {Gcloud::Vision.default_max_faces}, or may be provided here. Optional.
|
93
|
-
# @param [Boolean, Integer] landmarks Whether to perform the landmark
|
94
|
-
# detection feature. The maximum number of results is configured in
|
95
|
-
# {Gcloud::Vision.default_max_landmarks}, or may be provided here.
|
96
|
-
# Optional.
|
97
|
-
# @param [Boolean, Integer] logos Whether to perform the logo detection
|
98
|
-
# feature. The maximum number of results is configured in
|
99
|
-
# {Gcloud::Vision.default_max_logos}, or may be provided here. Optional.
|
100
|
-
# @param [Boolean, Integer] labels Whether to perform the label detection
|
101
|
-
# feature. The maximum number of results is configured in
|
102
|
-
# {Gcloud::Vision.default_max_labels}, or may be provided here.
|
103
|
-
# Optional.
|
104
|
-
# @param [Boolean] text Whether to perform the text (OCR) feature.
|
105
|
-
# Optional.
|
106
|
-
# @param [Boolean] safe_search Whether to perform the safe search feature.
|
107
|
-
# Optional.
|
108
|
-
# @param [Boolean] properties Whether to perform the image properties
|
109
|
-
# feature (currently, the image's dominant colors.) Optional.
|
110
|
-
#
|
111
|
-
# @return [Annotation, Array<Annotation>] The results for all image
|
112
|
-
# detections, returned as a single {Annotation} instance for one image,
|
113
|
-
# or as an array of {Annotation} instances, one per image, for multiple
|
114
|
-
# images.
|
115
|
-
#
|
116
|
-
# @example
|
117
|
-
# require "gcloud"
|
118
|
-
#
|
119
|
-
# gcloud = Gcloud.new
|
120
|
-
# vision = gcloud.vision
|
121
|
-
#
|
122
|
-
# face_image = vision.image "path/to/face.jpg"
|
123
|
-
# landmark_image = vision.image "path/to/landmark.jpg"
|
124
|
-
# text_image = vision.image "path/to/text.png"
|
125
|
-
#
|
126
|
-
# annotations = vision.annotate do |annotate|
|
127
|
-
# annotate.annotate face_image, faces: true, labels: true
|
128
|
-
# annotate.annotate landmark_image, landmarks: true
|
129
|
-
# annotate.annotate text_image, text: true
|
130
|
-
# end
|
131
|
-
#
|
132
|
-
# annotations[0].faces.count #=> 1
|
133
|
-
# annotations[0].labels.count #=> 4
|
134
|
-
# annotations[1].landmarks.count #=> 1
|
135
|
-
# annotations[2].text.words.count #=> 28
|
136
|
-
#
|
137
|
-
def annotate *images, faces: false, landmarks: false, logos: false,
|
138
|
-
labels: false, text: false, safe_search: false,
|
139
|
-
properties: false
|
140
|
-
add_requests(images, faces, landmarks, logos, labels, text,
|
141
|
-
safe_search, properties)
|
142
|
-
end
|
143
|
-
|
144
|
-
protected
|
145
|
-
|
146
|
-
def image source
|
147
|
-
return source if source.is_a? Image
|
148
|
-
Image.from_source source, @project
|
149
|
-
end
|
150
|
-
|
151
|
-
def add_requests images, faces, landmarks, logos, labels, text,
|
152
|
-
safe_search, properties
|
153
|
-
features = annotate_features(faces, landmarks, logos, labels, text,
|
154
|
-
safe_search, properties)
|
155
|
-
|
156
|
-
Array(images).flatten.each do |img|
|
157
|
-
i = image(img)
|
158
|
-
@requests << Google::Apis::VisionV1::AnnotateImageRequest.new(
|
159
|
-
image: i.to_gapi,
|
160
|
-
features: features,
|
161
|
-
imageContext: i.context.to_gapi
|
162
|
-
)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def annotate_features faces, landmarks, logos, labels, text,
|
167
|
-
safe_search, properties
|
168
|
-
return default_features if default_features?(
|
169
|
-
faces, landmarks, logos, labels, text, safe_search, properties)
|
170
|
-
|
171
|
-
faces, landmarks, logos, labels = validate_max_values(
|
172
|
-
faces, landmarks, logos, labels)
|
173
|
-
|
174
|
-
f = []
|
175
|
-
f << feature("FACE_DETECTION", faces) unless faces.zero?
|
176
|
-
f << feature("LANDMARK_DETECTION", landmarks) unless landmarks.zero?
|
177
|
-
f << feature("LOGO_DETECTION", logos) unless logos.zero?
|
178
|
-
f << feature("LABEL_DETECTION", labels) unless labels.zero?
|
179
|
-
f << feature("TEXT_DETECTION", 1) if text
|
180
|
-
f << feature("SAFE_SEARCH_DETECTION", 1) if safe_search
|
181
|
-
f << feature("IMAGE_PROPERTIES", 1) if properties
|
182
|
-
f
|
183
|
-
end
|
184
|
-
|
185
|
-
def feature type, max_results
|
186
|
-
Google::Apis::VisionV1::Feature.new type: type, max_results: max_results
|
187
|
-
end
|
188
|
-
|
189
|
-
def default_features? faces, landmarks, logos, labels, text,
|
190
|
-
safe_search, properties
|
191
|
-
faces == false && landmarks == false && logos == false &&
|
192
|
-
labels == false && text == false && safe_search == false &&
|
193
|
-
properties == false
|
194
|
-
end
|
195
|
-
|
196
|
-
def default_features
|
197
|
-
[
|
198
|
-
feature("FACE_DETECTION", Gcloud::Vision.default_max_faces),
|
199
|
-
feature("LANDMARK_DETECTION", Gcloud::Vision.default_max_landmarks),
|
200
|
-
feature("LOGO_DETECTION", Gcloud::Vision.default_max_logos),
|
201
|
-
feature("LABEL_DETECTION", Gcloud::Vision.default_max_labels),
|
202
|
-
feature("TEXT_DETECTION", 1),
|
203
|
-
feature("SAFE_SEARCH_DETECTION", 1),
|
204
|
-
feature("IMAGE_PROPERTIES", 1)
|
205
|
-
]
|
206
|
-
end
|
207
|
-
|
208
|
-
def validate_max_values faces, landmarks, logos, labels
|
209
|
-
faces = validate_max_value faces, Gcloud::Vision.default_max_faces
|
210
|
-
landmarks = validate_max_value landmarks,
|
211
|
-
Gcloud::Vision.default_max_landmarks
|
212
|
-
logos = validate_max_value logos, Gcloud::Vision.default_max_logos
|
213
|
-
labels = validate_max_value labels, Gcloud::Vision.default_max_labels
|
214
|
-
[faces, landmarks, logos, labels]
|
215
|
-
end
|
216
|
-
|
217
|
-
def validate_max_value value, default_value
|
218
|
-
return value.to_int if value.respond_to? :to_int
|
219
|
-
return default_value if value
|
220
|
-
0 # not a number, not a truthy value
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
@@ -1,455 +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/vision/annotation/face"
|
17
|
-
require "gcloud/vision/annotation/entity"
|
18
|
-
require "gcloud/vision/annotation/text"
|
19
|
-
require "gcloud/vision/annotation/safe_search"
|
20
|
-
require "gcloud/vision/annotation/properties"
|
21
|
-
|
22
|
-
module Gcloud
|
23
|
-
module Vision
|
24
|
-
##
|
25
|
-
# # Annotation
|
26
|
-
#
|
27
|
-
# The results of all requested image annotations.
|
28
|
-
#
|
29
|
-
# See {Project#annotate} and {Image}.
|
30
|
-
#
|
31
|
-
# @example
|
32
|
-
# require "gcloud"
|
33
|
-
#
|
34
|
-
# gcloud = Gcloud.new
|
35
|
-
# vision = gcloud.vision
|
36
|
-
# image = vision.image "path/to/face.jpg"
|
37
|
-
#
|
38
|
-
# annotation = vision.annotate image, faces: true, labels: true
|
39
|
-
# annotation.faces.count #=> 1
|
40
|
-
# annotation.labels.count #=> 4
|
41
|
-
# annotation.text #=> nil
|
42
|
-
#
|
43
|
-
class Annotation
|
44
|
-
##
|
45
|
-
# @private The AnnotateImageResponse Google API Client object.
|
46
|
-
attr_accessor :gapi
|
47
|
-
|
48
|
-
##
|
49
|
-
# @private Creates a new Annotation instance.
|
50
|
-
def initialize
|
51
|
-
@gapi = nil
|
52
|
-
end
|
53
|
-
|
54
|
-
##
|
55
|
-
# The results of face detection.
|
56
|
-
#
|
57
|
-
# @return [Array<Face>]
|
58
|
-
#
|
59
|
-
# @example
|
60
|
-
# require "gcloud"
|
61
|
-
#
|
62
|
-
# gcloud = Gcloud.new
|
63
|
-
# vision = gcloud.vision
|
64
|
-
# image = vision.image "path/to/face.jpg"
|
65
|
-
#
|
66
|
-
# annotation = vision.annotate image, faces: true
|
67
|
-
# annotation.faces.count #=> 1
|
68
|
-
# face = annotation.faces.first
|
69
|
-
#
|
70
|
-
def faces
|
71
|
-
@faces ||= Array(@gapi.face_annotations).map do |fa|
|
72
|
-
Face.from_gapi fa
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
##
|
77
|
-
# The first face result, if there is one.
|
78
|
-
#
|
79
|
-
# @return [Face]
|
80
|
-
#
|
81
|
-
# @example
|
82
|
-
# require "gcloud"
|
83
|
-
#
|
84
|
-
# gcloud = Gcloud.new
|
85
|
-
# vision = gcloud.vision
|
86
|
-
# image = vision.image "path/to/face.jpg"
|
87
|
-
#
|
88
|
-
# annotation = vision.annotate image, faces: 1
|
89
|
-
# face = annotation.face
|
90
|
-
#
|
91
|
-
def face
|
92
|
-
faces.first
|
93
|
-
end
|
94
|
-
|
95
|
-
##
|
96
|
-
# Whether there is at least one result from face detection.
|
97
|
-
#
|
98
|
-
# @return [Boolean]
|
99
|
-
#
|
100
|
-
# @example
|
101
|
-
# require "gcloud"
|
102
|
-
#
|
103
|
-
# gcloud = Gcloud.new
|
104
|
-
# vision = gcloud.vision
|
105
|
-
# image = vision.image "path/to/face.jpg"
|
106
|
-
#
|
107
|
-
# annotation = vision.annotate image, faces: 1
|
108
|
-
# annotation.face? #=> true
|
109
|
-
#
|
110
|
-
def face?
|
111
|
-
faces.count > 0
|
112
|
-
end
|
113
|
-
|
114
|
-
##
|
115
|
-
# The results of landmark detection.
|
116
|
-
#
|
117
|
-
# @return [Array<Entity>]
|
118
|
-
#
|
119
|
-
# @example
|
120
|
-
# require "gcloud"
|
121
|
-
#
|
122
|
-
# gcloud = Gcloud.new
|
123
|
-
# vision = gcloud.vision
|
124
|
-
# image = vision.image "path/to/landmark.jpg"
|
125
|
-
#
|
126
|
-
# annotation = vision.annotate image, landmarks: 1
|
127
|
-
# annotation.landmarks.count #=> 1
|
128
|
-
# landmark = annotation.landmarks.first
|
129
|
-
#
|
130
|
-
def landmarks
|
131
|
-
@landmarks ||= Array(@gapi.landmark_annotations).map do |lm|
|
132
|
-
Entity.from_gapi lm
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
##
|
137
|
-
# The first landmark result, if there is one.
|
138
|
-
#
|
139
|
-
# @return [Entity]
|
140
|
-
#
|
141
|
-
# @example
|
142
|
-
# require "gcloud"
|
143
|
-
#
|
144
|
-
# gcloud = Gcloud.new
|
145
|
-
# vision = gcloud.vision
|
146
|
-
# image = vision.image "path/to/landmark.jpg"
|
147
|
-
#
|
148
|
-
# annotation = vision.annotate image, landmarks: 1
|
149
|
-
# landmark = annotation.landmark
|
150
|
-
#
|
151
|
-
def landmark
|
152
|
-
landmarks.first
|
153
|
-
end
|
154
|
-
|
155
|
-
##
|
156
|
-
# Whether there is at least one result from landmark detection.
|
157
|
-
# detection.
|
158
|
-
#
|
159
|
-
# @return [Boolean]
|
160
|
-
#
|
161
|
-
# @example
|
162
|
-
# require "gcloud"
|
163
|
-
#
|
164
|
-
# gcloud = Gcloud.new
|
165
|
-
# vision = gcloud.vision
|
166
|
-
# image = vision.image "path/to/landmark.jpg"
|
167
|
-
#
|
168
|
-
# annotation = vision.annotate image, landmarks: 1
|
169
|
-
# annotation.landmark? #=> true
|
170
|
-
#
|
171
|
-
def landmark?
|
172
|
-
landmarks.count > 0
|
173
|
-
end
|
174
|
-
|
175
|
-
##
|
176
|
-
# The results of logo detection.
|
177
|
-
#
|
178
|
-
# @return [Array<Entity>]
|
179
|
-
#
|
180
|
-
# @example
|
181
|
-
# require "gcloud"
|
182
|
-
#
|
183
|
-
# gcloud = Gcloud.new
|
184
|
-
# vision = gcloud.vision
|
185
|
-
# image = vision.image "path/to/logo.jpg"
|
186
|
-
#
|
187
|
-
# annotation = vision.annotate image, logos: 1
|
188
|
-
# annotation.logos.count #=> 1
|
189
|
-
# logo = annotation.logos.first
|
190
|
-
#
|
191
|
-
def logos
|
192
|
-
@logos ||= Array(@gapi.logo_annotations).map do |lg|
|
193
|
-
Entity.from_gapi lg
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
##
|
198
|
-
# The first logo result, if there is one.
|
199
|
-
#
|
200
|
-
# @return [Entity]
|
201
|
-
#
|
202
|
-
# @example
|
203
|
-
# require "gcloud"
|
204
|
-
#
|
205
|
-
# gcloud = Gcloud.new
|
206
|
-
# vision = gcloud.vision
|
207
|
-
# image = vision.image "path/to/logo.jpg"
|
208
|
-
#
|
209
|
-
# annotation = vision.annotate image, logos: 1
|
210
|
-
# logo = annotation.logo
|
211
|
-
#
|
212
|
-
def logo
|
213
|
-
logos.first
|
214
|
-
end
|
215
|
-
|
216
|
-
##
|
217
|
-
# Whether there is at least one result from logo detection.
|
218
|
-
# detection.
|
219
|
-
#
|
220
|
-
# @return [Boolean]
|
221
|
-
#
|
222
|
-
# @example
|
223
|
-
# require "gcloud"
|
224
|
-
#
|
225
|
-
# gcloud = Gcloud.new
|
226
|
-
# vision = gcloud.vision
|
227
|
-
# image = vision.image "path/to/logo.jpg"
|
228
|
-
#
|
229
|
-
# annotation = vision.annotate image, logos: 1
|
230
|
-
# annotation.logo? #=> true
|
231
|
-
#
|
232
|
-
def logo?
|
233
|
-
logos.count > 0
|
234
|
-
end
|
235
|
-
|
236
|
-
##
|
237
|
-
# The results of label detection.
|
238
|
-
#
|
239
|
-
# @return [Array<Entity>]
|
240
|
-
#
|
241
|
-
# @example
|
242
|
-
# require "gcloud"
|
243
|
-
#
|
244
|
-
# gcloud = Gcloud.new
|
245
|
-
# vision = gcloud.vision
|
246
|
-
# image = vision.image "path/to/face.jpg"
|
247
|
-
#
|
248
|
-
# annotation = vision.annotate image, labels: 1
|
249
|
-
# annotation.labels.count #=> 1
|
250
|
-
# label = annotation.labels.first
|
251
|
-
#
|
252
|
-
def labels
|
253
|
-
@labels ||= Array(@gapi.label_annotations).map do |lb|
|
254
|
-
Entity.from_gapi lb
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
##
|
259
|
-
# The first label result, if there is one.
|
260
|
-
#
|
261
|
-
# @return [Entity]
|
262
|
-
#
|
263
|
-
# @example
|
264
|
-
# require "gcloud"
|
265
|
-
#
|
266
|
-
# gcloud = Gcloud.new
|
267
|
-
# vision = gcloud.vision
|
268
|
-
# image = vision.image "path/to/face.jpg"
|
269
|
-
#
|
270
|
-
# annotation = vision.annotate image, labels: 1
|
271
|
-
# label = annotation.label
|
272
|
-
#
|
273
|
-
def label
|
274
|
-
labels.first
|
275
|
-
end
|
276
|
-
|
277
|
-
##
|
278
|
-
# Whether there is at least one result from label detection.
|
279
|
-
# detection.
|
280
|
-
#
|
281
|
-
# @return [Boolean]
|
282
|
-
#
|
283
|
-
# @example
|
284
|
-
# require "gcloud"
|
285
|
-
#
|
286
|
-
# gcloud = Gcloud.new
|
287
|
-
# vision = gcloud.vision
|
288
|
-
# image = vision.image "path/to/face.jpg"
|
289
|
-
#
|
290
|
-
# annotation = vision.annotate image, labels: 1
|
291
|
-
# annotation.label? #=> true
|
292
|
-
#
|
293
|
-
def label?
|
294
|
-
labels.count > 0
|
295
|
-
end
|
296
|
-
|
297
|
-
##
|
298
|
-
# The results of text (OCR) detection.
|
299
|
-
#
|
300
|
-
# @return [Text]
|
301
|
-
#
|
302
|
-
# @example
|
303
|
-
# require "gcloud"
|
304
|
-
#
|
305
|
-
# gcloud = Gcloud.new
|
306
|
-
# vision = gcloud.vision
|
307
|
-
# image = vision.image "path/to/text.png"
|
308
|
-
#
|
309
|
-
# annotation = vision.annotate image, text: true
|
310
|
-
# text = annotation.text
|
311
|
-
#
|
312
|
-
def text
|
313
|
-
@text ||= Text.from_gapi(@gapi.text_annotations)
|
314
|
-
end
|
315
|
-
|
316
|
-
##
|
317
|
-
# Whether there is a result from text (OCR) detection.
|
318
|
-
#
|
319
|
-
# @return [Boolean]
|
320
|
-
#
|
321
|
-
# @example
|
322
|
-
# require "gcloud"
|
323
|
-
#
|
324
|
-
# gcloud = Gcloud.new
|
325
|
-
# vision = gcloud.vision
|
326
|
-
# image = vision.image "path/to/text.png"
|
327
|
-
#
|
328
|
-
# annotation = vision.annotate image, text: true
|
329
|
-
# annotation.text? #=> true
|
330
|
-
#
|
331
|
-
def text?
|
332
|
-
!text.nil?
|
333
|
-
end
|
334
|
-
|
335
|
-
##
|
336
|
-
# The results of safe_search detection.
|
337
|
-
#
|
338
|
-
# @return [SafeSearch]
|
339
|
-
#
|
340
|
-
# @example
|
341
|
-
# require "gcloud"
|
342
|
-
#
|
343
|
-
# gcloud = Gcloud.new
|
344
|
-
# vision = gcloud.vision
|
345
|
-
# image = vision.image "path/to/face.jpg"
|
346
|
-
#
|
347
|
-
# annotation = vision.annotate image, safe_search: true
|
348
|
-
# safe_search = annotation.safe_search
|
349
|
-
#
|
350
|
-
def safe_search
|
351
|
-
return nil unless @gapi.safe_search_annotation
|
352
|
-
@safe_search ||= SafeSearch.from_gapi(@gapi.safe_search_annotation)
|
353
|
-
end
|
354
|
-
|
355
|
-
##
|
356
|
-
# Whether there is a result for safe_search detection.
|
357
|
-
# detection.
|
358
|
-
#
|
359
|
-
# @return [Boolean]
|
360
|
-
#
|
361
|
-
# @example
|
362
|
-
# require "gcloud"
|
363
|
-
#
|
364
|
-
# gcloud = Gcloud.new
|
365
|
-
# vision = gcloud.vision
|
366
|
-
# image = vision.image "path/to/face.jpg"
|
367
|
-
#
|
368
|
-
# annotation = vision.annotate image, safe_search: true
|
369
|
-
# annotation.safe_search? #=> true
|
370
|
-
#
|
371
|
-
def safe_search?
|
372
|
-
!safe_search.nil?
|
373
|
-
end
|
374
|
-
|
375
|
-
##
|
376
|
-
# The results of properties detection.
|
377
|
-
#
|
378
|
-
# @return [Properties]
|
379
|
-
#
|
380
|
-
# @example
|
381
|
-
# require "gcloud"
|
382
|
-
#
|
383
|
-
# gcloud = Gcloud.new
|
384
|
-
# vision = gcloud.vision
|
385
|
-
# image = vision.image "path/to/face.jpg"
|
386
|
-
#
|
387
|
-
# annotation = vision.annotate image, properties: true
|
388
|
-
# properties = annotation.properties
|
389
|
-
#
|
390
|
-
def properties
|
391
|
-
return nil unless @gapi.image_properties_annotation
|
392
|
-
@properties ||= Properties.from_gapi(@gapi.image_properties_annotation)
|
393
|
-
end
|
394
|
-
|
395
|
-
##
|
396
|
-
# Whether there is a result for properties detection.
|
397
|
-
#
|
398
|
-
# @return [Boolean]
|
399
|
-
#
|
400
|
-
# @example
|
401
|
-
# require "gcloud"
|
402
|
-
#
|
403
|
-
# gcloud = Gcloud.new
|
404
|
-
# vision = gcloud.vision
|
405
|
-
# image = vision.image "path/to/face.jpg"
|
406
|
-
#
|
407
|
-
# annotation = vision.annotate image, properties: true
|
408
|
-
# annotation.properties? #=> true
|
409
|
-
#
|
410
|
-
def properties?
|
411
|
-
!properties.nil?
|
412
|
-
end
|
413
|
-
|
414
|
-
##
|
415
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
416
|
-
#
|
417
|
-
# @return [Hash]
|
418
|
-
#
|
419
|
-
def to_h
|
420
|
-
to_hash
|
421
|
-
end
|
422
|
-
|
423
|
-
##
|
424
|
-
# Deeply converts object to a hash. All keys will be symbolized.
|
425
|
-
#
|
426
|
-
# @return [Hash]
|
427
|
-
#
|
428
|
-
def to_hash
|
429
|
-
{ faces: faces.map(&:to_h), landmarks: landmarks.map(&:to_h),
|
430
|
-
logos: logos.map(&:to_h), labels: labels.map(&:to_h),
|
431
|
-
text: text.map(&:to_h), safe_search: safe_search.to_h,
|
432
|
-
properties: properties.to_h }
|
433
|
-
end
|
434
|
-
|
435
|
-
# @private
|
436
|
-
def to_s
|
437
|
-
tmplt = "(faces: %i, landmarks: %i, logos: %i, labels: %i, text: %s," \
|
438
|
-
" safe_search: %s, properties: %s)"
|
439
|
-
format tmplt, faces.count, landmarks.count, logos.count, labels.count,
|
440
|
-
text?, safe_search?, properties?
|
441
|
-
end
|
442
|
-
|
443
|
-
# @private
|
444
|
-
def inspect
|
445
|
-
"#<#{self.class.name} #{self}>"
|
446
|
-
end
|
447
|
-
|
448
|
-
##
|
449
|
-
# @private New Annotation from a Google API Client object.
|
450
|
-
def self.from_gapi gapi
|
451
|
-
new.tap { |a| a.instance_variable_set :@gapi, gapi }
|
452
|
-
end
|
453
|
-
end
|
454
|
-
end
|
455
|
-
end
|