Class: Gcloud::Vision::Annotation
- Inherits:
-
Object
- Object
- Gcloud::Vision::Annotation
- Defined in:
- lib/gcloud/vision/annotation.rb,
lib/gcloud/vision/annotation/face.rb,
lib/gcloud/vision/annotation/text.rb,
lib/gcloud/vision/annotation/entity.rb,
lib/gcloud/vision/annotation/vertex.rb,
lib/gcloud/vision/annotation/properties.rb,
lib/gcloud/vision/annotation/safe_search.rb
Overview
Defined Under Namespace
Classes: Entity, Face, Properties, SafeSearch, Text, Vertex
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#face ⇒ Face
The first face result, if there is one.
-
#face? ⇒ Boolean
Whether there is at least one result from face detection.
-
#faces ⇒ Array<Face>
The results of face detection.
-
#initialize ⇒ Annotation
constructor
A new instance of Annotation.
- #inspect ⇒ Object
-
#label ⇒ Entity
The first label result, if there is one.
-
#label? ⇒ Boolean
Whether there is at least one result from label detection.
-
#labels ⇒ Array<Entity>
The results of label detection.
-
#landmark ⇒ Entity
The first landmark result, if there is one.
-
#landmark? ⇒ Boolean
Whether there is at least one result from landmark detection.
-
#landmarks ⇒ Array<Entity>
The results of landmark detection.
-
#logo ⇒ Entity
The first logo result, if there is one.
-
#logo? ⇒ Boolean
Whether there is at least one result from logo detection.
-
#logos ⇒ Array<Entity>
The results of logo detection.
-
#properties ⇒ Properties
The results of properties detection.
-
#properties? ⇒ Boolean
Whether there is a result for properties detection.
-
#safe_search ⇒ SafeSearch
The results of safe_search detection.
-
#safe_search? ⇒ Boolean
Whether there is a result for safe_search detection.
-
#text ⇒ Text
The results of text (OCR) detection.
-
#text? ⇒ Boolean
Whether there is a result from text (OCR) detection.
-
#to_h ⇒ Hash
Deeply converts object to a hash.
-
#to_hash ⇒ Hash
Deeply converts object to a hash.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Annotation
Returns a new instance of Annotation.
50 51 52 |
# File 'lib/gcloud/vision/annotation.rb', line 50 def initialize @gapi = nil end |
Instance Attribute Details
#gapi ⇒ Object
46 47 48 |
# File 'lib/gcloud/vision/annotation.rb', line 46 def gapi @gapi end |
Class Method Details
.from_gapi(gapi) ⇒ Object
450 451 452 |
# File 'lib/gcloud/vision/annotation.rb', line 450 def self.from_gapi gapi new.tap { |a| a.instance_variable_set :@gapi, gapi } end |
Instance Method Details
#face ⇒ Face
The first face result, if there is one.
91 92 93 |
# File 'lib/gcloud/vision/annotation.rb', line 91 def face faces.first end |
#face? ⇒ Boolean
Whether there is at least one result from face detection.
110 111 112 |
# File 'lib/gcloud/vision/annotation.rb', line 110 def face? faces.count > 0 end |
#faces ⇒ Array<Face>
The results of face detection.
70 71 72 73 74 |
# File 'lib/gcloud/vision/annotation.rb', line 70 def faces @faces ||= Array(@gapi["faceAnnotations"]).map do |fa| Face.from_gapi fa end end |
#inspect ⇒ Object
444 445 446 |
# File 'lib/gcloud/vision/annotation.rb', line 444 def inspect "#<#{self.class.name} #{self}>" end |
#label ⇒ Entity
The first label result, if there is one.
273 274 275 |
# File 'lib/gcloud/vision/annotation.rb', line 273 def label labels.first end |
#label? ⇒ Boolean
Whether there is at least one result from label detection. detection.
293 294 295 |
# File 'lib/gcloud/vision/annotation.rb', line 293 def label? labels.count > 0 end |
#labels ⇒ Array<Entity>
The results of label detection.
252 253 254 255 256 |
# File 'lib/gcloud/vision/annotation.rb', line 252 def labels @labels ||= Array(@gapi["labelAnnotations"]).map do |lb| Entity.from_gapi lb end end |
#landmark ⇒ Entity
The first landmark result, if there is one.
151 152 153 |
# File 'lib/gcloud/vision/annotation.rb', line 151 def landmark landmarks.first end |
#landmark? ⇒ Boolean
Whether there is at least one result from landmark detection. detection.
171 172 173 |
# File 'lib/gcloud/vision/annotation.rb', line 171 def landmark? landmarks.count > 0 end |
#landmarks ⇒ Array<Entity>
The results of landmark detection.
130 131 132 133 134 |
# File 'lib/gcloud/vision/annotation.rb', line 130 def landmarks @landmarks ||= Array(@gapi["landmarkAnnotations"]).map do |lm| Entity.from_gapi lm end end |
#logo ⇒ Entity
The first logo result, if there is one.
212 213 214 |
# File 'lib/gcloud/vision/annotation.rb', line 212 def logo logos.first end |
#logo? ⇒ Boolean
Whether there is at least one result from logo detection. detection.
232 233 234 |
# File 'lib/gcloud/vision/annotation.rb', line 232 def logo? logos.count > 0 end |
#logos ⇒ Array<Entity>
The results of logo detection.
191 192 193 194 195 |
# File 'lib/gcloud/vision/annotation.rb', line 191 def logos @logos ||= Array(@gapi["logoAnnotations"]).map do |lg| Entity.from_gapi lg end end |
#properties ⇒ Properties
The results of properties detection.
390 391 392 393 |
# File 'lib/gcloud/vision/annotation.rb', line 390 def properties return nil unless @gapi["imagePropertiesAnnotation"] @properties ||= Properties.from_gapi(@gapi["imagePropertiesAnnotation"]) end |
#properties? ⇒ Boolean
Whether there is a result for properties detection.
410 411 412 |
# File 'lib/gcloud/vision/annotation.rb', line 410 def properties? !properties.nil? end |
#safe_search ⇒ SafeSearch
The results of safe_search detection.
350 351 352 353 |
# File 'lib/gcloud/vision/annotation.rb', line 350 def safe_search return nil unless @gapi["safeSearchAnnotation"] @safe_search ||= SafeSearch.from_gapi(@gapi["safeSearchAnnotation"]) end |
#safe_search? ⇒ Boolean
Whether there is a result for safe_search detection. detection.
371 372 373 |
# File 'lib/gcloud/vision/annotation.rb', line 371 def safe_search? !safe_search.nil? end |
#text ⇒ Text
The results of text (OCR) detection.
312 313 314 |
# File 'lib/gcloud/vision/annotation.rb', line 312 def text @text ||= Text.from_gapi(@gapi["textAnnotations"]) end |
#text? ⇒ Boolean
Whether there is a result from text (OCR) detection.
331 332 333 |
# File 'lib/gcloud/vision/annotation.rb', line 331 def text? !text.nil? end |
#to_h ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
419 420 421 |
# File 'lib/gcloud/vision/annotation.rb', line 419 def to_h to_hash end |
#to_hash ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
428 429 430 431 432 433 |
# File 'lib/gcloud/vision/annotation.rb', line 428 def to_hash { faces: faces.map(&:to_h), landmarks: landmarks.map(&:to_h), logos: logos.map(&:to_h), labels: labels.map(&:to_h), text: text.map(&:to_h), safe_search: safe_search.to_h, properties: properties.to_h } end |
#to_s ⇒ Object
436 437 438 439 440 441 |
# File 'lib/gcloud/vision/annotation.rb', line 436 def to_s tmplt = "(faces: %i, landmarks: %i, logos: %i, labels: %i, text: %s," \ " safe_search: %s, properties: %s)" format tmplt, faces.count, landmarks.count, logos.count, labels.count, text?, safe_search?, properties? end |