mindee 4.7.1 → 4.8.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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +6 -6
  4. data/Rakefile +1 -0
  5. data/lib/mindee/errors/mindee_http_error_v2.rb +23 -4
  6. data/lib/mindee/errors/mindee_http_unknown_error_v2.rb +18 -0
  7. data/lib/mindee/http/endpoint.rb +1 -0
  8. data/lib/mindee/input/sources/local_input_source.rb +9 -1
  9. data/lib/mindee/parsing/v2/error_item.rb +21 -0
  10. data/lib/mindee/parsing/v2/error_response.rb +18 -3
  11. data/lib/mindee/parsing/v2/inference_result.rb +4 -0
  12. data/lib/mindee/parsing/v2/rag_metadata.rb +17 -0
  13. data/lib/mindee/product.rb +0 -1
  14. data/lib/mindee/version.rb +1 -1
  15. data/mindee.gemspec +1 -0
  16. data/sig/mindee/errors/mindee_http_error_v2.rbs +4 -1
  17. data/sig/mindee/errors/mindee_http_unknown_error_v2.rbs +9 -0
  18. data/sig/mindee/http/endpoint.rbs +1 -0
  19. data/sig/mindee/input/sources/local_input_source.rbs +1 -1
  20. data/sig/mindee/parsing/v2/error_item.rbs +13 -0
  21. data/sig/mindee/parsing/v2/error_response.rbs +3 -0
  22. data/sig/mindee/parsing/v2/inference_result.rbs +1 -0
  23. data/sig/mindee/parsing/v2/rag_metadata.rbs +13 -0
  24. metadata +22 -47
  25. data/docs/advanced_file_operations.md +0 -109
  26. data/docs/code_samples/us_mail_v2_async.txt +0 -24
  27. data/docs/getting_started.md +0 -257
  28. data/docs/global_products/barcode_reader_v1.md +0 -125
  29. data/docs/global_products/bill_of_lading_v1.md +0 -276
  30. data/docs/global_products/business_card_v1.md +0 -194
  31. data/docs/global_products/cropper_v1.md +0 -123
  32. data/docs/global_products/delivery_notes_v1.md +0 -168
  33. data/docs/global_products/driver_license_v1.md +0 -212
  34. data/docs/global_products/expense_receipts_v5.md +0 -415
  35. data/docs/global_products/financial_document_v1.md +0 -615
  36. data/docs/global_products/international_id_v2.md +0 -264
  37. data/docs/global_products/invoice_splitter_v1.md +0 -127
  38. data/docs/global_products/invoices_v4.md +0 -576
  39. data/docs/global_products/multi_receipts_detector_v1.md +0 -131
  40. data/docs/global_products/nutrition_facts_v1.md +0 -399
  41. data/docs/global_products/passport_v1.md +0 -207
  42. data/docs/global_products/resume_v1.md +0 -384
  43. data/docs/global_products/universal.md +0 -113
  44. data/docs/global_products.md +0 -6
  45. data/docs/loading_a_document.md +0 -330
  46. data/docs/localized_products/bank_account_details_v2.md +0 -158
  47. data/docs/localized_products/bank_check_v1.md +0 -205
  48. data/docs/localized_products/bank_statement_fr_v2.md +0 -269
  49. data/docs/localized_products/carte_grise_v1.md +0 -475
  50. data/docs/localized_products/energy_bill_fra_v1.md +0 -342
  51. data/docs/localized_products/french_healthcard_v1.md +0 -142
  52. data/docs/localized_products/idcard_fr_v2.md +0 -284
  53. data/docs/localized_products/ind_passport_v1.md +0 -307
  54. data/docs/localized_products/payslip_fra_v3.md +0 -344
  55. data/docs/localized_products/us_healthcare_cards_v1.md +0 -258
  56. data/docs/localized_products/us_mail_v3.md +0 -152
  57. data/docs/localized_products.md +0 -6
  58. data/lib/mindee/product/us/us_mail/us_mail_v2.rb +0 -47
  59. data/lib/mindee/product/us/us_mail/us_mail_v2_document.rb +0 -105
  60. data/lib/mindee/product/us/us_mail/us_mail_v2_page.rb +0 -38
  61. data/lib/mindee/product/us/us_mail/us_mail_v2_recipient_address.rb +0 -105
  62. data/lib/mindee/product/us/us_mail/us_mail_v2_recipient_addresses.rb +0 -63
  63. data/lib/mindee/product/us/us_mail/us_mail_v2_sender_address.rb +0 -66
  64. data/sig/mindee/product/us/us_mail/us_mail_v2.rbs +0 -13
  65. data/sig/mindee/product/us/us_mail/us_mail_v2_document.rbs +0 -20
  66. data/sig/mindee/product/us/us_mail/us_mail_v2_page.rbs +0 -17
  67. data/sig/mindee/product/us/us_mail/us_mail_v2_recipient_address.rbs +0 -22
  68. data/sig/mindee/product/us/us_mail/us_mail_v2_recipient_addresses.rbs +0 -15
  69. data/sig/mindee/product/us/us_mail/us_mail_v2_sender_address.rbs +0 -18
@@ -1,415 +0,0 @@
1
- ---
2
- title: Receipt
3
- category: 622b805aaec68102ea7fcbc2
4
- slug: ruby-receipt-ocr
5
- parentDoc: 67b49df15b843f3fa9cd622b
6
- ---
7
- The Ruby Client Library supports the [Receipt API](https://platform.mindee.com/mindee/expense_receipts).
8
-
9
-
10
- > 📝 Product Specs
11
- >
12
- > | Specification | Details |
13
- > | ------------------------------ | -------------------------------------------------- |
14
- > | Endpoint Name | `expense_receipts` |
15
- > | Recommended Version | `v5.4` |
16
- > | Supports Polling/Webhooks | ✔️ Yes |
17
- > | Support Synchronous HTTP Calls | ✔️ Yes |
18
- > | Geography | 🌐 Global |
19
-
20
- > 🔐 Polling Limitations
21
- >
22
- > | Setting | Parameter name | Default Value |
23
- > | ------------------------------- | ----------------------- | ------------- |
24
- > | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds |
25
- > | Default Delay Between Calls | `delay_sec` | 1.5 seconds |
26
- > | Polling Attempts Before Timeout | `max_retries` | 80 retries |
27
-
28
-
29
- Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg),
30
- we are going to illustrate how to extract the data that we want using the Ruby Client Library.
31
- ![Receipt sample](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg?raw=true)
32
-
33
- # Quick-Start
34
- ```rb
35
- #
36
- # Install the Ruby client library by running:
37
- # gem install mindee
38
- #
39
-
40
- require 'mindee'
41
-
42
- # Init a new client
43
- mindee_client = Mindee::Client.new(api_key: 'my-api-key')
44
-
45
- # Load a file from disk
46
- input_source = mindee_client.source_from_path('/path/to/the/file.ext')
47
-
48
- # Parse the file
49
- result = mindee_client.parse(
50
- input_source,
51
- Mindee::Product::Receipt::ReceiptV5,
52
- enqueue: false
53
- )
54
-
55
- # Print a full summary of the parsed data in RST format
56
- puts result.document
57
-
58
- # Print the document-level parsed data
59
- # puts result.document.inference.prediction
60
- ```
61
-
62
- You can also call this product asynchronously:
63
-
64
- ```rb
65
- #
66
- # Install the Ruby client library by running:
67
- # gem install mindee
68
- #
69
-
70
- require 'mindee'
71
-
72
- # Init a new client
73
- mindee_client = Mindee::Client.new(api_key: 'my-api-key')
74
-
75
- # Load a file from disk
76
- input_source = mindee_client.source_from_path('/path/to/the/file.ext')
77
-
78
- # Parse the file
79
- result = mindee_client.parse(
80
- input_source,
81
- Mindee::Product::Receipt::ReceiptV5
82
- )
83
-
84
- # Print a full summary of the parsed data in RST format
85
- puts result.document
86
-
87
- # Print the document-level parsed data
88
- # puts result.document.inference.prediction
89
- ```
90
-
91
- **Output (RST):**
92
- ```rst
93
- ########
94
- Document
95
- ########
96
- :Mindee ID: d96fb043-8fb8-4adc-820c-387aae83376d
97
- :Filename: default_sample.jpg
98
-
99
- Inference
100
- #########
101
- :Product: mindee/expense_receipts v5.3
102
- :Rotation applied: Yes
103
-
104
- Prediction
105
- ==========
106
- :Expense Locale: en-GB; en; GB; GBP;
107
- :Purchase Category: food
108
- :Purchase Subcategory: restaurant
109
- :Document Type: EXPENSE RECEIPT
110
- :Purchase Date: 2016-02-26
111
- :Purchase Time: 15:20
112
- :Total Amount: 10.20
113
- :Total Net: 8.50
114
- :Total Tax: 1.70
115
- :Tip and Gratuity:
116
- :Taxes:
117
- +---------------+--------+----------+---------------+
118
- | Base | Code | Rate (%) | Amount |
119
- +===============+========+==========+===============+
120
- | 8.50 | VAT | 20.00 | 1.70 |
121
- +---------------+--------+----------+---------------+
122
- :Supplier Name: Clachan
123
- :Supplier Company Registrations: Type: VAT NUMBER, Value: 232153895
124
- Type: VAT NUMBER, Value: 232153895
125
- :Supplier Address: 34 Kingley Street W1B 50H
126
- :Supplier Phone Number: 02074940834
127
- :Receipt Number: 54/7500
128
- :Line Items:
129
- +--------------------------------------+----------+--------------+------------+
130
- | Description | Quantity | Total Amount | Unit Price |
131
- +======================================+==========+==============+============+
132
- | Meantime Pale | 2.00 | 10.20 | |
133
- +--------------------------------------+----------+--------------+------------+
134
-
135
- Page Predictions
136
- ================
137
-
138
- Page 0
139
- ------
140
- :Expense Locale: en-GB; en; GB; GBP;
141
- :Purchase Category: food
142
- :Purchase Subcategory: restaurant
143
- :Document Type: EXPENSE RECEIPT
144
- :Purchase Date: 2016-02-26
145
- :Purchase Time: 15:20
146
- :Total Amount: 10.20
147
- :Total Net: 8.50
148
- :Total Tax: 1.70
149
- :Tip and Gratuity:
150
- :Taxes:
151
- +---------------+--------+----------+---------------+
152
- | Base | Code | Rate (%) | Amount |
153
- +===============+========+==========+===============+
154
- | 8.50 | VAT | 20.00 | 1.70 |
155
- +---------------+--------+----------+---------------+
156
- :Supplier Name: Clachan
157
- :Supplier Company Registrations: Type: VAT NUMBER, Value: 232153895
158
- Type: VAT NUMBER, Value: 232153895
159
- :Supplier Address: 34 Kingley Street W1B 50H
160
- :Supplier Phone Number: 02074940834
161
- :Receipt Number: 54/7500
162
- :Line Items:
163
- +--------------------------------------+----------+--------------+------------+
164
- | Description | Quantity | Total Amount | Unit Price |
165
- +======================================+==========+==============+============+
166
- | Meantime Pale | 2.00 | 10.20 | |
167
- +--------------------------------------+----------+--------------+------------+
168
- ```
169
-
170
- # Field Types
171
- ## Standard Fields
172
- These fields are generic and used in several products.
173
-
174
- ### Basic Field
175
- Each prediction object contains a set of fields that inherit from the generic `Field` class.
176
- A typical `Field` object will have the following attributes:
177
-
178
- * **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted.
179
- * **confidence** (Float, nil): the confidence score of the field prediction.
180
- * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
181
- * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
182
- * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level.
183
- * **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it).
184
-
185
-
186
- Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
187
-
188
-
189
- ### Amount Field
190
- The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`).
191
-
192
-
193
- ### Classification Field
194
- The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements
195
- **value**, **confidence** and **page_id**.
196
-
197
- > Note: a classification field's `value is always a `String`.
198
-
199
-
200
- ### Company Registration Field
201
- Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the
202
- following:
203
-
204
- * **type** (`String`): the type of company.
205
-
206
- ### Date Field
207
- Aside from the basic `Field` attributes, the date field `DateField` also implements the following:
208
-
209
- * **date_object** (`Date`): an accessible representation of the value as a JavaScript object.
210
-
211
- ### Locale Field
212
- The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes,
213
- but it comes with its own:
214
-
215
- * **language** (`String`): ISO 639-1 language code (e.g.: `en` for English). Can be `nil`.
216
- * **country** (`String`): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.: `GRB` or `GB` for "Great
217
- Britain"). Can be `nil`.
218
- * **currency** (`String`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `nil`.
219
-
220
- ### String Field
221
- The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`).
222
-
223
- ### Taxes Field
224
- #### Tax
225
- Aside from the basic `Field` attributes, the tax field `TaxField` also implements the following:
226
-
227
- * **rate** (`Float`): the tax rate applied to an item can be expressed as a percentage. Can be `nil`.
228
- * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`.
229
- * **base** (`Float`): base amount used for the tax. Can be `nil`.
230
- * **value** (`Float`): the value of the tax. Can be `nil`.
231
-
232
- > Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like
233
- structure.
234
-
235
- #### Taxes (Array)
236
- The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several
237
- objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line.
238
-
239
- ## Specific Fields
240
- Fields which are specific to this product; they are not used in any other product.
241
-
242
- ### Line Items Field
243
- List of all line items on the receipt.
244
-
245
- A `ReceiptV5LineItem` implements the following attributes:
246
-
247
- * `description` (String): The item description.
248
- * `quantity` (Float): The item quantity.
249
- * `total_amount` (Float): The item total amount.
250
- * `unit_price` (Float): The item unit price.
251
-
252
- # Attributes
253
- The following fields are extracted for Receipt V5:
254
-
255
- ## Purchase Category
256
- **category** ([ClassificationField](#classification-field)): The purchase category of the receipt.
257
-
258
- #### Possible values include:
259
- - 'toll'
260
- - 'food'
261
- - 'parking'
262
- - 'transport'
263
- - 'accommodation'
264
- - 'gasoline'
265
- - 'telecom'
266
- - 'miscellaneous'
267
- - 'software'
268
- - 'shopping'
269
- - 'energy'
270
-
271
- ```rb
272
- puts result.document.inference.prediction.category.value
273
- ```
274
-
275
- ## Purchase Date
276
- **date** ([DateField](#date-field)): The date the purchase was made.
277
-
278
- ```rb
279
- puts result.document.inference.prediction.date.value
280
- ```
281
-
282
- ## Document Type
283
- **document_type** ([ClassificationField](#classification-field)): The type of receipt: EXPENSE RECEIPT or CREDIT CARD RECEIPT.
284
-
285
- #### Possible values include:
286
- - 'EXPENSE RECEIPT'
287
- - 'CREDIT CARD RECEIPT'
288
-
289
- ```rb
290
- puts result.document.inference.prediction.document_type.value
291
- ```
292
-
293
- ## Line Items
294
- **line_items** (Array<[ReceiptV5LineItem](#line-items-field)>): List of all line items on the receipt.
295
-
296
- ```rb
297
- result.document.inference.prediction.line_items do |line_items_elem|
298
- puts line_items_elem.value
299
- end
300
- ```
301
-
302
- ## Expense Locale
303
- **locale** ([LocaleField](#locale-field)): The locale of the document.
304
-
305
- ```rb
306
- puts result.document.inference.prediction.locale.value
307
- ```
308
-
309
- ## Receipt Number
310
- **receipt_number** ([StringField](#string-field)): The receipt number or identifier.
311
-
312
- ```rb
313
- puts result.document.inference.prediction.receipt_number.value
314
- ```
315
-
316
- ## Purchase Subcategory
317
- **subcategory** ([ClassificationField](#classification-field)): The purchase subcategory of the receipt for transport and food.
318
-
319
- #### Possible values include:
320
- - 'plane'
321
- - 'taxi'
322
- - 'train'
323
- - 'restaurant'
324
- - 'shopping'
325
- - 'other'
326
- - 'groceries'
327
- - 'cultural'
328
- - 'electronics'
329
- - 'office_supplies'
330
- - 'micromobility'
331
- - 'car_rental'
332
- - 'public'
333
- - 'delivery'
334
- - nil
335
-
336
- ```rb
337
- puts result.document.inference.prediction.subcategory.value
338
- ```
339
-
340
- ## Supplier Address
341
- **supplier_address** ([StringField](#string-field)): The address of the supplier or merchant.
342
-
343
- ```rb
344
- puts result.document.inference.prediction.supplier_address.value
345
- ```
346
-
347
- ## Supplier Company Registrations
348
- **supplier_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registration numbers associated to the supplier.
349
-
350
- ```rb
351
- result.document.inference.prediction.supplier_company_registrations do |supplier_company_registrations_elem|
352
- puts supplier_company_registrations_elem.value
353
- end
354
- ```
355
-
356
- ## Supplier Name
357
- **supplier_name** ([StringField](#string-field)): The name of the supplier or merchant.
358
-
359
- ```rb
360
- puts result.document.inference.prediction.supplier_name.value
361
- ```
362
-
363
- ## Supplier Phone Number
364
- **supplier_phone_number** ([StringField](#string-field)): The phone number of the supplier or merchant.
365
-
366
- ```rb
367
- puts result.document.inference.prediction.supplier_phone_number.value
368
- ```
369
-
370
- ## Taxes
371
- **taxes** (Array<[TaxField](#taxes-field)>): The list of taxes present on the receipt.
372
-
373
- ```rb
374
- result.document.inference.prediction.taxes do |taxes_elem|
375
- puts taxes_elem.value
376
- end
377
- ```
378
-
379
- ## Purchase Time
380
- **time** ([StringField](#string-field)): The time the purchase was made.
381
-
382
- ```rb
383
- puts result.document.inference.prediction.time.value
384
- ```
385
-
386
- ## Tip and Gratuity
387
- **tip** ([AmountField](#amount-field)): The total amount of tip and gratuity.
388
-
389
- ```rb
390
- puts result.document.inference.prediction.tip.value
391
- ```
392
-
393
- ## Total Amount
394
- **total_amount** ([AmountField](#amount-field)): The total amount paid: includes taxes, discounts, fees, tips, and gratuity.
395
-
396
- ```rb
397
- puts result.document.inference.prediction.total_amount.value
398
- ```
399
-
400
- ## Total Net
401
- **total_net** ([AmountField](#amount-field)): The net amount paid: does not include taxes, fees, and discounts.
402
-
403
- ```rb
404
- puts result.document.inference.prediction.total_net.value
405
- ```
406
-
407
- ## Total Tax
408
- **total_tax** ([AmountField](#amount-field)): The sum of all taxes.
409
-
410
- ```rb
411
- puts result.document.inference.prediction.total_tax.value
412
- ```
413
-
414
- # Questions?
415
- [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)