Class: Mindee::Parsing::Common::Extras::Extras

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/parsing/common/extras/extras.rb

Overview

Extra information added to the prediction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_prediction) ⇒ Extras

Returns a new instance of Extras.



17
18
19
20
21
22
23
24
# File 'lib/mindee/parsing/common/extras/extras.rb', line 17

def initialize(raw_prediction)
  @cropper = CropperExtra.new(raw_prediction['cropper']) if raw_prediction['cropper']
  @full_text_ocr = FullTextOCRExtra.new(raw_prediction['full_text_ocr']) if raw_prediction['full_text_ocr']

  raw_prediction.each do |key, value|
    instance_variable_set("@#{key}", value) unless ['cropper', 'full_text_ocr'].include?(key)
  end
end

Instance Attribute Details

#cropperCropperExtra? (readonly)

Returns:



13
14
15
# File 'lib/mindee/parsing/common/extras/extras.rb', line 13

def cropper
  @cropper
end

#full_text_ocrFullTextOCRExtra? (readonly)

Returns:



15
16
17
# File 'lib/mindee/parsing/common/extras/extras.rb', line 15

def full_text_ocr
  @full_text_ocr
end

Instance Method Details

#add_artificial_extra(raw_prediction) ⇒ Object

Adds artificial extra data for reconstructed extras. Currently only used for full_text_ocr.

Parameters:

  • raw_prediction (Hash)

    Raw prediction used by the document.



37
38
39
40
41
# File 'lib/mindee/parsing/common/extras/extras.rb', line 37

def add_artificial_extra(raw_prediction)
  return unless raw_prediction['full_text_ocr']

  @full_text_ocr << FullTextOCRExtra.new(raw_prediction)
end

#to_sObject



26
27
28
29
30
31
32
# File 'lib/mindee/parsing/common/extras/extras.rb', line 26

def to_s
  out_str = String.new
  instance_variables.each do |var|
    out_str << "#{var}: #{instance_variable_get(var)}"
  end
  out_str
end