Class: Google::Cloud::Vision::Annotation::Entity
- Inherits:
-
Object
- Object
- Google::Cloud::Vision::Annotation::Entity
- Defined in:
- lib/google/cloud/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_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.
78 79 80 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 78 def initialize @grpc = nil end |
Instance Attribute Details
#grpc ⇒ Object
74 75 76 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 74 def grpc @grpc end |
Class Method Details
.from_grpc(grpc) ⇒ Object
218 219 220 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 218 def self.from_grpc grpc new.tap { |f| f.instance_variable_set :@grpc, grpc } end |
Instance Method Details
#bounds ⇒ Array<Vertex>
Image region to which this entity belongs. Not filled currently for ‘labels` detection.
154 155 156 157 158 159 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 154 def bounds return [] unless @grpc.bounding_poly @bounds ||= Array(@grpc.bounding_poly.vertices).map do |v| Vertex.from_grpc 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.
131 132 133 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 131 def confidence @grpc.confidence end |
#description ⇒ String
Entity textual description, expressed in the #locale language.
111 112 113 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 111 def description @grpc.description end |
#inspect ⇒ Object
212 213 214 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 212 def inspect "#<#{self.class.name} #{self}>" end |
#locale ⇒ String
The language code for the locale in which the ‘description` is expressed.
102 103 104 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 102 def locale @grpc.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.
171 172 173 174 175 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 171 def locations @locations ||= Array(@grpc.locations).map do |l| Location.from_grpc l.lat_lng end end |
#mid ⇒ String
Opaque entity ID. Some IDs might be available in Knowledge Graph (KG).
90 91 92 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 90 def mid @grpc.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.
184 185 186 187 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 184 def properties @properties ||= Hash[Array(@grpc.properties).map { |p| [p.name, p.value] }] end |
#score ⇒ Float
Overall score of the result.
120 121 122 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 120 def score @grpc.score end |
#to_h ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
194 195 196 197 198 199 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 194 def to_h { 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
202 203 204 205 206 207 208 209 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 202 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.
144 145 146 |
# File 'lib/google/cloud/vision/annotation/entity.rb', line 144 def topicality @grpc.topicality end |