Class: Mindee::Parsing::Standard::PositionField

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/parsing/standard/position_field.rb

Overview

An element’s position on the image

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prediction, page_id) ⇒ PositionField

Returns a new instance of PositionField.

Parameters:

  • prediction (Hash)
  • page_id (Integer, nil)


21
22
23
24
25
26
27
28
29
30
# File 'lib/mindee/parsing/standard/position_field.rb', line 21

def initialize(prediction, page_id)
  unless prediction['polygon'].nil? || prediction['polygon'].empty?
    @polygon = Geometry.polygon_from_prediction(prediction['polygon'])
  end
  @quadrangle = to_quadrilateral(prediction, 'quadrangle')
  @rectangle = to_quadrilateral(prediction, 'rectangle')
  @bounding_box = to_quadrilateral(prediction, 'bounding_box')
  @page_id = page_id || prediction['page_id']
  @value = @polygon
end

Instance Attribute Details

#bounding_boxMindee::Geometry::Quadrilateral (readonly)



17
18
19
# File 'lib/mindee/parsing/standard/position_field.rb', line 17

def bounding_box
  @bounding_box
end

#polygonMindee::Geometry::Polygon (readonly)



9
10
11
# File 'lib/mindee/parsing/standard/position_field.rb', line 9

def polygon
  @polygon
end

#quadrangleMindee::Geometry::Quadrilateral (readonly)



13
14
15
# File 'lib/mindee/parsing/standard/position_field.rb', line 13

def quadrangle
  @quadrangle
end

#rectangleMindee::Geometry::Quadrilateral (readonly)



15
16
17
# File 'lib/mindee/parsing/standard/position_field.rb', line 15

def rectangle
  @rectangle
end

#valueMindee::Geometry::Polygon (readonly)



11
12
13
# File 'lib/mindee/parsing/standard/position_field.rb', line 11

def value
  @value
end

Instance Method Details

#to_sString

String representation.

Returns:

  • (String)


37
38
39
40
41
42
43
44
# File 'lib/mindee/parsing/standard/position_field.rb', line 37

def to_s
  return "Polygon with #{@polygon.size} points." if @polygon&.size&.positive?
  return "Polygon with #{@bounding_box.size} points." if @bounding_box&.size&.positive?
  return "Polygon with #{@rectangle.size} points." if @rectangle&.size&.positive?
  return "Polygon with #{@quadrangle.size} points." if @quadrangle&.size&.positive?

  ''
end