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

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/v1/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.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mindee/v1/parsing/common/extras/extras.rb', line 20

def initialize(raw_prediction)
  if raw_prediction['cropper']
    @cropper = Mindee::V1::Parsing::Common::Extras::CropperExtra.new(raw_prediction['cropper'])
  end
  if raw_prediction['full_text_ocr']
    @full_text_ocr = Mindee::V1::Parsing::Common::Extras::FullTextOCRExtra.new(
      raw_prediction['full_text_ocr']
    )
  end
  @rag = Mindee::V1::Parsing::Common::Extras::RAGExtra.new(raw_prediction['rag']) if raw_prediction['rag']

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

Instance Attribute Details

#cropperCropperExtra? (readonly)

Returns:



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

def cropper
  @cropper
end

#full_text_ocrMindee::V1::Parsing::Common::Extras::FullTextOCRExtra (readonly)



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

def full_text_ocr
  @full_text_ocr
end

#ragRAGExtra? (readonly)

Returns:



18
19
20
# File 'lib/mindee/v1/parsing/common/extras/extras.rb', line 18

def rag
  @rag
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.



48
49
50
51
52
# File 'lib/mindee/v1/parsing/common/extras/extras.rb', line 48

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

  @full_text_ocr << Mindee::V1::Parsing::Common::Extras::FullTextOCRExtra.new(raw_prediction)
end

#to_sString

Returns:

  • (String)


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

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