Class: Gcloud::Vision::Annotation::Entity
- Inherits:
-
Object
- Object
- Gcloud::Vision::Annotation::Entity
- Defined in:
- lib/gcloud/vision/annotation/entity.rb
Overview
# Entity
Represents characteristics of an entity detected in an image. May describe a real-world entity such as a person, place, or thing. May be identified with an entity ID as an entity in the Knowledge Graph (KG).
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#bounds ⇒ Array<Vertex>
Image region to which this entity belongs.
-
#confidence ⇒ Float
The accuracy of the entity detection in an image.
-
#description ⇒ String
Entity textual description, expressed in the #locale language.
-
#initialize ⇒ Entity
constructor
A new instance of Entity.
- #inspect ⇒ Object
-
#locale ⇒ String
The language code for the locale in which the ‘description` is expressed.
-
#locations ⇒ Array<Location>
The location information for the detected entity.
-
#mid ⇒ String
Opaque entity ID.
-
#properties ⇒ Hash
Some entities can have additional optional Property fields.
-
#score ⇒ Float
Overall score of the result.
-
#to_h ⇒ Hash
Deeply converts object to a hash.
-
#to_hash ⇒ Hash
Deeply converts object to a hash.
- #to_s ⇒ Object
-
#topicality ⇒ Float
The relevancy of the ICA (Image Content Annotation) label to the image.
Constructor Details
#initialize ⇒ Entity
Returns a new instance of Entity.
80 81 82 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 80 def initialize @gapi = {} end |
Instance Attribute Details
#gapi ⇒ Object
76 77 78 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 76 def gapi @gapi end |
Class Method Details
.from_gapi(gapi) ⇒ Object
228 229 230 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 228 def self.from_gapi gapi new.tap { |f| f.instance_variable_set :@gapi, gapi } end |
Instance Method Details
#bounds ⇒ Array<Vertex>
Image region to which this entity belongs. Not filled currently for ‘labels` detection.
155 156 157 158 159 160 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 155 def bounds return [] unless @gapi.bounding_poly @bounds ||= Array(@gapi.bounding_poly.vertices).map do |v| Vertex.from_gapi v end end |
#confidence ⇒ Float
The accuracy of the entity detection in an image. For example, for an image containing ‘Eiffel Tower,’ this field represents the confidence that there is a tower in the query image.
132 133 134 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 132 def confidence @gapi.confidence end |
#description ⇒ String
Entity textual description, expressed in the #locale language.
112 113 114 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 112 def description @gapi.description end |
#inspect ⇒ Object
222 223 224 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 222 def inspect "#<#{self.class.name} #{self}>" end |
#locale ⇒ String
The language code for the locale in which the ‘description` is expressed.
103 104 105 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 103 def locale @gapi.locale end |
#locations ⇒ Array<Location>
The location information for the detected entity. Multiple Location elements can be present since one location may indicate the location of the scene in the query image, and another the location of the place where the query image was taken. Location information is usually present for landmarks.
172 173 174 175 176 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 172 def locations @locations ||= Array(@gapi.locations).map do |l| Location.from_gapi l.lat_lng end end |
#mid ⇒ String
Opaque entity ID. Some IDs might be available in Knowledge Graph (KG).
91 92 93 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 91 def mid @gapi.mid end |
#properties ⇒ Hash
Some entities can have additional optional Property fields. For example a different kind of score or string that qualifies the entity. present for landmarks.
185 186 187 188 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 185 def properties @properties ||= Hash[Array(@gapi.properties).map { |p| [p.name, p.value] }] end |
#score ⇒ Float
Overall score of the result.
121 122 123 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 121 def score @gapi.score end |
#to_h ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
195 196 197 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 195 def to_h to_hash end |
#to_hash ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
204 205 206 207 208 209 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 204 def to_hash { mid: mid, locale: locale, description: description, score: score, confidence: confidence, topicality: topicality, bounds: bounds.map(&:to_h), locations: locations.map(&:to_h), properties: properties } end |
#to_s ⇒ Object
212 213 214 215 216 217 218 219 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 212 def to_s tmplt = "mid: %s, locale: %s, description: %s, score: %s, " \ "confidence: %s, topicality: %s, bounds: %i, " \ "locations: %i, properties: %s" format tmplt, mid.inspect, locale.inspect, description.inspect, score.inspect, confidence.inspect, topicality.inspect, bounds.count, locations.count, properties.inspect end |
#topicality ⇒ Float
The relevancy of the ICA (Image Content Annotation) label to the image. For example, the relevancy of ‘tower’ to an image containing ‘Eiffel Tower’ is likely higher than an image containing a distant towering building, though the confidence that there is a tower may be the same.
145 146 147 |
# File 'lib/gcloud/vision/annotation/entity.rb', line 145 def topicality @gapi.topicality end |