mindee 2.2.1 → 3.1.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 (156) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +2 -0
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +40 -0
  6. data/README.md +29 -16
  7. data/bin/mindee.rb +23 -26
  8. data/docs/code_samples/bank_account_details_v1.txt +10 -5
  9. data/docs/code_samples/bank_account_details_v2.txt +19 -0
  10. data/docs/code_samples/bank_check_v1.txt +10 -5
  11. data/docs/code_samples/carte_vitale_v1.txt +10 -5
  12. data/docs/code_samples/custom_v1.txt +19 -10
  13. data/docs/code_samples/default.txt +10 -2
  14. data/docs/code_samples/expense_receipts_v4.txt +10 -5
  15. data/docs/code_samples/expense_receipts_v5.txt +11 -6
  16. data/docs/code_samples/financial_document_v1.txt +10 -5
  17. data/docs/code_samples/idcard_fr_v1.txt +10 -5
  18. data/docs/code_samples/invoice_splitter_v1_async.txt +66 -0
  19. data/docs/code_samples/invoices_v4.txt +10 -5
  20. data/docs/code_samples/license_plates_v1.txt +10 -5
  21. data/docs/code_samples/passport_v1.txt +10 -5
  22. data/docs/code_samples/proof_of_address_v1.txt +10 -5
  23. data/docs/code_samples/us_driver_license_v1.txt +19 -0
  24. data/docs/ruby-api-builder.md +30 -31
  25. data/docs/ruby-getting-started.md +64 -23
  26. data/docs/ruby-invoice-ocr.md +70 -59
  27. data/docs/ruby-passport-ocr.md +49 -40
  28. data/docs/ruby-receipt-ocr.md +45 -32
  29. data/lib/mindee/client.rb +150 -148
  30. data/lib/mindee/geometry/min_max.rb +23 -0
  31. data/lib/mindee/geometry/point.rb +35 -0
  32. data/lib/mindee/geometry/polygon.rb +23 -0
  33. data/lib/mindee/geometry/quadrilateral.rb +45 -0
  34. data/lib/mindee/geometry/utils.rb +81 -0
  35. data/lib/mindee/geometry.rb +5 -116
  36. data/lib/mindee/http/endpoint.rb +115 -16
  37. data/lib/mindee/http.rb +3 -0
  38. data/lib/mindee/input/sources.rb +90 -73
  39. data/lib/mindee/parsing/common/api_response.rb +109 -0
  40. data/lib/mindee/parsing/common/document.rb +48 -0
  41. data/lib/mindee/parsing/common/error.rb +24 -0
  42. data/lib/mindee/parsing/common/inference.rb +43 -0
  43. data/lib/mindee/parsing/common/ocr/mvision_v1.rb +34 -0
  44. data/lib/mindee/parsing/common/ocr/ocr.rb +169 -0
  45. data/lib/mindee/parsing/common/ocr.rb +3 -0
  46. data/lib/mindee/parsing/common/orientation.rb +26 -0
  47. data/lib/mindee/parsing/common/page.rb +40 -0
  48. data/lib/mindee/parsing/common/prediction.rb +15 -0
  49. data/lib/mindee/parsing/common/product.rb +19 -0
  50. data/lib/mindee/parsing/common.rb +10 -0
  51. data/lib/mindee/parsing/custom/classification_field.rb +28 -0
  52. data/lib/mindee/parsing/custom/list_field.rb +76 -0
  53. data/lib/mindee/parsing/custom.rb +4 -0
  54. data/lib/mindee/parsing/standard/amount_field.rb +26 -0
  55. data/lib/mindee/parsing/standard/base_field.rb +104 -0
  56. data/lib/mindee/parsing/standard/classification_field.rb +16 -0
  57. data/lib/mindee/parsing/standard/company_registration_field.rb +21 -0
  58. data/lib/mindee/parsing/standard/date_field.rb +34 -0
  59. data/lib/mindee/parsing/standard/locale_field.rb +50 -0
  60. data/lib/mindee/parsing/standard/payment_details_field.rb +42 -0
  61. data/lib/mindee/parsing/standard/position_field.rb +47 -0
  62. data/lib/mindee/parsing/standard/tax_field.rb +108 -0
  63. data/lib/mindee/parsing/standard/text_field.rb +16 -0
  64. data/lib/mindee/parsing/standard.rb +12 -0
  65. data/lib/mindee/parsing.rb +3 -2
  66. data/lib/mindee/{input → pdf}/pdf_processing.rb +4 -32
  67. data/lib/mindee/pdf/pdf_tools.rb +34 -0
  68. data/lib/mindee/pdf.rb +3 -0
  69. data/lib/mindee/product/.rubocop.yml +5 -0
  70. data/lib/mindee/product/custom/custom_v1.rb +35 -0
  71. data/lib/mindee/product/custom/custom_v1_document.rb +60 -0
  72. data/lib/mindee/product/custom/custom_v1_page.rb +32 -0
  73. data/lib/mindee/product/eu/license_plate/license_plate_v1.rb +38 -0
  74. data/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb +37 -0
  75. data/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb +34 -0
  76. data/lib/mindee/product/financial_document/financial_document_v1.rb +36 -0
  77. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +202 -0
  78. data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +90 -0
  79. data/lib/mindee/product/financial_document/financial_document_v1_page.rb +32 -0
  80. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +38 -0
  81. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb +43 -0
  82. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb +34 -0
  83. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +38 -0
  84. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +71 -0
  85. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb +51 -0
  86. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb +34 -0
  87. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb +38 -0
  88. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_document.rb +52 -0
  89. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_page.rb +34 -0
  90. data/lib/mindee/product/fr/id_card/id_card_v1.rb +38 -0
  91. data/lib/mindee/product/fr/id_card/id_card_v1_document.rb +82 -0
  92. data/lib/mindee/product/fr/id_card/id_card_v1_page.rb +48 -0
  93. data/lib/mindee/product/invoice/invoice_v4.rb +37 -0
  94. data/lib/mindee/product/invoice/invoice_v4_document.rb +212 -0
  95. data/lib/mindee/product/invoice/invoice_v4_line_item.rb +66 -0
  96. data/lib/mindee/product/invoice/invoice_v4_page.rb +32 -0
  97. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +36 -0
  98. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +65 -0
  99. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb +32 -0
  100. data/lib/mindee/product/passport/passport_v1.rb +36 -0
  101. data/lib/mindee/{parsing/prediction/fr/id_card/id_card_v1.rb → product/passport/passport_v1_document.rb} +45 -45
  102. data/lib/mindee/product/passport/passport_v1_page.rb +32 -0
  103. data/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +36 -0
  104. data/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb +83 -0
  105. data/lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb +32 -0
  106. data/lib/mindee/product/receipt/receipt_v4.rb +36 -0
  107. data/lib/mindee/product/receipt/receipt_v4_document.rb +86 -0
  108. data/lib/mindee/product/receipt/receipt_v4_page.rb +32 -0
  109. data/lib/mindee/product/receipt/receipt_v5.rb +36 -0
  110. data/lib/mindee/product/receipt/receipt_v5_document.rb +149 -0
  111. data/lib/mindee/product/receipt/receipt_v5_line_item.rb +69 -0
  112. data/lib/mindee/product/receipt/receipt_v5_page.rb +32 -0
  113. data/lib/mindee/product/us/bank_check/bank_check_v1.rb +38 -0
  114. data/lib/mindee/product/us/bank_check/bank_check_v1_document.rb +62 -0
  115. data/lib/mindee/product/us/bank_check/bank_check_v1_page.rb +57 -0
  116. data/lib/mindee/product/us/driver_license/driver_license_v1.rb +38 -0
  117. data/lib/mindee/product/us/driver_license/driver_license_v1_document.rb +113 -0
  118. data/lib/mindee/product/us/driver_license/driver_license_v1_page.rb +53 -0
  119. data/lib/mindee/product.rb +17 -0
  120. data/lib/mindee/version.rb +2 -1
  121. data/lib/mindee.rb +3 -1
  122. metadata +91 -38
  123. data/docs/code_samples/shipping_containers_v1.txt +0 -14
  124. data/lib/mindee/document_config.rb +0 -60
  125. data/lib/mindee/parsing/document.rb +0 -31
  126. data/lib/mindee/parsing/error.rb +0 -22
  127. data/lib/mindee/parsing/inference.rb +0 -53
  128. data/lib/mindee/parsing/page.rb +0 -46
  129. data/lib/mindee/parsing/prediction/base.rb +0 -30
  130. data/lib/mindee/parsing/prediction/common_fields/amount.rb +0 -21
  131. data/lib/mindee/parsing/prediction/common_fields/base.rb +0 -72
  132. data/lib/mindee/parsing/prediction/common_fields/company_registration.rb +0 -17
  133. data/lib/mindee/parsing/prediction/common_fields/date.rb +0 -30
  134. data/lib/mindee/parsing/prediction/common_fields/locale.rb +0 -45
  135. data/lib/mindee/parsing/prediction/common_fields/payment_details.rb +0 -33
  136. data/lib/mindee/parsing/prediction/common_fields/position.rb +0 -39
  137. data/lib/mindee/parsing/prediction/common_fields/tax.rb +0 -44
  138. data/lib/mindee/parsing/prediction/common_fields/text.rb +0 -12
  139. data/lib/mindee/parsing/prediction/common_fields.rb +0 -11
  140. data/lib/mindee/parsing/prediction/custom/custom_v1.rb +0 -58
  141. data/lib/mindee/parsing/prediction/custom/fields.rb +0 -91
  142. data/lib/mindee/parsing/prediction/eu/license_plate/license_plate_v1.rb +0 -34
  143. data/lib/mindee/parsing/prediction/financial_document/financial_document_v1.rb +0 -237
  144. data/lib/mindee/parsing/prediction/financial_document/financial_document_v1_line_item.rb +0 -58
  145. data/lib/mindee/parsing/prediction/fr/bank_account_details/bank_account_details_v1.rb +0 -40
  146. data/lib/mindee/parsing/prediction/fr/carte_vitale/carte_vitale_v1.rb +0 -49
  147. data/lib/mindee/parsing/prediction/invoice/invoice_v4.rb +0 -212
  148. data/lib/mindee/parsing/prediction/invoice/invoice_v4_line_item.rb +0 -58
  149. data/lib/mindee/parsing/prediction/passport/passport_v1.rb +0 -121
  150. data/lib/mindee/parsing/prediction/proof_of_address/proof_of_address_v1.rb +0 -80
  151. data/lib/mindee/parsing/prediction/receipt/receipt_v4.rb +0 -87
  152. data/lib/mindee/parsing/prediction/receipt/receipt_v5.rb +0 -136
  153. data/lib/mindee/parsing/prediction/receipt/receipt_v5_line_item.rb +0 -37
  154. data/lib/mindee/parsing/prediction/shipping_container/shipping_container_v1.rb +0 -38
  155. data/lib/mindee/parsing/prediction/us/bank_check/bank_check_v1.rb +0 -70
  156. data/lib/mindee/parsing/prediction.rb +0 -15
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindee, SA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-22 00:00:00.000000000 Z
11
+ date: 2023-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: marcel
@@ -118,6 +118,7 @@ files:
118
118
  - bin/console
119
119
  - bin/mindee.rb
120
120
  - docs/code_samples/bank_account_details_v1.txt
121
+ - docs/code_samples/bank_account_details_v2.txt
121
122
  - docs/code_samples/bank_check_v1.txt
122
123
  - docs/code_samples/carte_vitale_v1.txt
123
124
  - docs/code_samples/custom_v1.txt
@@ -126,11 +127,12 @@ files:
126
127
  - docs/code_samples/expense_receipts_v5.txt
127
128
  - docs/code_samples/financial_document_v1.txt
128
129
  - docs/code_samples/idcard_fr_v1.txt
130
+ - docs/code_samples/invoice_splitter_v1_async.txt
129
131
  - docs/code_samples/invoices_v4.txt
130
132
  - docs/code_samples/license_plates_v1.txt
131
133
  - docs/code_samples/passport_v1.txt
132
134
  - docs/code_samples/proof_of_address_v1.txt
133
- - docs/code_samples/shipping_containers_v1.txt
135
+ - docs/code_samples/us_driver_license_v1.txt
134
136
  - docs/ruby-api-builder.md
135
137
  - docs/ruby-getting-started.md
136
138
  - docs/ruby-invoice-ocr.md
@@ -138,46 +140,97 @@ files:
138
140
  - docs/ruby-receipt-ocr.md
139
141
  - lib/mindee.rb
140
142
  - lib/mindee/client.rb
141
- - lib/mindee/document_config.rb
142
143
  - lib/mindee/geometry.rb
144
+ - lib/mindee/geometry/min_max.rb
145
+ - lib/mindee/geometry/point.rb
146
+ - lib/mindee/geometry/polygon.rb
147
+ - lib/mindee/geometry/quadrilateral.rb
148
+ - lib/mindee/geometry/utils.rb
149
+ - lib/mindee/http.rb
143
150
  - lib/mindee/http/endpoint.rb
144
151
  - lib/mindee/input.rb
145
- - lib/mindee/input/pdf_processing.rb
146
152
  - lib/mindee/input/sources.rb
147
153
  - lib/mindee/parsing.rb
148
- - lib/mindee/parsing/document.rb
149
- - lib/mindee/parsing/error.rb
150
- - lib/mindee/parsing/inference.rb
151
- - lib/mindee/parsing/page.rb
152
- - lib/mindee/parsing/prediction.rb
153
- - lib/mindee/parsing/prediction/base.rb
154
- - lib/mindee/parsing/prediction/common_fields.rb
155
- - lib/mindee/parsing/prediction/common_fields/amount.rb
156
- - lib/mindee/parsing/prediction/common_fields/base.rb
157
- - lib/mindee/parsing/prediction/common_fields/company_registration.rb
158
- - lib/mindee/parsing/prediction/common_fields/date.rb
159
- - lib/mindee/parsing/prediction/common_fields/locale.rb
160
- - lib/mindee/parsing/prediction/common_fields/payment_details.rb
161
- - lib/mindee/parsing/prediction/common_fields/position.rb
162
- - lib/mindee/parsing/prediction/common_fields/tax.rb
163
- - lib/mindee/parsing/prediction/common_fields/text.rb
164
- - lib/mindee/parsing/prediction/custom/custom_v1.rb
165
- - lib/mindee/parsing/prediction/custom/fields.rb
166
- - lib/mindee/parsing/prediction/eu/license_plate/license_plate_v1.rb
167
- - lib/mindee/parsing/prediction/financial_document/financial_document_v1.rb
168
- - lib/mindee/parsing/prediction/financial_document/financial_document_v1_line_item.rb
169
- - lib/mindee/parsing/prediction/fr/bank_account_details/bank_account_details_v1.rb
170
- - lib/mindee/parsing/prediction/fr/carte_vitale/carte_vitale_v1.rb
171
- - lib/mindee/parsing/prediction/fr/id_card/id_card_v1.rb
172
- - lib/mindee/parsing/prediction/invoice/invoice_v4.rb
173
- - lib/mindee/parsing/prediction/invoice/invoice_v4_line_item.rb
174
- - lib/mindee/parsing/prediction/passport/passport_v1.rb
175
- - lib/mindee/parsing/prediction/proof_of_address/proof_of_address_v1.rb
176
- - lib/mindee/parsing/prediction/receipt/receipt_v4.rb
177
- - lib/mindee/parsing/prediction/receipt/receipt_v5.rb
178
- - lib/mindee/parsing/prediction/receipt/receipt_v5_line_item.rb
179
- - lib/mindee/parsing/prediction/shipping_container/shipping_container_v1.rb
180
- - lib/mindee/parsing/prediction/us/bank_check/bank_check_v1.rb
154
+ - lib/mindee/parsing/common.rb
155
+ - lib/mindee/parsing/common/api_response.rb
156
+ - lib/mindee/parsing/common/document.rb
157
+ - lib/mindee/parsing/common/error.rb
158
+ - lib/mindee/parsing/common/inference.rb
159
+ - lib/mindee/parsing/common/ocr.rb
160
+ - lib/mindee/parsing/common/ocr/mvision_v1.rb
161
+ - lib/mindee/parsing/common/ocr/ocr.rb
162
+ - lib/mindee/parsing/common/orientation.rb
163
+ - lib/mindee/parsing/common/page.rb
164
+ - lib/mindee/parsing/common/prediction.rb
165
+ - lib/mindee/parsing/common/product.rb
166
+ - lib/mindee/parsing/custom.rb
167
+ - lib/mindee/parsing/custom/classification_field.rb
168
+ - lib/mindee/parsing/custom/list_field.rb
169
+ - lib/mindee/parsing/standard.rb
170
+ - lib/mindee/parsing/standard/amount_field.rb
171
+ - lib/mindee/parsing/standard/base_field.rb
172
+ - lib/mindee/parsing/standard/classification_field.rb
173
+ - lib/mindee/parsing/standard/company_registration_field.rb
174
+ - lib/mindee/parsing/standard/date_field.rb
175
+ - lib/mindee/parsing/standard/locale_field.rb
176
+ - lib/mindee/parsing/standard/payment_details_field.rb
177
+ - lib/mindee/parsing/standard/position_field.rb
178
+ - lib/mindee/parsing/standard/tax_field.rb
179
+ - lib/mindee/parsing/standard/text_field.rb
180
+ - lib/mindee/pdf.rb
181
+ - lib/mindee/pdf/pdf_processing.rb
182
+ - lib/mindee/pdf/pdf_tools.rb
183
+ - lib/mindee/product.rb
184
+ - lib/mindee/product/.rubocop.yml
185
+ - lib/mindee/product/custom/custom_v1.rb
186
+ - lib/mindee/product/custom/custom_v1_document.rb
187
+ - lib/mindee/product/custom/custom_v1_page.rb
188
+ - lib/mindee/product/eu/license_plate/license_plate_v1.rb
189
+ - lib/mindee/product/eu/license_plate/license_plate_v1_document.rb
190
+ - lib/mindee/product/eu/license_plate/license_plate_v1_page.rb
191
+ - lib/mindee/product/financial_document/financial_document_v1.rb
192
+ - lib/mindee/product/financial_document/financial_document_v1_document.rb
193
+ - lib/mindee/product/financial_document/financial_document_v1_line_item.rb
194
+ - lib/mindee/product/financial_document/financial_document_v1_page.rb
195
+ - lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb
196
+ - lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb
197
+ - lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb
198
+ - lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb
199
+ - lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb
200
+ - lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb
201
+ - lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb
202
+ - lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb
203
+ - lib/mindee/product/fr/carte_vitale/carte_vitale_v1_document.rb
204
+ - lib/mindee/product/fr/carte_vitale/carte_vitale_v1_page.rb
205
+ - lib/mindee/product/fr/id_card/id_card_v1.rb
206
+ - lib/mindee/product/fr/id_card/id_card_v1_document.rb
207
+ - lib/mindee/product/fr/id_card/id_card_v1_page.rb
208
+ - lib/mindee/product/invoice/invoice_v4.rb
209
+ - lib/mindee/product/invoice/invoice_v4_document.rb
210
+ - lib/mindee/product/invoice/invoice_v4_line_item.rb
211
+ - lib/mindee/product/invoice/invoice_v4_page.rb
212
+ - lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb
213
+ - lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb
214
+ - lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb
215
+ - lib/mindee/product/passport/passport_v1.rb
216
+ - lib/mindee/product/passport/passport_v1_document.rb
217
+ - lib/mindee/product/passport/passport_v1_page.rb
218
+ - lib/mindee/product/proof_of_address/proof_of_address_v1.rb
219
+ - lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb
220
+ - lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb
221
+ - lib/mindee/product/receipt/receipt_v4.rb
222
+ - lib/mindee/product/receipt/receipt_v4_document.rb
223
+ - lib/mindee/product/receipt/receipt_v4_page.rb
224
+ - lib/mindee/product/receipt/receipt_v5.rb
225
+ - lib/mindee/product/receipt/receipt_v5_document.rb
226
+ - lib/mindee/product/receipt/receipt_v5_line_item.rb
227
+ - lib/mindee/product/receipt/receipt_v5_page.rb
228
+ - lib/mindee/product/us/bank_check/bank_check_v1.rb
229
+ - lib/mindee/product/us/bank_check/bank_check_v1_document.rb
230
+ - lib/mindee/product/us/bank_check/bank_check_v1_page.rb
231
+ - lib/mindee/product/us/driver_license/driver_license_v1.rb
232
+ - lib/mindee/product/us/driver_license/driver_license_v1_document.rb
233
+ - lib/mindee/product/us/driver_license/driver_license_v1_page.rb
181
234
  - lib/mindee/version.rb
182
235
  - mindee.gemspec
183
236
  homepage: https://github.com/mindee/mindee-api-ruby
@@ -1,14 +0,0 @@
1
- require 'mindee'
2
-
3
- # Init a new client
4
- mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
-
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::ShippingContainerV1)
9
-
10
- # Print a full summary of the parsed data in RST format
11
- puts result
12
-
13
- # Print the document-level parsed data
14
- # puts result.inference.prediction
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
-
5
- require_relative 'http/endpoint'
6
- require_relative 'parsing/document'
7
- require_relative 'parsing/error'
8
- require_relative 'parsing/prediction'
9
-
10
- module Mindee
11
- # Specific client for sending a document to the API.
12
- class DocumentConfig
13
- # Array of possible Mindee::Endpoint to be used.
14
- # @return [Mindee::HTTP::Endpoint]
15
- attr_reader :endpoint
16
-
17
- # @param prediction_class [Class<Mindee::Prediction::Prediction>]
18
- # @param endpoint [Mindee::HTTP::Endpoint]
19
- def initialize(prediction_class, endpoint)
20
- @prediction_class = prediction_class
21
- @endpoint = endpoint
22
- end
23
-
24
- # Call the prediction API.
25
- # @param input_doc [Mindee::InputDocument]
26
- # @param include_words [Boolean]
27
- # @param close_file [Boolean]
28
- # @param cropper [Boolean]
29
- # @return [Mindee::DocumentResponse]
30
- def predict(input_doc, include_words, close_file, cropper)
31
- check_api_key
32
- response = predict_request(input_doc, include_words, close_file, cropper)
33
- hashed_response = JSON.parse(response.body, object_class: Hash)
34
- return Document.new(@prediction_class, hashed_response['document']) if (200..299).include?(response.code.to_i)
35
-
36
- error = Parsing::Error.new(hashed_response['api_request']['error'])
37
- raise error
38
- end
39
-
40
- private
41
-
42
- # @param input_doc [Mindee::InputDocument]
43
- # @param include_words [Boolean]
44
- # @param close_file [Boolean]
45
- # # @param cropper [Boolean]
46
- # @return [Net::HTTPResponse]
47
- def predict_request(input_doc, include_words, close_file, cropper)
48
- @endpoint.predict_req_post(input_doc, include_words: include_words, close_file: close_file, cropper: cropper)
49
- end
50
-
51
- def check_api_key
52
- return unless @endpoint.api_key.nil? || @endpoint.api_key.empty?
53
-
54
- raise "Missing API key for '#{@document_type}', " \
55
- "check your Client Configuration.\n" \
56
- 'You can set this using the ' \
57
- "'#{HTTP::API_KEY_ENV_NAME}' environment variable."
58
- end
59
- end
60
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'inference'
4
-
5
- module Mindee
6
- # Stores all response attributes.
7
- class Document
8
- # @return [Mindee::Inference]
9
- attr_reader :inference
10
- # @return [String] Filename sent to the API
11
- attr_reader :name
12
- # @return [String] Mindee ID of the document
13
- attr_reader :id
14
-
15
- # @param prediction_class [Class<Mindee::Prediction::Prediction>]
16
- # @param http_response [Hash]
17
- def initialize(prediction_class, http_response)
18
- @id = http_response['id']
19
- @name = http_response['name']
20
- @inference = Mindee::Inference.new(prediction_class, http_response['inference'])
21
- end
22
-
23
- def to_s
24
- out_str = String.new
25
- out_str << "########\nDocument\n########"
26
- out_str << "\n:Mindee ID: #{@id}"
27
- out_str << "\n:Filename: #{@name}"
28
- out_str << "\n\n#{@inference}"
29
- end
30
- end
31
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mindee
4
- module Parsing
5
- # API Error
6
- class Error < StandardError
7
- # @return [String]
8
- attr_reader :api_code
9
- # @return [String]
10
- attr_reader :api_details
11
- # @return [String]
12
- attr_reader :api_message
13
-
14
- def initialize(error)
15
- @api_code = error['code']
16
- @api_details = error['details']
17
- @api_message = error['message']
18
- super("#{@api_code}: #{@api_details} - #{@api_message}")
19
- end
20
- end
21
- end
22
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'page'
4
-
5
- module Mindee
6
- # Product information
7
- class Product
8
- attr_reader :name, :type, :version
9
-
10
- # @param http_response [Hash]
11
- def initialize(http_response)
12
- @name = http_response['name']
13
- @type = http_response['type']
14
- @version = http_response['version']
15
- end
16
- end
17
-
18
- # Inference holds all predictions
19
- class Inference
20
- # @return [Boolean]
21
- attr_reader :is_rotation_applied
22
- # @return [Array<Mindee::Page>]
23
- attr_reader :pages
24
- # @return [Mindee::Prediction]
25
- attr_reader :prediction
26
- # @return [Mindee::Product]
27
- attr_reader :product
28
-
29
- # @param prediction_class [Class<Mindee::Prediction::Prediction>]
30
- # @param http_response [Hash]
31
- def initialize(prediction_class, http_response)
32
- @is_rotation_applied = http_response['is_rotation_applied']
33
- @prediction = prediction_class.new(http_response['prediction'], nil)
34
- @product = Product.new(http_response['product'])
35
- @pages = []
36
- http_response['pages'].each do |page|
37
- @pages.push(Page.new(prediction_class, page))
38
- end
39
- end
40
-
41
- def to_s
42
- is_rotation_applied = @is_rotation_applied ? 'Yes' : 'No'
43
- out_str = String.new
44
- out_str << "Inference\n#########"
45
- out_str << "\n:Product: #{@product.name} v#{@product.version}"
46
- out_str << "\n:Rotation applied: #{is_rotation_applied}"
47
- out_str << "\n\nPrediction\n=========="
48
- out_str << "\n#{@prediction}"
49
- out_str << "\n\nPage Predictions\n================\n\n"
50
- out_str << @pages.map(&:to_s).join("\n\n")
51
- end
52
- end
53
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mindee
4
- # Page orientation
5
- class Orientation
6
- # @return [Integer]
7
- attr_reader :page_id
8
- # A prediction among these 3 possible outputs:
9
- # * 0 degrees: the page is already upright
10
- # * 90 degrees: the page must be rotated clockwise to be upright
11
- # * 270 degrees: the page must be rotated counterclockwise to be upright
12
- # @return [Integer, nil]
13
- attr_reader :value
14
-
15
- # @param prediction [Hash]
16
- # @param page_id [Integer]
17
- def initialize(prediction, page_id)
18
- @value = prediction['value']
19
- @page_id = page_id
20
- end
21
- end
22
-
23
- # Page object
24
- class Page
25
- # @return [Integer]
26
- attr_reader :id
27
- # @return [Mindee::Prediction]
28
- attr_reader :prediction
29
- # @return [Mindee::Orientation]
30
- attr_reader :orientation
31
-
32
- def initialize(prediction_class, page)
33
- @id = page['id'].to_i
34
- @prediction = prediction_class.new(page['prediction'], @id)
35
- @orientation = Orientation.new(page['orientation'], @id)
36
- end
37
-
38
- def to_s
39
- out_str = String.new
40
- title = "Page #{@id}"
41
- out_str << "#{title}\n"
42
- out_str << ('-' * title.size)
43
- out_str << "\n#{@prediction}"
44
- end
45
- end
46
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mindee
4
- module Prediction
5
- # Base document object.
6
- class Prediction
7
- # document type
8
- # @return [String]
9
- attr_reader :document_type
10
- # Validation checks for the document
11
- # @return [Hash<Symbol, Boolean>]
12
- attr_reader :checklist
13
- # Original filename of the document
14
- # @return [String, nil]
15
- attr_reader :filename
16
- # Detected MIME type of the document
17
- # @return [String, nil]
18
- attr_reader :file_mimetype
19
-
20
- def initialize(_prediction, _page_id)
21
- @checklist = {}
22
- end
23
-
24
- # @return [Boolean]
25
- def all_checks
26
- @checklist.all? { |_, value| value == true }
27
- end
28
- end
29
- end
30
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base'
4
-
5
- module Mindee
6
- # Represents tax information.
7
- class AmountField < Field
8
- # Amount value as 3 decimal float
9
- # @return [Float, nil]
10
- attr_reader :value
11
-
12
- def initialize(prediction, page_id, reconstructed: false)
13
- super
14
- @value = @value.round(3) unless @value.nil?
15
- end
16
-
17
- def to_s
18
- Field.float_to_string(@value)
19
- end
20
- end
21
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../../geometry'
4
-
5
- module Mindee
6
- # Base field object.
7
- class Field
8
- # @return [String, Float, Integer, Boolean]
9
- attr_reader :value
10
- # @return [Array<Array<Float>>]
11
- attr_reader :bounding_box
12
- # @return [Mindee::Geometry::Polygon]
13
- attr_reader :polygon
14
- # @return [Integer, nil]
15
- attr_reader :page_id
16
- # true if the field was reconstructed or computed using other fields.
17
- # @return [Boolean]
18
- attr_reader :reconstructed
19
- # The confidence score, value will be between 0.0 and 1.0
20
- # @return [Float]
21
- attr_accessor :confidence
22
-
23
- # @param prediction [Hash]
24
- # @param page_id [Integer, nil]
25
- # @param reconstructed [Boolean]
26
- def initialize(prediction, page_id, reconstructed: false)
27
- @value = prediction['value']
28
- @confidence = prediction['confidence']
29
- @polygon = Geometry.polygon_from_prediction(prediction['polygon'])
30
- @bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty?
31
- @page_id = page_id || prediction['page_id']
32
- @reconstructed = reconstructed
33
- end
34
-
35
- def to_s
36
- @value ? @value.to_s : ''
37
- end
38
-
39
- # Multiply all the Mindee::Field confidences in the array.
40
- def self.array_confidence(field_array)
41
- product = 1
42
- field_array.each do |field|
43
- return 0.0 if field.confidence.nil?
44
-
45
- product *= field.confidence
46
- end
47
- product.to_f
48
- end
49
-
50
- # Add all the Mindee::Field values in the array.
51
- def self.array_sum(field_array)
52
- arr_sum = 0
53
- field_array.each do |field|
54
- return 0.0 if field.value.nil?
55
-
56
- arr_sum += field.value
57
- end
58
- arr_sum.to_f
59
- end
60
-
61
- # @param value [Float]
62
- # @param min_precision [Integer]
63
- def self.float_to_string(value, min_precision = 2)
64
- return String.new if value.nil?
65
-
66
- precision = value.to_f.to_s.split('.')[1].size
67
- precision = [precision, min_precision].max
68
- format_string = "%.#{precision}f"
69
- format(format_string, value)
70
- end
71
- end
72
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mindee
4
- # Company registration number or code, and its type.
5
- class CompanyRegistration < Field
6
- # @return [String]
7
- attr_reader :type
8
-
9
- # @param prediction [Hash]
10
- # @param page_id [Integer, nil]
11
- # @param reconstructed [Boolean]
12
- def initialize(prediction, page_id, reconstructed: false)
13
- super
14
- @type = prediction['type']
15
- end
16
- end
17
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'date'
4
-
5
- require_relative 'base'
6
-
7
- module Mindee
8
- # Represents a date.
9
- class DateField < Field
10
- # The date as a standard Ruby `Date` object.
11
- # @return [Date, nil]
12
- attr_reader :date_object
13
- # The ISO 8601 representation of the date, regardless of the `raw` contents.
14
- # @return [String, nil]
15
- attr_reader :value
16
- # The textual representation of the date as found on the document.
17
- # @return [String, nil]
18
- attr_reader :raw
19
-
20
- # @param prediction [Hash]
21
- # @param page_id [Integer, nil]
22
- def initialize(prediction, page_id)
23
- super
24
- return unless @value
25
-
26
- @date_object = Date.parse(@value)
27
- @raw = prediction['raw']
28
- end
29
- end
30
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mindee
4
- # Represents locale information
5
- class Locale
6
- # The confidence score, value will be between 0.0 and 1.0
7
- # @return [Float]
8
- attr_reader :confidence
9
- # Language code in ISO 639-1 format.
10
- # @return [String]
11
- attr_reader :language
12
- # Country code in ISO 3166-1 alpha-2 format.
13
- # @return [String, nil]
14
- attr_reader :country
15
- # Currency code in ISO 4217 format.
16
- # @return [String]
17
- attr_reader :currency
18
- # Language code, with country code when available.
19
- # @return [String]
20
- attr_reader :value
21
-
22
- # @param prediction [Hash]
23
- def initialize(prediction, _page_id = nil)
24
- value_key = if prediction.include? 'value'
25
- 'value'
26
- else
27
- 'language'
28
- end
29
- @confidence = prediction['confidence']
30
- @value = prediction[value_key]
31
- @language = prediction['language']
32
- @country = prediction['country']
33
- @currency = prediction['currency']
34
- end
35
-
36
- def to_s
37
- out_str = String.new
38
- out_str << "#{@value}; " if @value
39
- out_str << "#{@language}; " if @language
40
- out_str << "#{@country}; " if @country
41
- out_str << "#{@currency}; " if @currency
42
- out_str.strip
43
- end
44
- end
45
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base'
4
-
5
- module Mindee
6
- # Represents payment details for invoices and receipts
7
- class PaymentDetails < Field
8
- attr_reader :account_number,
9
- :iban,
10
- :routing_number,
11
- :swift
12
-
13
- # @param prediction [Hash]
14
- # @param page_id [Integer, nil]
15
- # @param reconstructed [Boolean]
16
- def initialize(prediction, page_id, reconstructed: false)
17
- super
18
- @account_number = prediction['account_number']
19
- @iban = prediction['iban']
20
- @routing_number = prediction['routing_number']
21
- @swift = prediction['swift']
22
- end
23
-
24
- def to_s
25
- out_str = String.new
26
- out_str << "#{@account_number}; " if @account_number
27
- out_str << "#{@iban}; " if @iban
28
- out_str << "#{@routing_number}; " if @routing_number
29
- out_str << "#{@swift}; " if @swift
30
- out_str.strip
31
- end
32
- end
33
- end