mindee 3.11.0 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +27 -0
  4. data/README.md +23 -23
  5. data/Rakefile +5 -0
  6. data/bin/mindee.rb +7 -1
  7. data/docs/bank_account_details_v2.md +5 -1
  8. data/docs/bank_check_v1.md +6 -2
  9. data/docs/bank_statement_fr_v1.md +3 -0
  10. data/docs/barcode_reader_v1.md +5 -1
  11. data/docs/bill_of_lading_v1.md +202 -0
  12. data/docs/carte_grise_v1.md +5 -1
  13. data/docs/carte_vitale_v1.md +5 -1
  14. data/docs/code_samples/bill_of_lading_v1_async.txt +19 -0
  15. data/docs/code_samples/energy_bill_fra_v1_async.txt +19 -0
  16. data/docs/code_samples/financial_document_v1_async.txt +19 -0
  17. data/docs/code_samples/invoices_v4_async.txt +19 -0
  18. data/docs/code_samples/nutrition_facts_v1_async.txt +19 -0
  19. data/docs/code_samples/payslip_fra_v2_async.txt +19 -0
  20. data/docs/code_samples/us_healthcare_cards_v1_async.txt +19 -0
  21. data/docs/cropper_v1.md +6 -2
  22. data/docs/custom_v1.md +5 -3
  23. data/docs/energy_bill_fra_v1.md +249 -0
  24. data/docs/eu_driver_license_v1.md +6 -2
  25. data/docs/expense_receipts_v5.md +38 -11
  26. data/docs/financial_document_v1.md +80 -23
  27. data/docs/generated_v1.md +3 -0
  28. data/docs/getting_started.md +3 -0
  29. data/docs/idcard_fr_v2.md +15 -2
  30. data/docs/international_id_v2.md +13 -1
  31. data/docs/invoice_splitter_v1.md +16 -13
  32. data/docs/invoices_v4.md +57 -23
  33. data/docs/license_plates_v1.md +5 -1
  34. data/docs/multi_receipts_detector_v1.md +5 -1
  35. data/docs/nutrition_facts_v1.md +295 -0
  36. data/docs/passport_v1.md +5 -1
  37. data/docs/payslip_fra_v2.md +218 -0
  38. data/docs/proof_of_address_v1.md +5 -1
  39. data/docs/resume_v1.md +24 -1
  40. data/docs/us_driver_license_v1.md +6 -2
  41. data/docs/us_healthcare_cards_v1.md +208 -0
  42. data/docs/us_mail_v2.md +5 -1
  43. data/docs/us_w9_v1.md +6 -2
  44. data/examples/auto_invoice_splitter_extraction.rb +43 -0
  45. data/lib/mindee/client.rb +20 -8
  46. data/lib/mindee/extraction/common/extracted_image.rb +73 -0
  47. data/lib/mindee/extraction/common/image_extractor.rb +189 -0
  48. data/lib/mindee/extraction/common.rb +4 -0
  49. data/lib/mindee/extraction/multi_receipts_extractor/multi_receipts_extractor.rb +26 -0
  50. data/lib/mindee/extraction/multi_receipts_extractor.rb +3 -0
  51. data/lib/mindee/extraction/pdf_extractor/extracted_pdf.rb +55 -0
  52. data/lib/mindee/extraction/pdf_extractor/pdf_extractor.rb +111 -0
  53. data/lib/mindee/extraction/pdf_extractor.rb +4 -0
  54. data/lib/mindee/extraction/tax_extractor/tax_extractor.rb +322 -0
  55. data/lib/mindee/extraction/tax_extractor.rb +1 -320
  56. data/lib/mindee/extraction.rb +3 -0
  57. data/lib/mindee/http/endpoint.rb +18 -6
  58. data/lib/mindee/input/sources.rb +8 -0
  59. data/lib/mindee/parsing/common/api_response.rb +1 -1
  60. data/lib/mindee/parsing/common/document.rb +31 -1
  61. data/lib/mindee/parsing/common/extras/cropper_extra.rb +29 -0
  62. data/lib/mindee/parsing/common/extras/extras.rb +50 -0
  63. data/lib/mindee/parsing/common/extras/full_text_ocr_extra.rb +32 -0
  64. data/lib/mindee/parsing/common/extras.rb +5 -0
  65. data/lib/mindee/parsing/common/page.rb +5 -0
  66. data/lib/mindee/parsing/standard/base_field.rb +1 -0
  67. data/lib/mindee/parsing/standard/company_registration_field.rb +17 -0
  68. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb +39 -0
  69. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rb +52 -0
  70. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rb +95 -0
  71. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rb +58 -0
  72. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_document.rb +136 -0
  73. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rb +58 -0
  74. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb +32 -0
  75. data/lib/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rb +58 -0
  76. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +3 -1
  77. data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +22 -1
  78. data/lib/mindee/product/financial_document/financial_document_v1_page.rb +1 -1
  79. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +4 -15
  80. data/lib/mindee/product/fr/energy_bill/energy_bill_v1.rb +41 -0
  81. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_document.rb +235 -0
  82. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rb +48 -0
  83. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rb +48 -0
  84. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rb +97 -0
  85. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rb +54 -0
  86. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_page.rb +34 -0
  87. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rb +97 -0
  88. data/lib/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rb +97 -0
  89. data/lib/mindee/product/fr/payslip/payslip_v2.rb +41 -0
  90. data/lib/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rb +54 -0
  91. data/lib/mindee/product/fr/payslip/payslip_v2_document.rb +128 -0
  92. data/lib/mindee/product/fr/payslip/payslip_v2_employee.rb +78 -0
  93. data/lib/mindee/product/fr/payslip/payslip_v2_employer.rb +78 -0
  94. data/lib/mindee/product/fr/payslip/payslip_v2_employment.rb +72 -0
  95. data/lib/mindee/product/fr/payslip/payslip_v2_page.rb +34 -0
  96. data/lib/mindee/product/fr/payslip/payslip_v2_pay_detail.rb +100 -0
  97. data/lib/mindee/product/fr/payslip/payslip_v2_pay_period.rb +66 -0
  98. data/lib/mindee/product/fr/payslip/payslip_v2_pto.rb +56 -0
  99. data/lib/mindee/product/fr/payslip/payslip_v2_salary_detail.rb +81 -0
  100. data/lib/mindee/product/international_id/international_id_v2_document.rb +1 -1
  101. data/lib/mindee/product/international_id/international_id_v2_page.rb +1 -1
  102. data/lib/mindee/product/invoice/invoice_v4_document.rb +3 -1
  103. data/lib/mindee/product/invoice/invoice_v4_line_item.rb +22 -1
  104. data/lib/mindee/product/invoice/invoice_v4_page.rb +1 -1
  105. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +1 -1
  106. data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb +1 -1
  107. data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb +1 -1
  108. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rb +39 -0
  109. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rb +52 -0
  110. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rb +52 -0
  111. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rb +52 -0
  112. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rb +52 -0
  113. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rb +173 -0
  114. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rb +87 -0
  115. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rb +32 -0
  116. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rb +52 -0
  117. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rb +52 -0
  118. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rb +46 -0
  119. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rb +58 -0
  120. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rb +52 -0
  121. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rb +52 -0
  122. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rb +52 -0
  123. data/lib/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rb +52 -0
  124. data/lib/mindee/product/receipt/receipt_v5_document.rb +1 -1
  125. data/lib/mindee/product/receipt/receipt_v5_line_item.rb +11 -1
  126. data/lib/mindee/product/receipt/receipt_v5_page.rb +1 -1
  127. data/lib/mindee/product/resume/resume_v1_certificate.rb +11 -1
  128. data/lib/mindee/product/resume/resume_v1_education.rb +14 -1
  129. data/lib/mindee/product/resume/resume_v1_language.rb +9 -1
  130. data/lib/mindee/product/resume/resume_v1_professional_experience.rb +15 -1
  131. data/lib/mindee/product/resume/resume_v1_social_networks_url.rb +9 -1
  132. data/lib/mindee/product/us/healthcare_card/healthcare_card_v1.rb +41 -0
  133. data/lib/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rb +65 -0
  134. data/lib/mindee/product/us/healthcare_card/healthcare_card_v1_document.rb +127 -0
  135. data/lib/mindee/product/us/healthcare_card/healthcare_card_v1_page.rb +34 -0
  136. data/lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb +14 -1
  137. data/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb +5 -17
  138. data/lib/mindee/product.rb +6 -1
  139. data/lib/mindee/version.rb +1 -1
  140. data/mindee.gemspec +1 -0
  141. metadata +91 -3
  142. /data/lib/mindee/extraction/{ocr_extractor.rb → tax_extractor/ocr_extractor.rb} +0 -0
@@ -48,12 +48,19 @@ module Mindee
48
48
  # Call the prediction API.
49
49
  # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
50
50
  # @param all_words [Boolean] Whether the full word extraction needs to be performed
51
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs
51
52
  # @param close_file [Boolean] Whether the file will be closed after reading
52
53
  # @param cropper [Boolean] Whether a cropping operation will be applied
53
54
  # @return [Array]
54
- def predict(input_source, all_words, close_file, cropper)
55
+ def predict(input_source, all_words, full_text, close_file, cropper)
55
56
  check_api_key
56
- response = predict_req_post(input_source, all_words: all_words, close_file: close_file, cropper: cropper)
57
+ response = predict_req_post(
58
+ input_source,
59
+ all_words: all_words,
60
+ full_text: full_text,
61
+ close_file: close_file,
62
+ cropper: cropper
63
+ )
57
64
  hashed_response = JSON.parse(response.body, object_class: Hash)
58
65
  return [hashed_response, response.body] if ResponseValidation.valid_sync_response?(response)
59
66
 
@@ -65,12 +72,13 @@ module Mindee
65
72
  # Call the prediction API.
66
73
  # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
67
74
  # @param all_words [Boolean] Whether the full word extraction needs to be performed
75
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
68
76
  # @param close_file [Boolean] Whether the file will be closed after reading
69
77
  # @param cropper [Boolean] Whether a cropping operation will be applied
70
78
  # @return [Array]
71
- def predict_async(input_source, all_words, close_file, cropper)
79
+ def predict_async(input_source, all_words, full_text, close_file, cropper)
72
80
  check_api_key
73
- response = document_queue_req_get(input_source, all_words, close_file, cropper)
81
+ response = document_queue_req_get(input_source, all_words, full_text, close_file, cropper)
74
82
  hashed_response = JSON.parse(response.body, object_class: Hash)
75
83
  return [hashed_response, response.body] if ResponseValidation.valid_async_response?(response)
76
84
 
@@ -97,14 +105,16 @@ module Mindee
97
105
 
98
106
  # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
99
107
  # @param all_words [Boolean] Whether the full word extraction needs to be performed
108
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
100
109
  # @param close_file [Boolean] Whether the file will be closed after reading
101
110
  # @param cropper [Boolean] Whether a cropping operation will be applied
102
111
  # @return [Net::HTTPResponse, nil]
103
- def predict_req_post(input_source, all_words: false, close_file: true, cropper: false)
112
+ def predict_req_post(input_source, all_words: false, full_text: false, close_file: true, cropper: false)
104
113
  uri = URI("#{@url_root}/predict")
105
114
 
106
115
  params = {}
107
116
  params[:cropper] = 'true' if cropper
117
+ params[:full_text_ocr] = 'true' if full_text
108
118
  uri.query = URI.encode_www_form(params)
109
119
 
110
120
  headers = {
@@ -129,14 +139,16 @@ module Mindee
129
139
 
130
140
  # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
131
141
  # @param all_words [Boolean] Whether the full word extraction needs to be performed
142
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
132
143
  # @param close_file [Boolean] Whether the file will be closed after reading
133
144
  # @param cropper [Boolean] Whether a cropping operation will be applied
134
145
  # @return [Net::HTTPResponse, nil]
135
- def document_queue_req_get(input_source, all_words, close_file, cropper)
146
+ def document_queue_req_get(input_source, all_words, full_text, close_file, cropper)
136
147
  uri = URI("#{@url_root}/predict_async")
137
148
 
138
149
  params = {}
139
150
  params[:cropper] = 'true' if cropper
151
+ params[:full_text_ocr] = 'true' if full_text
140
152
  uri.query = URI.encode_www_form(params)
141
153
 
142
154
  headers = {
@@ -118,6 +118,14 @@ module Mindee
118
118
  @io_stream.close if close
119
119
  ['document', data, { filename: Mindee::Input::Source.convert_to_unicode_escape(@filename) }]
120
120
  end
121
+
122
+ def count_pdf_pages
123
+ return 1 unless pdf?
124
+
125
+ @io_stream.seek(0)
126
+ pdf_processor = Mindee::PDF::PdfProcessor.open_pdf(@io_stream)
127
+ pdf_processor.pages.size
128
+ end
121
129
  end
122
130
 
123
131
  # Load a document from a path.
@@ -103,7 +103,7 @@ module Mindee
103
103
  # @return [String]
104
104
  attr_reader :raw_http
105
105
 
106
- # @param product_class [Class<Mindee::Product>]
106
+ # @param product_class [Mindee::Inference]
107
107
  # @param http_response [Hash]
108
108
  # @param raw_http [String]
109
109
  def initialize(product_class, http_response, raw_http)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'inference'
4
+ require_relative 'extras'
4
5
 
5
6
  module Mindee
6
7
  module Parsing
@@ -13,6 +14,8 @@ module Mindee
13
14
  attr_reader :name
14
15
  # @return [String] Mindee ID of the document
15
16
  attr_reader :id
17
+ # @return [Mindee::Parsing::Common::Extras::Extras] Potential Extras fields sent back along the prediction.
18
+ attr_reader :extras
16
19
  # @return [Mindee::Parsing::Common::Ocr::Ocr, nil] OCR text results (limited availability)
17
20
  attr_reader :ocr
18
21
  # @return [Integer] Amount of pages of the document
@@ -27,13 +30,22 @@ module Mindee
27
30
  Ocr::Ocr.new(ocr_prediction)
28
31
  end
29
32
 
30
- # @param product_class [Class<Mindee::Product>]
33
+ def self.load_extras(http_response)
34
+ extras_prediction = http_response['inference'].fetch('extras', nil)
35
+ return nil if extras_prediction.nil? || extras_prediction.fetch('mvision-v1', nil).nil?
36
+
37
+ Extras::Extras::Extras.new(extras_prediction)
38
+ end
39
+
40
+ # @param product_class [Mindee::Inference]
31
41
  # @param http_response [Hash]
32
42
  def initialize(product_class, http_response)
33
43
  @id = http_response['id']
34
44
  @name = http_response['name']
35
45
  @inference = product_class.new(http_response['inference'])
36
46
  @ocr = self.class.load_ocr(http_response)
47
+ @extras = self.class.load_extras(http_response)
48
+ inject_full_text_ocr(http_response)
37
49
  @n_pages = http_response['n_pages']
38
50
  end
39
51
 
@@ -45,6 +57,24 @@ module Mindee
45
57
  out_str << "\n:Filename: #{@name}"
46
58
  out_str << "\n\n#{@inference}"
47
59
  end
60
+
61
+ private
62
+
63
+ def inject_full_text_ocr(raw_prediction)
64
+ return unless raw_prediction.dig('inference', 'pages') &&
65
+ raw_prediction['inference']['pages'][0]['extras']['full_text_ocr']
66
+
67
+ full_text_ocr = String.new
68
+ raw_prediction.dig('inference', 'pages').each do |page|
69
+ full_text_ocr << (page['extras']['full_text_ocr']['content'])
70
+ end
71
+ artificial_text_obj = { 'content' => full_text_ocr }
72
+ if @extras.nil? || @extras.empty?
73
+ @extras = Extras::Extras.new({ 'full_text_ocr' => artificial_text_obj })
74
+ else
75
+ @extras.add_artificial_extra({ 'full_text_ocr' => artificial_text_obj })
76
+ end
77
+ end
48
78
  end
49
79
  end
50
80
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../standard/position_field'
4
+
5
+ module Mindee
6
+ module Parsing
7
+ module Common
8
+ module Extras
9
+ # Contains information on the cropping of a prediction.
10
+ class CropperExtra
11
+ # Cropper extra initialization.
12
+ # @return [Array<Mindee::Parsing::Standard::PositionField>]
13
+ attr_reader :croppings
14
+
15
+ def initialize(raw_prediction, page_id = nil)
16
+ @croppings = []
17
+ raw_prediction['cropping']&.each do |crop|
18
+ @croppings.push(Mindee::Parsing::Standard::PositionField.new(crop, page_id))
19
+ end
20
+ end
21
+
22
+ def to_s
23
+ @croppings.map(&:to_s).join("\n ")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../standard/position_field'
4
+
5
+ module Mindee
6
+ module Parsing
7
+ module Common
8
+ # Extras namespace.
9
+ module Extras
10
+ # Extra information added to the prediction.
11
+ class Extras
12
+ # @return [CropperExtra, nil]
13
+ attr_reader :cropper
14
+ # @return [FullTextOCRExtra, nil]
15
+ attr_reader :full_text_ocr
16
+
17
+ def initialize(raw_prediction)
18
+ @cropper = CropperExtra.new(raw_prediction['cropper']) if raw_prediction['cropper']
19
+ @full_text_ocr = FullTextOCRExtra.new(raw_prediction['full_text_ocr']) if raw_prediction['full_text_ocr']
20
+
21
+ raw_prediction.each do |key, value|
22
+ instance_variable_set("@#{key}", value) unless ['cropper', 'full_text_ocr'].include?(key)
23
+ end
24
+ end
25
+
26
+ def to_s
27
+ out_str = String.new
28
+ instance_variables.each do |var|
29
+ out_str << "#{var}: #{instance_variable_get(var)}"
30
+ end
31
+ out_str
32
+ end
33
+
34
+ # Adds artificial extra data for reconstructed extras. Currently only used for full_text_ocr.
35
+ #
36
+ # @param [Hash] raw_prediction Raw prediction used by the document.
37
+ def add_artificial_extra(raw_prediction)
38
+ return unless raw_prediction['full_text_ocr']
39
+
40
+ @full_text_ocr << FullTextOCRExtra.new(raw_prediction)
41
+ end
42
+ end
43
+
44
+ def empty?
45
+ instance_variables.all? { |var| instance_variable_get(var).nil? }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../standard/position_field'
4
+
5
+ module Mindee
6
+ module Parsing
7
+ module Common
8
+ module Extras
9
+ # Full Text OCR result.
10
+ class FullTextOCRExtra
11
+ # Contents of the full text OCR result.
12
+ # @return [String, nil]
13
+ attr_reader :contents
14
+ # Language used on the page.
15
+ # @return [String, nil]
16
+ attr_reader :language
17
+
18
+ def initialize(raw_prediction)
19
+ @contents = raw_prediction['content'] if raw_prediction['content']
20
+ return unless raw_prediction['language']
21
+
22
+ @language = raw_prediction['language']
23
+ end
24
+
25
+ def to_s
26
+ @contents || ''
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'extras/extras'
4
+ require_relative 'extras/cropper_extra'
5
+ require_relative 'extras/full_text_ocr_extra'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'product'
4
+ require_relative 'extras'
4
5
 
5
6
  module Mindee
6
7
  module Parsing
@@ -18,11 +19,15 @@ module Mindee
18
19
  # Page prediction
19
20
  # @return [Mindee::Parsing::Common::Prediction]
20
21
  attr_reader :prediction
22
+ # Additional page-level information.
23
+ # @return [Mindee::Parsing::Common::Extras::Extras]
24
+ attr_reader :extras
21
25
 
22
26
  # @param raw_prediction [Hash]
23
27
  def initialize(raw_prediction)
24
28
  @page_id = raw_prediction['id']
25
29
  @orientation = Orientation.new(raw_prediction['orientation'], @page_id)
30
+ @extras = Extras::Extras.new(raw_prediction['extras']) unless raw_prediction['extras'].nil?
26
31
  end
27
32
 
28
33
  # @return [String]
@@ -98,6 +98,7 @@ module Mindee
98
98
  return '' if in_str.nil?
99
99
  return in_str if max_col_size.nil?
100
100
 
101
+ in_str = in_str.gsub(%r{[\n\r\t]}, "\n" => '\\n', "\r" => '\\r', "\t" => '\\t')
101
102
  in_str.length <= max_col_size ? in_str : "#{in_str[0..max_col_size - 4]}..."
102
103
  end
103
104
  end
@@ -15,6 +15,23 @@ module Mindee
15
15
  super
16
16
  @type = prediction['type']
17
17
  end
18
+
19
+ def to_table_line
20
+ printable = printable_values
21
+ format('| %<type>-15s | %<value>-20s ', type: printable['type'], value: printable['value'])
22
+ end
23
+
24
+ def to_s
25
+ printable = printable_values
26
+ format('Type: %<type>s, Value: %<value>s', type: printable['type'], value: printable['value'])
27
+ end
28
+
29
+ def printable_values
30
+ printable = {}
31
+ printable['type'] = type
32
+ printable['value'] = value
33
+ printable
34
+ end
18
35
  end
19
36
  end
20
37
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'bill_of_lading_v1_document'
5
+ require_relative 'bill_of_lading_v1_page'
6
+
7
+ module Mindee
8
+ module Product
9
+ # Bill of Lading module.
10
+ module BillOfLading
11
+ # Bill of Lading API version 1 inference prediction.
12
+ class BillOfLadingV1 < Mindee::Parsing::Common::Inference
13
+ @endpoint_name = 'bill_of_lading'
14
+ @endpoint_version = '1'
15
+
16
+ # @param prediction [Hash]
17
+ def initialize(prediction)
18
+ super
19
+ @prediction = BillOfLadingV1Document.new(prediction['prediction'], nil)
20
+ @pages = []
21
+ prediction['pages'].each do |page|
22
+ if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
23
+ @pages.push(BillOfLadingV1Page.new(page))
24
+ end
25
+ end
26
+ end
27
+
28
+ class << self
29
+ # Name of the endpoint for this product.
30
+ # @return [String]
31
+ attr_reader :endpoint_name
32
+ # Version for this product.
33
+ # @return [String]
34
+ attr_reader :endpoint_version
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module BillOfLading
8
+ # The shipping company responsible for transporting the goods.
9
+ class BillOfLadingV1Carrier < Mindee::Parsing::Standard::FeatureField
10
+ include Mindee::Parsing::Standard
11
+ # The name of the carrier.
12
+ # @return [String]
13
+ attr_reader :name
14
+ # The professional number of the carrier.
15
+ # @return [String]
16
+ attr_reader :professional_number
17
+ # The Standard Carrier Alpha Code (SCAC) of the carrier.
18
+ # @return [String]
19
+ attr_reader :scac
20
+
21
+ # @param prediction [Hash]
22
+ # @param page_id [Integer, nil]
23
+ def initialize(prediction, page_id)
24
+ super(prediction, page_id)
25
+ @name = prediction['name']
26
+ @professional_number = prediction['professional_number']
27
+ @scac = prediction['scac']
28
+ @page_id = page_id
29
+ end
30
+
31
+ # @return [Hash]
32
+ def printable_values
33
+ printable = {}
34
+ printable[:name] = format_for_display(@name)
35
+ printable[:professional_number] = format_for_display(@professional_number)
36
+ printable[:scac] = format_for_display(@scac)
37
+ printable
38
+ end
39
+
40
+ # @return [String]
41
+ def to_s
42
+ printable = printable_values
43
+ out_str = String.new
44
+ out_str << "\n :Name: #{printable[:name]}"
45
+ out_str << "\n :Professional Number: #{printable[:professional_number]}"
46
+ out_str << "\n :SCAC: #{printable[:scac]}"
47
+ out_str
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module BillOfLading
8
+ # The goods being shipped.
9
+ class BillOfLadingV1CarrierItem < Mindee::Parsing::Standard::FeatureField
10
+ include Mindee::Parsing::Standard
11
+ # A description of the item.
12
+ # @return [String]
13
+ attr_reader :description
14
+ # The gross weight of the item.
15
+ # @return [Float]
16
+ attr_reader :gross_weight
17
+ # The measurement of the item.
18
+ # @return [Float]
19
+ attr_reader :measurement
20
+ # The unit of measurement for the measurement.
21
+ # @return [String]
22
+ attr_reader :measurement_unit
23
+ # The quantity of the item being shipped.
24
+ # @return [Float]
25
+ attr_reader :quantity
26
+ # The unit of measurement for weights.
27
+ # @return [String]
28
+ attr_reader :weight_unit
29
+
30
+ # @param prediction [Hash]
31
+ # @param page_id [Integer, nil]
32
+ def initialize(prediction, page_id)
33
+ super(prediction, page_id)
34
+ @description = prediction['description']
35
+ @gross_weight = prediction['gross_weight']
36
+ @measurement = prediction['measurement']
37
+ @measurement_unit = prediction['measurement_unit']
38
+ @quantity = prediction['quantity']
39
+ @weight_unit = prediction['weight_unit']
40
+ @page_id = page_id
41
+ end
42
+
43
+ # @return [Hash]
44
+ def printable_values
45
+ printable = {}
46
+ printable[:description] = format_for_display(@description)
47
+ printable[:gross_weight] = @gross_weight.nil? ? '' : Field.float_to_string(@gross_weight)
48
+ printable[:measurement] = @measurement.nil? ? '' : Field.float_to_string(@measurement)
49
+ printable[:measurement_unit] = format_for_display(@measurement_unit)
50
+ printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity)
51
+ printable[:weight_unit] = format_for_display(@weight_unit)
52
+ printable
53
+ end
54
+
55
+ # @return [Hash]
56
+ def table_printable_values
57
+ printable = {}
58
+ printable[:description] = format_for_display(@description, 36)
59
+ printable[:gross_weight] = @gross_weight.nil? ? '' : Field.float_to_string(@gross_weight)
60
+ printable[:measurement] = @measurement.nil? ? '' : Field.float_to_string(@measurement)
61
+ printable[:measurement_unit] = format_for_display(@measurement_unit, nil)
62
+ printable[:quantity] = @quantity.nil? ? '' : Field.float_to_string(@quantity)
63
+ printable[:weight_unit] = format_for_display(@weight_unit, nil)
64
+ printable
65
+ end
66
+
67
+ # @return [String]
68
+ def to_table_line
69
+ printable = table_printable_values
70
+ out_str = String.new
71
+ out_str << format('| %- 37s', printable[:description])
72
+ out_str << format('| %- 13s', printable[:gross_weight])
73
+ out_str << format('| %- 12s', printable[:measurement])
74
+ out_str << format('| %- 17s', printable[:measurement_unit])
75
+ out_str << format('| %- 9s', printable[:quantity])
76
+ out_str << format('| %- 12s', printable[:weight_unit])
77
+ out_str << '|'
78
+ end
79
+
80
+ # @return [String]
81
+ def to_s
82
+ printable = printable_values
83
+ out_str = String.new
84
+ out_str << "\n :Description: #{printable[:description]}"
85
+ out_str << "\n :Gross Weight: #{printable[:gross_weight]}"
86
+ out_str << "\n :Measurement: #{printable[:measurement]}"
87
+ out_str << "\n :Measurement Unit: #{printable[:measurement_unit]}"
88
+ out_str << "\n :Quantity: #{printable[:quantity]}"
89
+ out_str << "\n :Weight Unit: #{printable[:weight_unit]}"
90
+ out_str
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module BillOfLading
8
+ # The party to whom the goods are being shipped.
9
+ class BillOfLadingV1Consignee < Mindee::Parsing::Standard::FeatureField
10
+ include Mindee::Parsing::Standard
11
+ # The address of the consignee.
12
+ # @return [String]
13
+ attr_reader :address
14
+ # The email of the shipper.
15
+ # @return [String]
16
+ attr_reader :email
17
+ # The name of the consignee.
18
+ # @return [String]
19
+ attr_reader :name
20
+ # The phone number of the consignee.
21
+ # @return [String]
22
+ attr_reader :phone
23
+
24
+ # @param prediction [Hash]
25
+ # @param page_id [Integer, nil]
26
+ def initialize(prediction, page_id)
27
+ super(prediction, page_id)
28
+ @address = prediction['address']
29
+ @email = prediction['email']
30
+ @name = prediction['name']
31
+ @phone = prediction['phone']
32
+ @page_id = page_id
33
+ end
34
+
35
+ # @return [Hash]
36
+ def printable_values
37
+ printable = {}
38
+ printable[:address] = format_for_display(@address)
39
+ printable[:email] = format_for_display(@email)
40
+ printable[:name] = format_for_display(@name)
41
+ printable[:phone] = format_for_display(@phone)
42
+ printable
43
+ end
44
+
45
+ # @return [String]
46
+ def to_s
47
+ printable = printable_values
48
+ out_str = String.new
49
+ out_str << "\n :Address: #{printable[:address]}"
50
+ out_str << "\n :Email: #{printable[:email]}"
51
+ out_str << "\n :Name: #{printable[:name]}"
52
+ out_str << "\n :Phone: #{printable[:phone]}"
53
+ out_str
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end