Class: Mindee::Parsing::Standard::AbstractField
- Inherits:
-
Object
- Object
- Mindee::Parsing::Standard::AbstractField
- Defined in:
- lib/mindee/parsing/standard/base_field.rb
Overview
Base Field object, upon which fields and feature fields are built
Direct Known Subclasses
Instance Attribute Summary collapse
- #bounding_box ⇒ Mindee::Geometry::Quadrilateral? readonly
-
#confidence ⇒ Float?
The confidence score, value will be between 0.0 and 1.0.
- #page_id ⇒ Integer? readonly
- #polygon ⇒ Mindee::Geometry::Polygon? readonly
Class Method Summary collapse
-
.array_confidence(field_array) ⇒ Float
Multiply all the Mindee::Parsing::Standard::Field confidences in the array.
-
.array_sum(field_array) ⇒ Float
Add all the Mindee::Parsing::Standard::Field values in the array.
- .float_to_string(value, min_precision = 2) ⇒ String
Instance Method Summary collapse
-
#initialize(prediction, page_id) ⇒ AbstractField
constructor
A new instance of AbstractField.
- #to_s ⇒ String
Constructor Details
#initialize(prediction, page_id) ⇒ AbstractField
Returns a new instance of AbstractField.
22 23 24 25 26 27 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 22 def initialize(prediction, page_id) @confidence = prediction['confidence'] if prediction.key?('confidence') @polygon = Geometry.polygon_from_prediction(prediction['polygon']) if prediction.key?('polygon') @bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty? @page_id = page_id || prediction['page_id'] end |
Instance Attribute Details
#bounding_box ⇒ Mindee::Geometry::Quadrilateral? (readonly)
11 12 13 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 11 def bounding_box @bounding_box end |
#confidence ⇒ Float?
The confidence score, value will be between 0.0 and 1.0
18 19 20 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 18 def confidence @confidence end |
#page_id ⇒ Integer? (readonly)
15 16 17 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 15 def page_id @page_id end |
#polygon ⇒ Mindee::Geometry::Polygon? (readonly)
13 14 15 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 13 def polygon @polygon end |
Class Method Details
.array_confidence(field_array) ⇒ Float
Multiply all the Mindee::Parsing::Standard::Field confidences in the array.
36 37 38 39 40 41 42 43 44 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 36 def self.array_confidence(field_array) product = 1 field_array.each do |field| return 0.0 if field.confidence.nil? product *= field.confidence end product.to_f end |
.array_sum(field_array) ⇒ Float
Add all the Mindee::Parsing::Standard::Field values in the array.
48 49 50 51 52 53 54 55 56 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 48 def self.array_sum(field_array) arr_sum = 0 field_array.each do |field| return 0.0 if field.value.nil? arr_sum += field.value end arr_sum.to_f end |
.float_to_string(value, min_precision = 2) ⇒ String
61 62 63 64 65 66 67 68 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 61 def self.float_to_string(value, min_precision = 2) return String.new if value.nil? precision = value.to_f.to_s.split('.')[1].size precision = [precision, min_precision].max format_string = "%.#{precision}f" format(format_string, value) end |
Instance Method Details
#to_s ⇒ String
30 31 32 |
# File 'lib/mindee/parsing/standard/base_field.rb', line 30 def to_s @value ? @value.to_s : '' end |