google-cloud-vision 0.28.0 → 0.29.0
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.
- checksums.yaml +4 -4
- data/README.md +29 -0
- data/lib/google/cloud/vision.rb +33 -0
- data/lib/google/cloud/vision/v1.rb +42 -16
- data/lib/google/cloud/vision/v1/credentials.rb +33 -0
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/geometry.rb +15 -1
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/image_annotator.rb +224 -46
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/text_annotation.rb +36 -14
- data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/web_detection.rb +34 -7
- data/lib/google/cloud/vision/v1/doc/google/longrunning/operations.rb +92 -0
- data/lib/google/cloud/vision/v1/doc/google/protobuf/any.rb +1 -1
- data/lib/google/cloud/vision/v1/doc/google/protobuf/wrappers.rb +1 -1
- data/lib/google/cloud/vision/v1/doc/google/rpc/status.rb +1 -1
- data/lib/google/cloud/vision/v1/doc/google/type/color.rb +1 -1
- data/lib/google/cloud/vision/v1/doc/google/type/latlng.rb +1 -1
- data/lib/google/cloud/vision/v1/doc/overview.rb +32 -6
- data/lib/google/cloud/vision/v1/geometry_pb.rb +6 -0
- data/lib/google/cloud/vision/v1/image_annotator_client.rb +124 -27
- data/lib/google/cloud/vision/v1/image_annotator_client_config.json +5 -0
- data/lib/google/cloud/vision/v1/image_annotator_pb.rb +72 -0
- data/lib/google/cloud/vision/v1/image_annotator_services_pb.rb +9 -2
- data/lib/google/cloud/vision/v1/text_annotation_pb.rb +5 -0
- data/lib/google/cloud/vision/v1/web_detection_pb.rb +10 -0
- data/lib/google/cloud/vision/version.rb +1 -1
- metadata +5 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2018 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -20,9 +20,9 @@ module Google
|
|
20
20
|
# The hierarchy of an OCR extracted text structure is like this:
|
21
21
|
# TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol
|
22
22
|
# Each structural component, starting from Page, may further have their own
|
23
|
-
# properties. Properties describe detected languages, breaks etc.. Please
|
24
|
-
#
|
25
|
-
#
|
23
|
+
# properties. Properties describe detected languages, breaks etc.. Please refer
|
24
|
+
# to the {Google::Cloud::Vision::V1::TextAnnotation::TextProperty TextAnnotation::TextProperty} message definition below for more
|
25
|
+
# detail.
|
26
26
|
# @!attribute [rw] pages
|
27
27
|
# @return [Array<Google::Cloud::Vision::V1::Page>]
|
28
28
|
# List of pages detected by OCR.
|
@@ -44,6 +44,7 @@ module Google
|
|
44
44
|
# Detected start or end of a structural component.
|
45
45
|
# @!attribute [rw] type
|
46
46
|
# @return [Google::Cloud::Vision::V1::TextAnnotation::DetectedBreak::BreakType]
|
47
|
+
# Detected break type.
|
47
48
|
# @!attribute [rw] is_prefix
|
48
49
|
# @return [true, false]
|
49
50
|
# True if break prepends the element.
|
@@ -62,11 +63,10 @@ module Google
|
|
62
63
|
# Line-wrapping break.
|
63
64
|
EOL_SURE_SPACE = 3
|
64
65
|
|
65
|
-
# End-line hyphen that is not present in text; does
|
66
|
+
# End-line hyphen that is not present in text; does not co-occur with
|
67
|
+
# +SPACE+, +LEADER_SPACE+, or +LINE_BREAK+.
|
66
68
|
HYPHEN = 4
|
67
69
|
|
68
|
-
# not co-occur with SPACE, LEADER_SPACE, or
|
69
|
-
# LINE_BREAK.
|
70
70
|
# Line break that ends a paragraph.
|
71
71
|
LINE_BREAK = 5
|
72
72
|
end
|
@@ -88,13 +88,18 @@ module Google
|
|
88
88
|
# Additional information detected on the page.
|
89
89
|
# @!attribute [rw] width
|
90
90
|
# @return [Integer]
|
91
|
-
# Page width
|
91
|
+
# Page width. For PDFs the unit is points. For images (including
|
92
|
+
# TIFFs) the unit is pixels.
|
92
93
|
# @!attribute [rw] height
|
93
94
|
# @return [Integer]
|
94
|
-
# Page height
|
95
|
+
# Page height. For PDFs the unit is points. For images (including
|
96
|
+
# TIFFs) the unit is pixels.
|
95
97
|
# @!attribute [rw] blocks
|
96
98
|
# @return [Array<Google::Cloud::Vision::V1::Block>]
|
97
99
|
# List of blocks of text, images etc on this page.
|
100
|
+
# @!attribute [rw] confidence
|
101
|
+
# @return [Float]
|
102
|
+
# Confidence of the OCR results on the page. Range [0, 1].
|
98
103
|
class Page; end
|
99
104
|
|
100
105
|
# Logical element on the page.
|
@@ -109,21 +114,29 @@ module Google
|
|
109
114
|
# is represented as around the top-left corner as defined when the text is
|
110
115
|
# read in the 'natural' orientation.
|
111
116
|
# For example:
|
117
|
+
#
|
112
118
|
# * when the text is horizontal it might look like:
|
119
|
+
#
|
113
120
|
# 0----1
|
114
121
|
# | |
|
115
122
|
# 3----2
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
123
|
+
#
|
124
|
+
# * when it's rotated 180 degrees around the top-left corner it becomes:
|
125
|
+
#
|
126
|
+
# 2----3
|
127
|
+
# | |
|
128
|
+
# 1----0
|
129
|
+
#
|
130
|
+
# and the vertice order will still be (0, 1, 2, 3).
|
121
131
|
# @!attribute [rw] paragraphs
|
122
132
|
# @return [Array<Google::Cloud::Vision::V1::Paragraph>]
|
123
133
|
# List of paragraphs in this block (if this blocks is of type text).
|
124
134
|
# @!attribute [rw] block_type
|
125
135
|
# @return [Google::Cloud::Vision::V1::Block::BlockType]
|
126
136
|
# Detected block type (text, image etc) for this block.
|
137
|
+
# @!attribute [rw] confidence
|
138
|
+
# @return [Float]
|
139
|
+
# Confidence of the OCR results on the block. Range [0, 1].
|
127
140
|
class Block
|
128
141
|
# Type of a block (text, image etc) as identified by OCR.
|
129
142
|
module BlockType
|
@@ -171,6 +184,9 @@ module Google
|
|
171
184
|
# @!attribute [rw] words
|
172
185
|
# @return [Array<Google::Cloud::Vision::V1::Word>]
|
173
186
|
# List of words in this paragraph.
|
187
|
+
# @!attribute [rw] confidence
|
188
|
+
# @return [Float]
|
189
|
+
# Confidence of the OCR results for the paragraph. Range [0, 1].
|
174
190
|
class Paragraph; end
|
175
191
|
|
176
192
|
# A word representation.
|
@@ -198,6 +214,9 @@ module Google
|
|
198
214
|
# @return [Array<Google::Cloud::Vision::V1::Symbol>]
|
199
215
|
# List of symbols in the word.
|
200
216
|
# The order of the symbols follows the natural reading order.
|
217
|
+
# @!attribute [rw] confidence
|
218
|
+
# @return [Float]
|
219
|
+
# Confidence of the OCR results for the word. Range [0, 1].
|
201
220
|
class Word; end
|
202
221
|
|
203
222
|
# A single symbol representation.
|
@@ -224,6 +243,9 @@ module Google
|
|
224
243
|
# @!attribute [rw] text
|
225
244
|
# @return [String]
|
226
245
|
# The actual UTF-8 representation of the symbol.
|
246
|
+
# @!attribute [rw] confidence
|
247
|
+
# @return [Float]
|
248
|
+
# Confidence of the OCR results for the symbol. Range [0, 1].
|
227
249
|
class Symbol; end
|
228
250
|
end
|
229
251
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2018 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -23,8 +23,7 @@ module Google
|
|
23
23
|
# @!attribute [rw] full_matching_images
|
24
24
|
# @return [Array<Google::Cloud::Vision::V1::WebDetection::WebImage>]
|
25
25
|
# Fully matching images from the Internet.
|
26
|
-
#
|
27
|
-
# merely a size change.
|
26
|
+
# Can include resized copies of the query image.
|
28
27
|
# @!attribute [rw] partial_matching_images
|
29
28
|
# @return [Array<Google::Cloud::Vision::V1::WebDetection::WebImage>]
|
30
29
|
# Partial matching images from the Internet.
|
@@ -33,6 +32,12 @@ module Google
|
|
33
32
|
# @!attribute [rw] pages_with_matching_images
|
34
33
|
# @return [Array<Google::Cloud::Vision::V1::WebDetection::WebPage>]
|
35
34
|
# Web pages containing the matching images from the Internet.
|
35
|
+
# @!attribute [rw] visually_similar_images
|
36
|
+
# @return [Array<Google::Cloud::Vision::V1::WebDetection::WebImage>]
|
37
|
+
# The visually similar image results.
|
38
|
+
# @!attribute [rw] best_guess_labels
|
39
|
+
# @return [Array<Google::Cloud::Vision::V1::WebDetection::WebLabel>]
|
40
|
+
# Best guess text labels for the request image.
|
36
41
|
class WebDetection
|
37
42
|
# Entity deduced from similar images on the Internet.
|
38
43
|
# @!attribute [rw] entity_id
|
@@ -53,8 +58,7 @@ module Google
|
|
53
58
|
# The result image URL.
|
54
59
|
# @!attribute [rw] score
|
55
60
|
# @return [Float]
|
56
|
-
# Overall relevancy score for the image.
|
57
|
-
# Not normalized and not comparable across different image queries.
|
61
|
+
# (Deprecated) Overall relevancy score for the image.
|
58
62
|
class WebImage; end
|
59
63
|
|
60
64
|
# Metadata for web pages.
|
@@ -63,9 +67,32 @@ module Google
|
|
63
67
|
# The result web page URL.
|
64
68
|
# @!attribute [rw] score
|
65
69
|
# @return [Float]
|
66
|
-
# Overall relevancy score for the web page.
|
67
|
-
#
|
70
|
+
# (Deprecated) Overall relevancy score for the web page.
|
71
|
+
# @!attribute [rw] page_title
|
72
|
+
# @return [String]
|
73
|
+
# Title for the web page, may contain HTML markups.
|
74
|
+
# @!attribute [rw] full_matching_images
|
75
|
+
# @return [Array<Google::Cloud::Vision::V1::WebDetection::WebImage>]
|
76
|
+
# Fully matching images on the page.
|
77
|
+
# Can include resized copies of the query image.
|
78
|
+
# @!attribute [rw] partial_matching_images
|
79
|
+
# @return [Array<Google::Cloud::Vision::V1::WebDetection::WebImage>]
|
80
|
+
# Partial matching images on the page.
|
81
|
+
# Those images are similar enough to share some key-point features. For
|
82
|
+
# example an original image will likely have partial matching for its
|
83
|
+
# crops.
|
68
84
|
class WebPage; end
|
85
|
+
|
86
|
+
# Label to provide extra metadata for the web detection.
|
87
|
+
# @!attribute [rw] label
|
88
|
+
# @return [String]
|
89
|
+
# Label for extra metadata.
|
90
|
+
# @!attribute [rw] language_code
|
91
|
+
# @return [String]
|
92
|
+
# The BCP-47 language code for +label+, such as "en-US" or "sr-Latn".
|
93
|
+
# For more information, see
|
94
|
+
# http://www.unicode.org/reports/tr35/#Unicode_locale_identifier.
|
95
|
+
class WebLabel; end
|
69
96
|
end
|
70
97
|
end
|
71
98
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# Copyright 2018 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
|
+
module Google
|
16
|
+
module Longrunning
|
17
|
+
# This resource represents a long-running operation that is the result of a
|
18
|
+
# network API call.
|
19
|
+
# @!attribute [rw] name
|
20
|
+
# @return [String]
|
21
|
+
# The server-assigned name, which is only unique within the same service that
|
22
|
+
# originally returns it. If you use the default HTTP mapping, the
|
23
|
+
# +name+ should have the format of +operations/some/unique/name+.
|
24
|
+
# @!attribute [rw] metadata
|
25
|
+
# @return [Google::Protobuf::Any]
|
26
|
+
# Service-specific metadata associated with the operation. It typically
|
27
|
+
# contains progress information and common metadata such as create time.
|
28
|
+
# Some services might not provide such metadata. Any method that returns a
|
29
|
+
# long-running operation should document the metadata type, if any.
|
30
|
+
# @!attribute [rw] done
|
31
|
+
# @return [true, false]
|
32
|
+
# If the value is +false+, it means the operation is still in progress.
|
33
|
+
# If true, the operation is completed, and either +error+ or +response+ is
|
34
|
+
# available.
|
35
|
+
# @!attribute [rw] error
|
36
|
+
# @return [Google::Rpc::Status]
|
37
|
+
# The error result of the operation in case of failure or cancellation.
|
38
|
+
# @!attribute [rw] response
|
39
|
+
# @return [Google::Protobuf::Any]
|
40
|
+
# The normal response of the operation in case of success. If the original
|
41
|
+
# method returns no data on success, such as +Delete+, the response is
|
42
|
+
# +google.protobuf.Empty+. If the original method is standard
|
43
|
+
# +Get+/+Create+/+Update+, the response should be the resource. For other
|
44
|
+
# methods, the response should have the type +XxxResponse+, where +Xxx+
|
45
|
+
# is the original method name. For example, if the original method name
|
46
|
+
# is +TakeSnapshot()+, the inferred response type is
|
47
|
+
# +TakeSnapshotResponse+.
|
48
|
+
class Operation; end
|
49
|
+
|
50
|
+
# The request message for {Google::Longrunning::Operations::GetOperation Operations::GetOperation}.
|
51
|
+
# @!attribute [rw] name
|
52
|
+
# @return [String]
|
53
|
+
# The name of the operation resource.
|
54
|
+
class GetOperationRequest; end
|
55
|
+
|
56
|
+
# The request message for {Google::Longrunning::Operations::ListOperations Operations::ListOperations}.
|
57
|
+
# @!attribute [rw] name
|
58
|
+
# @return [String]
|
59
|
+
# The name of the operation collection.
|
60
|
+
# @!attribute [rw] filter
|
61
|
+
# @return [String]
|
62
|
+
# The standard list filter.
|
63
|
+
# @!attribute [rw] page_size
|
64
|
+
# @return [Integer]
|
65
|
+
# The standard list page size.
|
66
|
+
# @!attribute [rw] page_token
|
67
|
+
# @return [String]
|
68
|
+
# The standard list page token.
|
69
|
+
class ListOperationsRequest; end
|
70
|
+
|
71
|
+
# The response message for {Google::Longrunning::Operations::ListOperations Operations::ListOperations}.
|
72
|
+
# @!attribute [rw] operations
|
73
|
+
# @return [Array<Google::Longrunning::Operation>]
|
74
|
+
# A list of operations that matches the specified filter in the request.
|
75
|
+
# @!attribute [rw] next_page_token
|
76
|
+
# @return [String]
|
77
|
+
# The standard List next-page token.
|
78
|
+
class ListOperationsResponse; end
|
79
|
+
|
80
|
+
# The request message for {Google::Longrunning::Operations::CancelOperation Operations::CancelOperation}.
|
81
|
+
# @!attribute [rw] name
|
82
|
+
# @return [String]
|
83
|
+
# The name of the operation resource to be cancelled.
|
84
|
+
class CancelOperationRequest; end
|
85
|
+
|
86
|
+
# The request message for {Google::Longrunning::Operations::DeleteOperation Operations::DeleteOperation}.
|
87
|
+
# @!attribute [rw] name
|
88
|
+
# @return [String]
|
89
|
+
# The name of the operation resource to be deleted.
|
90
|
+
class DeleteOperationRequest; end
|
91
|
+
end
|
92
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2018 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -17,9 +17,9 @@ module Google
|
|
17
17
|
# rubocop:disable LineLength
|
18
18
|
|
19
19
|
##
|
20
|
-
# # Ruby Client for
|
20
|
+
# # Ruby Client for Cloud Vision API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
|
21
21
|
#
|
22
|
-
# [
|
22
|
+
# [Cloud Vision API][Product Documentation]:
|
23
23
|
# Integrates Google Vision features, including image labeling, face, logo, and
|
24
24
|
# landmark detection, optical character recognition (OCR), and detection of
|
25
25
|
# explicit content, into applications.
|
@@ -30,8 +30,9 @@ module Google
|
|
30
30
|
# steps:
|
31
31
|
#
|
32
32
|
# 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
|
33
|
-
# 2. [Enable
|
34
|
-
# 3. [
|
33
|
+
# 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
|
34
|
+
# 3. [Enable the Cloud Vision API.](https://console.cloud.google.com/apis/api/vision)
|
35
|
+
# 4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
|
35
36
|
#
|
36
37
|
# ### Installation
|
37
38
|
# ```
|
@@ -56,13 +57,38 @@ module Google
|
|
56
57
|
# ```
|
57
58
|
#
|
58
59
|
# ### Next Steps
|
59
|
-
# - Read the [
|
60
|
+
# - Read the [Cloud Vision API Product documentation][Product Documentation]
|
60
61
|
# to learn more about the product and see How-to Guides.
|
61
62
|
# - View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
|
62
63
|
# to see the full list of Cloud APIs that we cover.
|
63
64
|
#
|
64
65
|
# [Product Documentation]: https://cloud.google.com/vision
|
65
66
|
#
|
67
|
+
# ## Enabling Logging
|
68
|
+
#
|
69
|
+
# To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
|
70
|
+
# The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below,
|
71
|
+
# or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
|
72
|
+
# that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
|
73
|
+
# and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
|
74
|
+
#
|
75
|
+
# Configuring a Ruby stdlib logger:
|
76
|
+
#
|
77
|
+
# ```ruby
|
78
|
+
# require "logger"
|
79
|
+
#
|
80
|
+
# module MyLogger
|
81
|
+
# LOGGER = Logger.new $stderr, level: Logger::WARN
|
82
|
+
# def logger
|
83
|
+
# LOGGER
|
84
|
+
# end
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
|
88
|
+
# module GRPC
|
89
|
+
# extend MyLogger
|
90
|
+
# end
|
91
|
+
# ```
|
66
92
|
#
|
67
93
|
module Vision
|
68
94
|
module V1
|
@@ -8,8 +8,13 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
8
8
|
optional :x, :int32, 1
|
9
9
|
optional :y, :int32, 2
|
10
10
|
end
|
11
|
+
add_message "google.cloud.vision.v1.NormalizedVertex" do
|
12
|
+
optional :x, :float, 1
|
13
|
+
optional :y, :float, 2
|
14
|
+
end
|
11
15
|
add_message "google.cloud.vision.v1.BoundingPoly" do
|
12
16
|
repeated :vertices, :message, 1, "google.cloud.vision.v1.Vertex"
|
17
|
+
repeated :normalized_vertices, :message, 2, "google.cloud.vision.v1.NormalizedVertex"
|
13
18
|
end
|
14
19
|
add_message "google.cloud.vision.v1.Position" do
|
15
20
|
optional :x, :float, 1
|
@@ -23,6 +28,7 @@ module Google
|
|
23
28
|
module Vision
|
24
29
|
module V1
|
25
30
|
Vertex = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1.Vertex").msgclass
|
31
|
+
NormalizedVertex = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1.NormalizedVertex").msgclass
|
26
32
|
BoundingPoly = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1.BoundingPoly").msgclass
|
27
33
|
Position = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.vision.v1.Position").msgclass
|
28
34
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2018 Google LLC
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -18,17 +18,16 @@
|
|
18
18
|
# and updates to that file get reflected here through a refresh process.
|
19
19
|
# For the short term, the refresh process will only be runnable by Google
|
20
20
|
# engineers.
|
21
|
-
#
|
22
|
-
# The only allowed edits are to method and file documentation. A 3-way
|
23
|
-
# merge preserves those additions if the generated source changes.
|
24
21
|
|
25
22
|
require "json"
|
26
23
|
require "pathname"
|
27
24
|
|
28
25
|
require "google/gax"
|
26
|
+
require "google/gax/operation"
|
27
|
+
require "google/longrunning/operations_client"
|
29
28
|
|
30
29
|
require "google/cloud/vision/v1/image_annotator_pb"
|
31
|
-
require "google/cloud/vision/credentials"
|
30
|
+
require "google/cloud/vision/v1/credentials"
|
32
31
|
|
33
32
|
module Google
|
34
33
|
module Cloud
|
@@ -49,6 +48,9 @@ module Google
|
|
49
48
|
# The default port of the service.
|
50
49
|
DEFAULT_SERVICE_PORT = 443
|
51
50
|
|
51
|
+
# The default set of gRPC interceptors.
|
52
|
+
GRPC_INTERCEPTORS = []
|
53
|
+
|
52
54
|
DEFAULT_TIMEOUT = 30
|
53
55
|
|
54
56
|
# The scopes needed to make gRPC calls to all of the methods defined in
|
@@ -58,6 +60,11 @@ module Google
|
|
58
60
|
"https://www.googleapis.com/auth/cloud-vision"
|
59
61
|
].freeze
|
60
62
|
|
63
|
+
class OperationsClient < Google::Longrunning::OperationsClient
|
64
|
+
self::SERVICE_ADDRESS = ImageAnnotatorClient::SERVICE_ADDRESS
|
65
|
+
self::GRPC_INTERCEPTORS = ImageAnnotatorClient::GRPC_INTERCEPTORS
|
66
|
+
end
|
67
|
+
|
61
68
|
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
62
69
|
# Provides the means for authenticating requests made by the client. This parameter can
|
63
70
|
# be many types.
|
@@ -82,16 +89,18 @@ module Google
|
|
82
89
|
# or the specified config is missing data points.
|
83
90
|
# @param timeout [Numeric]
|
84
91
|
# The default timeout, in seconds, for calls made through this client.
|
92
|
+
# @param metadata [Hash]
|
93
|
+
# Default metadata to be sent with each request. This can be overridden on a per call basis.
|
94
|
+
# @param exception_transformer [Proc]
|
95
|
+
# An optional proc that intercepts any exceptions raised during an API call to inject
|
96
|
+
# custom error handling.
|
85
97
|
def initialize \
|
86
|
-
service_path: SERVICE_ADDRESS,
|
87
|
-
port: DEFAULT_SERVICE_PORT,
|
88
|
-
channel: nil,
|
89
|
-
chan_creds: nil,
|
90
|
-
updater_proc: nil,
|
91
98
|
credentials: nil,
|
92
99
|
scopes: ALL_SCOPES,
|
93
100
|
client_config: {},
|
94
101
|
timeout: DEFAULT_TIMEOUT,
|
102
|
+
metadata: nil,
|
103
|
+
exception_transformer: nil,
|
95
104
|
lib_name: nil,
|
96
105
|
lib_version: ""
|
97
106
|
# These require statements are intentionally placed here to initialize
|
@@ -100,21 +109,19 @@ module Google
|
|
100
109
|
require "google/gax/grpc"
|
101
110
|
require "google/cloud/vision/v1/image_annotator_services_pb"
|
102
111
|
|
103
|
-
|
104
|
-
warn "The `channel`, `chan_creds`, and `updater_proc` parameters will be removed " \
|
105
|
-
"on 2017/09/08"
|
106
|
-
credentials ||= channel
|
107
|
-
credentials ||= chan_creds
|
108
|
-
credentials ||= updater_proc
|
109
|
-
end
|
110
|
-
if service_path != SERVICE_ADDRESS || port != DEFAULT_SERVICE_PORT
|
111
|
-
warn "`service_path` and `port` parameters are deprecated and will be removed"
|
112
|
-
end
|
112
|
+
credentials ||= Google::Cloud::Vision::V1::Credentials.default
|
113
113
|
|
114
|
-
|
114
|
+
@operations_client = OperationsClient.new(
|
115
|
+
credentials: credentials,
|
116
|
+
scopes: scopes,
|
117
|
+
client_config: client_config,
|
118
|
+
timeout: timeout,
|
119
|
+
lib_name: lib_name,
|
120
|
+
lib_version: lib_version,
|
121
|
+
)
|
115
122
|
|
116
123
|
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
117
|
-
updater_proc = Google::Cloud::Vision::Credentials.new(credentials).updater_proc
|
124
|
+
updater_proc = Google::Cloud::Vision::V1::Credentials.new(credentials).updater_proc
|
118
125
|
end
|
119
126
|
if credentials.is_a?(GRPC::Core::Channel)
|
120
127
|
channel = credentials
|
@@ -129,13 +136,16 @@ module Google
|
|
129
136
|
updater_proc = credentials.updater_proc
|
130
137
|
end
|
131
138
|
|
139
|
+
package_version = Gem.loaded_specs['google-cloud-vision'].version.version
|
140
|
+
|
132
141
|
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
133
142
|
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
134
|
-
google_api_client << " gapic
|
143
|
+
google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
|
135
144
|
google_api_client << " grpc/#{GRPC::VERSION}"
|
136
145
|
google_api_client.freeze
|
137
146
|
|
138
147
|
headers = { :"x-goog-api-client" => google_api_client }
|
148
|
+
headers.merge!(metadata) unless metadata.nil?
|
139
149
|
client_config_file = Pathname.new(__dir__).join(
|
140
150
|
"image_annotator_client_config.json"
|
141
151
|
)
|
@@ -147,9 +157,14 @@ module Google
|
|
147
157
|
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
148
158
|
timeout,
|
149
159
|
errors: Google::Gax::Grpc::API_ERRORS,
|
150
|
-
|
160
|
+
metadata: headers
|
151
161
|
)
|
152
162
|
end
|
163
|
+
|
164
|
+
# Allow overriding the service path/port in subclasses.
|
165
|
+
service_path = self.class::SERVICE_ADDRESS
|
166
|
+
port = self.class::DEFAULT_SERVICE_PORT
|
167
|
+
interceptors = self.class::GRPC_INTERCEPTORS
|
153
168
|
@image_annotator_stub = Google::Gax::Grpc.create_stub(
|
154
169
|
service_path,
|
155
170
|
port,
|
@@ -157,12 +172,19 @@ module Google
|
|
157
172
|
channel: channel,
|
158
173
|
updater_proc: updater_proc,
|
159
174
|
scopes: scopes,
|
175
|
+
interceptors: interceptors,
|
160
176
|
&Google::Cloud::Vision::V1::ImageAnnotator::Stub.method(:new)
|
161
177
|
)
|
162
178
|
|
163
179
|
@batch_annotate_images = Google::Gax.create_api_call(
|
164
180
|
@image_annotator_stub.method(:batch_annotate_images),
|
165
|
-
defaults["batch_annotate_images"]
|
181
|
+
defaults["batch_annotate_images"],
|
182
|
+
exception_transformer: exception_transformer
|
183
|
+
)
|
184
|
+
@async_batch_annotate_files = Google::Gax.create_api_call(
|
185
|
+
@image_annotator_stub.method(:async_batch_annotate_files),
|
186
|
+
defaults["async_batch_annotate_files"],
|
187
|
+
exception_transformer: exception_transformer
|
166
188
|
)
|
167
189
|
end
|
168
190
|
|
@@ -177,23 +199,98 @@ module Google
|
|
177
199
|
# @param options [Google::Gax::CallOptions]
|
178
200
|
# Overrides the default settings for this call, e.g, timeout,
|
179
201
|
# retries, etc.
|
202
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
203
|
+
# @yieldparam result [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse]
|
204
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
180
205
|
# @return [Google::Cloud::Vision::V1::BatchAnnotateImagesResponse]
|
181
206
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
182
207
|
# @example
|
183
208
|
# require "google/cloud/vision/v1"
|
184
209
|
#
|
185
210
|
# image_annotator_client = Google::Cloud::Vision::V1.new
|
211
|
+
#
|
212
|
+
# # TODO: Initialize +requests+:
|
186
213
|
# requests = []
|
187
214
|
# response = image_annotator_client.batch_annotate_images(requests)
|
188
215
|
|
189
216
|
def batch_annotate_images \
|
190
217
|
requests,
|
191
|
-
options: nil
|
218
|
+
options: nil,
|
219
|
+
&block
|
192
220
|
req = {
|
193
221
|
requests: requests
|
194
222
|
}.delete_if { |_, v| v.nil? }
|
195
223
|
req = Google::Gax::to_proto(req, Google::Cloud::Vision::V1::BatchAnnotateImagesRequest)
|
196
|
-
@batch_annotate_images.call(req, options)
|
224
|
+
@batch_annotate_images.call(req, options, &block)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Run asynchronous image detection and annotation for a list of generic
|
228
|
+
# files, such as PDF files, which may contain multiple pages and multiple
|
229
|
+
# images per page. Progress and results can be retrieved through the
|
230
|
+
# +google.longrunning.Operations+ interface.
|
231
|
+
# +Operation.metadata+ contains +OperationMetadata+ (metadata).
|
232
|
+
# +Operation.response+ contains +AsyncBatchAnnotateFilesResponse+ (results).
|
233
|
+
#
|
234
|
+
# @param requests [Array<Google::Cloud::Vision::V1::AsyncAnnotateFileRequest | Hash>]
|
235
|
+
# Individual async file annotation requests for this batch.
|
236
|
+
# A hash of the same form as `Google::Cloud::Vision::V1::AsyncAnnotateFileRequest`
|
237
|
+
# can also be provided.
|
238
|
+
# @param options [Google::Gax::CallOptions]
|
239
|
+
# Overrides the default settings for this call, e.g, timeout,
|
240
|
+
# retries, etc.
|
241
|
+
# @return [Google::Gax::Operation]
|
242
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
243
|
+
# @example
|
244
|
+
# require "google/cloud/vision/v1"
|
245
|
+
#
|
246
|
+
# image_annotator_client = Google::Cloud::Vision::V1.new
|
247
|
+
#
|
248
|
+
# # TODO: Initialize +requests+:
|
249
|
+
# requests = []
|
250
|
+
#
|
251
|
+
# # Register a callback during the method call.
|
252
|
+
# operation = image_annotator_client.async_batch_annotate_files(requests) do |op|
|
253
|
+
# raise op.results.message if op.error?
|
254
|
+
# op_results = op.results
|
255
|
+
# # Process the results.
|
256
|
+
#
|
257
|
+
# metadata = op.metadata
|
258
|
+
# # Process the metadata.
|
259
|
+
# end
|
260
|
+
#
|
261
|
+
# # Or use the return value to register a callback.
|
262
|
+
# operation.on_done do |op|
|
263
|
+
# raise op.results.message if op.error?
|
264
|
+
# op_results = op.results
|
265
|
+
# # Process the results.
|
266
|
+
#
|
267
|
+
# metadata = op.metadata
|
268
|
+
# # Process the metadata.
|
269
|
+
# end
|
270
|
+
#
|
271
|
+
# # Manually reload the operation.
|
272
|
+
# operation.reload!
|
273
|
+
#
|
274
|
+
# # Or block until the operation completes, triggering callbacks on
|
275
|
+
# # completion.
|
276
|
+
# operation.wait_until_done!
|
277
|
+
|
278
|
+
def async_batch_annotate_files \
|
279
|
+
requests,
|
280
|
+
options: nil
|
281
|
+
req = {
|
282
|
+
requests: requests
|
283
|
+
}.delete_if { |_, v| v.nil? }
|
284
|
+
req = Google::Gax::to_proto(req, Google::Cloud::Vision::V1::AsyncBatchAnnotateFilesRequest)
|
285
|
+
operation = Google::Gax::Operation.new(
|
286
|
+
@async_batch_annotate_files.call(req, options),
|
287
|
+
@operations_client,
|
288
|
+
Google::Cloud::Vision::V1::AsyncBatchAnnotateFilesResponse,
|
289
|
+
Google::Cloud::Vision::V1::OperationMetadata,
|
290
|
+
call_options: options
|
291
|
+
)
|
292
|
+
operation.on_done { |operation| yield(operation) } if block_given?
|
293
|
+
operation
|
197
294
|
end
|
198
295
|
end
|
199
296
|
end
|