mindee 3.1.0 → 3.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +57 -7
- data/bin/mindee.rb +160 -83
- data/docs/bank_account_details_v2.md +137 -0
- data/docs/bank_check_v1.md +179 -0
- data/docs/barcode_reader_v1.md +104 -0
- data/docs/carte_vitale_v1.md +123 -0
- data/docs/code_samples/barcode_reader_v1.txt +19 -0
- data/docs/code_samples/cropper_v1.txt +16 -0
- data/docs/code_samples/idcard_fr_v2.txt +19 -0
- data/docs/code_samples/invoice_splitter_v1_async.txt +6 -54
- data/docs/code_samples/multi_receipts_detector_v1.txt +19 -0
- data/docs/code_samples/us_w9_v1.txt +16 -0
- data/docs/cropper_v1.md +97 -0
- data/docs/custom_v1.md +101 -0
- data/docs/expense_receipts_v5.md +306 -0
- data/docs/financial_document_v1.md +384 -0
- data/docs/{ruby-getting-started.md → getting_started.md} +22 -6
- data/docs/idcard_fr_v2.md +253 -0
- data/docs/invoice_splitter_v1.md +85 -0
- data/docs/invoices_v4.md +369 -0
- data/docs/license_plates_v1.md +91 -0
- data/docs/multi_receipts_detector_v1.md +105 -0
- data/docs/passport_v1.md +186 -0
- data/docs/proof_of_address_v1.md +207 -0
- data/docs/us_driver_license_v1.md +268 -0
- data/docs/us_w9_v1.md +207 -0
- data/lib/mindee/client.rb +95 -16
- data/lib/mindee/geometry/quadrilateral.rb +5 -0
- data/lib/mindee/http/.rubocop.yml +8 -0
- data/lib/mindee/http/endpoint.rb +14 -6
- data/lib/mindee/http/error.rb +104 -0
- data/lib/mindee/http.rb +1 -0
- data/lib/mindee/input/sources.rb +84 -15
- data/lib/mindee/parsing/common/api_response.rb +11 -1
- data/lib/mindee/parsing/common/inference.rb +2 -2
- data/lib/mindee/parsing/common/ocr/ocr.rb +1 -0
- data/lib/mindee/parsing/common.rb +0 -1
- data/lib/mindee/parsing/standard/company_registration_field.rb +1 -1
- data/lib/mindee/parsing/standard/locale_field.rb +1 -1
- data/lib/mindee/parsing/standard/payment_details_field.rb +1 -1
- data/lib/mindee/parsing/standard/position_field.rb +10 -3
- data/lib/mindee/parsing/standard/{text_field.rb → string_field.rb} +1 -1
- data/lib/mindee/parsing/standard.rb +1 -1
- data/lib/mindee/pdf/pdf_processing.rb +2 -1
- data/lib/mindee/product/barcode_reader/barcode_reader_v1.rb +37 -0
- data/lib/mindee/product/barcode_reader/barcode_reader_v1_document.rb +44 -0
- data/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb +32 -0
- data/lib/mindee/product/cropper/cropper_v1.rb +37 -0
- data/lib/mindee/product/cropper/cropper_v1_document.rb +13 -0
- data/lib/mindee/product/cropper/cropper_v1_page.rb +49 -0
- data/lib/mindee/product/custom/custom_v1.rb +1 -0
- data/lib/mindee/product/eu/license_plate/license_plate_v1.rb +1 -0
- data/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb +2 -2
- data/lib/mindee/product/financial_document/financial_document_v1.rb +1 -0
- data/lib/mindee/product/financial_document/financial_document_v1_document.rb +24 -24
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +1 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb +6 -6
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +1 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb +6 -6
- data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb +1 -0
- data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_document.rb +6 -6
- data/lib/mindee/product/fr/id_card/id_card_v1.rb +1 -0
- data/lib/mindee/product/fr/id_card/id_card_v1_document.rb +16 -16
- data/lib/mindee/product/fr/id_card/id_card_v2.rb +39 -0
- data/lib/mindee/product/fr/id_card/id_card_v2_document.rb +107 -0
- data/lib/mindee/product/fr/id_card/id_card_v2_page.rb +53 -0
- data/lib/mindee/product/invoice/invoice_v4.rb +1 -0
- data/lib/mindee/product/invoice/invoice_v4_document.rb +24 -24
- data/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +1 -0
- data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +5 -3
- data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb +37 -0
- data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb +35 -0
- data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb +32 -0
- data/lib/mindee/product/passport/passport_v1.rb +1 -0
- data/lib/mindee/product/passport/passport_v1_document.rb +16 -16
- data/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +1 -0
- data/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb +14 -14
- data/lib/mindee/product/receipt/receipt_v4_document.rb +6 -6
- data/lib/mindee/product/receipt/receipt_v5.rb +1 -0
- data/lib/mindee/product/receipt/receipt_v5_document.rb +12 -12
- data/lib/mindee/product/us/bank_check/bank_check_v1.rb +1 -0
- data/lib/mindee/product/us/bank_check/bank_check_v1_document.rb +8 -8
- data/lib/mindee/product/us/driver_license/driver_license_v1.rb +1 -0
- data/lib/mindee/product/us/driver_license/driver_license_v1_document.rb +28 -28
- data/lib/mindee/product/us/w9/w9_v1.rb +39 -0
- data/lib/mindee/product/us/w9/w9_v1_document.rb +15 -0
- data/lib/mindee/product/us/w9/w9_v1_page.rb +102 -0
- data/lib/mindee/product.rb +5 -0
- data/lib/mindee/version.rb +5 -1
- data/lib/mindee.rb +47 -0
- metadata +43 -9
- data/docs/ruby-api-builder.md +0 -123
- data/docs/ruby-invoice-ocr.md +0 -271
- data/docs/ruby-passport-ocr.md +0 -165
- data/docs/ruby-receipt-ocr.md +0 -196
- data/lib/mindee/parsing/common/error.rb +0 -24
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Invoice Splitter API Ruby
|
|
3
|
+
---
|
|
4
|
+
The Ruby OCR SDK supports the [Invoice Splitter API](https://platform.mindee.com/mindee/invoice_splitter).
|
|
5
|
+
|
|
6
|
+
Using [this sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/default_sample.pdf), we are going to illustrate how to detect the pages of multiple invoices within the same document.
|
|
7
|
+
|
|
8
|
+
# Quick-Start
|
|
9
|
+
|
|
10
|
+
```rb
|
|
11
|
+
require 'mindee'
|
|
12
|
+
|
|
13
|
+
# Init a new client
|
|
14
|
+
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
|
|
15
|
+
|
|
16
|
+
# Load a file from disk
|
|
17
|
+
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
|
|
18
|
+
|
|
19
|
+
result = mindee_client.enqueue_and_parse(
|
|
20
|
+
input_source,
|
|
21
|
+
Mindee::Product::InvoiceSplitter::InvoiceSplitterV1
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Print a full summary of the parsed data in RST format
|
|
25
|
+
puts result.document
|
|
26
|
+
|
|
27
|
+
# Print the document-level parsed data
|
|
28
|
+
# puts result.document.inference.prediction
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Output (RST):**
|
|
32
|
+
```rst
|
|
33
|
+
########
|
|
34
|
+
Document
|
|
35
|
+
########
|
|
36
|
+
:Mindee ID: 8c25cc63-212b-4537-9c9b-3fbd3bd0ee20
|
|
37
|
+
:Filename: default_sample.jpg
|
|
38
|
+
|
|
39
|
+
Inference
|
|
40
|
+
#########
|
|
41
|
+
:Product: mindee/carte_vitale v1.0
|
|
42
|
+
:Rotation applied: Yes
|
|
43
|
+
|
|
44
|
+
Prediction
|
|
45
|
+
==========
|
|
46
|
+
:Given Name(s): NATHALIE
|
|
47
|
+
:Surname: DURAND
|
|
48
|
+
:Social Security Number: 269054958815780
|
|
49
|
+
:Issuance Date: 2007-01-01
|
|
50
|
+
|
|
51
|
+
Page Predictions
|
|
52
|
+
================
|
|
53
|
+
|
|
54
|
+
Page 0
|
|
55
|
+
------
|
|
56
|
+
:Given Name(s): NATHALIE
|
|
57
|
+
:Surname: DURAND
|
|
58
|
+
:Social Security Number: 269054958815780
|
|
59
|
+
:Issuance Date: 2007-01-01
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
# Field Types
|
|
63
|
+
## Specific Fields
|
|
64
|
+
### Invoice Splitter V1 Page Group
|
|
65
|
+
List of page group indexes.
|
|
66
|
+
|
|
67
|
+
An `InvoiceSplitterV1PageGroup` implements the following attributes:
|
|
68
|
+
|
|
69
|
+
* **page_indexes** (Array<`Integer`>): List of indexes of the pages of a single invoice.
|
|
70
|
+
* **confidence** (`Float`): The confidence of the prediction.
|
|
71
|
+
|
|
72
|
+
# Attributes
|
|
73
|
+
The following fields are extracted for Invoice Splitter V1:
|
|
74
|
+
|
|
75
|
+
## Invoice Page Groups
|
|
76
|
+
**invoice_page_groups** (Array<[InvoiceSplitterV1PageGroup](#invoice-splitter-v1-page-group)>): List of page indexes that belong to the same invoice in the PDF.
|
|
77
|
+
|
|
78
|
+
```rb
|
|
79
|
+
for invoice_page_groups_elem in result.document.inference.prediction.invoice_page_groups do
|
|
80
|
+
puts invoicePageGroupsElem.pageIndexes.join(', ')
|
|
81
|
+
end
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
# Questions?
|
|
85
|
+
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)
|
data/docs/invoices_v4.md
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Invoice OCR Ruby
|
|
3
|
+
---
|
|
4
|
+
The Ruby OCR SDK supports the [Invoice API](https://platform.mindee.com/mindee/invoices).
|
|
5
|
+
|
|
6
|
+
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/invoices/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
# Quick-Start
|
|
10
|
+
```rb
|
|
11
|
+
require 'mindee'
|
|
12
|
+
|
|
13
|
+
# Init a new client
|
|
14
|
+
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
|
|
15
|
+
|
|
16
|
+
# Load a file from disk
|
|
17
|
+
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
|
|
18
|
+
|
|
19
|
+
# Parse the file
|
|
20
|
+
result = mindee_client.parse(
|
|
21
|
+
input_source,
|
|
22
|
+
Mindee::Product::Invoice::InvoiceV4
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Print a full summary of the parsed data in RST format
|
|
26
|
+
puts result.document
|
|
27
|
+
|
|
28
|
+
# Print the document-level parsed data
|
|
29
|
+
# puts result.document.inference.prediction
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Output (RST):**
|
|
33
|
+
```rst
|
|
34
|
+
########
|
|
35
|
+
Document
|
|
36
|
+
########
|
|
37
|
+
:Mindee ID: 656c2ec1-0920-4556-9bc2-772162bc698a
|
|
38
|
+
:Filename: invoice.pdf
|
|
39
|
+
|
|
40
|
+
Inference
|
|
41
|
+
#########
|
|
42
|
+
:Product: mindee/invoices v4.1
|
|
43
|
+
:Rotation applied: Yes
|
|
44
|
+
|
|
45
|
+
Prediction
|
|
46
|
+
==========
|
|
47
|
+
:Locale: fr; fr; EUR;
|
|
48
|
+
:Document type: INVOICE
|
|
49
|
+
:Invoice number: 0042004801351
|
|
50
|
+
:Reference numbers: AD29094
|
|
51
|
+
:Invoice date: 2020-02-17
|
|
52
|
+
:Invoice due date: 2020-02-17
|
|
53
|
+
:Supplier name: TURNPIKE DESIGNS CO.
|
|
54
|
+
:Supplier address: 156 University Ave, Toronto ON, Canada M5H 2H7
|
|
55
|
+
:Supplier company registrations: 501124705; FR33501124705
|
|
56
|
+
:Supplier payment details: FR7640254025476501124705368;
|
|
57
|
+
:Customer name: JIRO DOI
|
|
58
|
+
:Customer address: 1954 Bloon Street West Toronto, ON, M6P 3K9 Canada
|
|
59
|
+
:Customer company registrations: FR00000000000; 111222333
|
|
60
|
+
:Taxes:
|
|
61
|
+
+---------------+--------+----------+---------------+
|
|
62
|
+
| Base | Code | Rate (%) | Amount |
|
|
63
|
+
+===============+========+==========+===============+
|
|
64
|
+
| | | 20.00 | 97.98 |
|
|
65
|
+
+---------------+--------+----------+---------------+
|
|
66
|
+
:Total net: 489.97
|
|
67
|
+
:Total tax: 97.98
|
|
68
|
+
:Total amount: 587.95
|
|
69
|
+
:Line Items:
|
|
70
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
71
|
+
| Code | QTY | Price | Amount | Tax (Rate) | Description |
|
|
72
|
+
+======================+=========+=========+==========+==================+======================================+
|
|
73
|
+
| | | | 4.31 | (2.10%) | PQ20 ETIQ ULTRA RESIS METAXXDC |
|
|
74
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
75
|
+
| | 1.00 | 65.00 | 75.00 | 10.00 | Platinum web hosting package Down... |
|
|
76
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
77
|
+
| XXX81125600010 | 1.00 | 250.01 | 275.51 | 25.50 (10.20%) | a long string describing the item |
|
|
78
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
79
|
+
| ABC456 | 200.30 | 8.101 | 1622.63 | 121.70 (7.50%) | Liquid perfection |
|
|
80
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
81
|
+
| | | | | | CARTOUCHE L NR BROTHER TN247BK |
|
|
82
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
83
|
+
|
|
84
|
+
Page Predictions
|
|
85
|
+
================
|
|
86
|
+
|
|
87
|
+
Page 0
|
|
88
|
+
------
|
|
89
|
+
:Locale: fr; fr; EUR;
|
|
90
|
+
:Document type: INVOICE
|
|
91
|
+
:Invoice number: 0042004801351
|
|
92
|
+
:Reference numbers:
|
|
93
|
+
:Invoice date: 2020-02-17
|
|
94
|
+
:Invoice due date: 2020-02-17
|
|
95
|
+
:Supplier name:
|
|
96
|
+
:Supplier address:
|
|
97
|
+
:Supplier company registrations: 501124705; FR33501124705
|
|
98
|
+
:Supplier payment details: FR7640254025476501124705368;
|
|
99
|
+
:Customer name:
|
|
100
|
+
:Customer address:
|
|
101
|
+
:Customer company registrations:
|
|
102
|
+
:Taxes:
|
|
103
|
+
+---------------+--------+----------+---------------+
|
|
104
|
+
| Base | Code | Rate (%) | Amount |
|
|
105
|
+
+===============+========+==========+===============+
|
|
106
|
+
| | | 20.00 | 97.98 |
|
|
107
|
+
+---------------+--------+----------+---------------+
|
|
108
|
+
:Total net: 489.97
|
|
109
|
+
:Total tax: 97.98
|
|
110
|
+
:Total amount: 587.95
|
|
111
|
+
:Line Items:
|
|
112
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
113
|
+
| Code | QTY | Price | Amount | Tax (Rate) | Description |
|
|
114
|
+
+======================+=========+=========+==========+==================+======================================+
|
|
115
|
+
| | | | 4.31 | (2.10%) | PQ20 ETIQ ULTRA RESIS METAXXDC |
|
|
116
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
117
|
+
| | 1.00 | 65.00 | 75.00 | 10.00 | Platinum web hosting package Down... |
|
|
118
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
119
|
+
|
|
120
|
+
Page 1
|
|
121
|
+
------
|
|
122
|
+
:Locale: fr; fr; EUR;
|
|
123
|
+
:Document type: INVOICE
|
|
124
|
+
:Invoice number:
|
|
125
|
+
:Reference numbers: AD29094
|
|
126
|
+
:Invoice date:
|
|
127
|
+
:Invoice due date: 2020-02-17
|
|
128
|
+
:Supplier name: TURNPIKE DESIGNS CO.
|
|
129
|
+
:Supplier address: 156 University Ave, Toronto ON, Canada M5H 2H7
|
|
130
|
+
:Supplier company registrations:
|
|
131
|
+
:Supplier payment details:
|
|
132
|
+
:Customer name: JIRO DOI
|
|
133
|
+
:Customer address: 1954 Bloon Street West Toronto, ON, M6P 3K9 Canada
|
|
134
|
+
:Customer company registrations:
|
|
135
|
+
:Taxes:
|
|
136
|
+
+---------------+--------+----------+---------------+
|
|
137
|
+
| Base | Code | Rate (%) | Amount |
|
|
138
|
+
+===============+========+==========+===============+
|
|
139
|
+
| | | 8.00 | 193.20 |
|
|
140
|
+
+---------------+--------+----------+---------------+
|
|
141
|
+
:Total net:
|
|
142
|
+
:Total tax: 193.20
|
|
143
|
+
:Total amount: 2608.20
|
|
144
|
+
:Line Items:
|
|
145
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
146
|
+
| Code | QTY | Price | Amount | Tax (Rate) | Description |
|
|
147
|
+
+======================+=========+=========+==========+==================+======================================+
|
|
148
|
+
| XXX81125600010 | 1.00 | 250.00 | 250.00 | (10.00%) | a long string describing the item |
|
|
149
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
150
|
+
| ABC456 | 200.30 | 8.101 | 1622.63 | 121.70 (7.50%) | Liquid perfection |
|
|
151
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
152
|
+
| | | | | | CARTOUCHE L NR BROTHER TN247BK |
|
|
153
|
+
+----------------------+---------+---------+----------+------------------+--------------------------------------+
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
# Field Types
|
|
157
|
+
## Standard Fields
|
|
158
|
+
These fields are generic and used in several products.
|
|
159
|
+
|
|
160
|
+
### Basic Field
|
|
161
|
+
Each prediction object contains a set of fields that inherit from the generic `Field` class.
|
|
162
|
+
A typical `Field` object will have the following attributes:
|
|
163
|
+
|
|
164
|
+
* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
|
|
165
|
+
* **confidence** (Float, nil): the confidence score of the field prediction.
|
|
166
|
+
* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
|
|
167
|
+
* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
|
|
168
|
+
* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
|
|
169
|
+
* **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
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.
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
### Amount Field
|
|
176
|
+
The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`).
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
### Classification Field
|
|
180
|
+
The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**.
|
|
181
|
+
|
|
182
|
+
> Note: a classification field's `value is always a `String`.
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### Company Registration Field
|
|
186
|
+
Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the following:
|
|
187
|
+
|
|
188
|
+
* **type** (`String`): the type of company.
|
|
189
|
+
|
|
190
|
+
### Date Field
|
|
191
|
+
Aside from the basic `Field` attributes, the date field `DateField` also implements the following:
|
|
192
|
+
|
|
193
|
+
* **date_object** (`Date`): an accessible representation of the value as a JavaScript object.
|
|
194
|
+
|
|
195
|
+
### Locale Field
|
|
196
|
+
The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes, but it comes with its own:
|
|
197
|
+
|
|
198
|
+
* **language** (`String`): ISO 639-1 language code (e.g.: `en` for English). Can be `nil`.
|
|
199
|
+
* **country** (`String`): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.: `GRB` or `GB` for "Great Britain"). Can be `nil`.
|
|
200
|
+
* **currency** (`String`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `nil`.
|
|
201
|
+
|
|
202
|
+
### String Field
|
|
203
|
+
The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`).
|
|
204
|
+
|
|
205
|
+
### Taxes Field
|
|
206
|
+
#### Tax
|
|
207
|
+
Aside from the basic `Field` attributes, the tax field `TaxField` also implements the following:
|
|
208
|
+
|
|
209
|
+
* **rate** (`Float`): the tax rate applied to an item can be undefined. Expressed as a percentage. Can be `nil`.
|
|
210
|
+
* **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`.
|
|
211
|
+
* **base** (`Float`): base amount used for the tax. Can be `nil`.
|
|
212
|
+
|
|
213
|
+
> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure.
|
|
214
|
+
|
|
215
|
+
#### Taxes (Array)
|
|
216
|
+
The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line.
|
|
217
|
+
|
|
218
|
+
## Specific Fields
|
|
219
|
+
Fields which are specific to this product; they are not used in any other product.
|
|
220
|
+
|
|
221
|
+
### Line Items Field
|
|
222
|
+
List of line item details.
|
|
223
|
+
|
|
224
|
+
A `InvoiceV4LineItem` implements the following attributes:
|
|
225
|
+
|
|
226
|
+
* `description` (String): The item description.
|
|
227
|
+
* `product_code` (String): The product code referring to the item.
|
|
228
|
+
* `quantity` (Integer): The item quantity
|
|
229
|
+
* `tax_amount` (Float): The item tax amount.
|
|
230
|
+
* `tax_rate` (Float): The item tax rate in percentage.
|
|
231
|
+
* `total_amount` (Float): The item total amount.
|
|
232
|
+
* `unit_price` (Float): The item unit price.
|
|
233
|
+
|
|
234
|
+
# Attributes
|
|
235
|
+
The following fields are extracted for Invoice V4:
|
|
236
|
+
|
|
237
|
+
## Customer Address
|
|
238
|
+
**customerAddress** ([StringField](#string-field)): The address of the customer.
|
|
239
|
+
|
|
240
|
+
```rb
|
|
241
|
+
puts result.document.inference.prediction.customer_address.value
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Customer Company Registrations
|
|
245
|
+
**customer_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the customer.
|
|
246
|
+
|
|
247
|
+
```rb
|
|
248
|
+
for customer_company_registration_elem in result.document.inference.prediction.customer_company_registration do
|
|
249
|
+
puts customer_company_registration_elem.value
|
|
250
|
+
end
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Customer Name
|
|
254
|
+
**customer_name** ([StringField](#string-field)): The name of the customer.
|
|
255
|
+
|
|
256
|
+
```rb
|
|
257
|
+
puts result.document.inference.prediction.customer_name.value
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Purchase Date
|
|
261
|
+
**date** ([DateField](#date-field)): The date the purchase was made.
|
|
262
|
+
|
|
263
|
+
```rb
|
|
264
|
+
puts result.document.inference.prediction.date.value
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Document Type
|
|
268
|
+
**document_type** ([ClassificationField](#classification-field)): One of: 'INVOICE', 'CREDIT NOTE'.
|
|
269
|
+
|
|
270
|
+
```rb
|
|
271
|
+
puts result.document.inference.prediction.document_type.value
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Due Date
|
|
275
|
+
**due_date** ([DateField](#date-field)): The date on which the payment is due.
|
|
276
|
+
|
|
277
|
+
```rb
|
|
278
|
+
puts result.document.inference.prediction.due_date.value
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Invoice Number
|
|
282
|
+
**invoice_number** ([StringField](#string-field)): The invoice number or identifier.
|
|
283
|
+
|
|
284
|
+
```rb
|
|
285
|
+
puts result.document.inference.prediction.invoice_number.value
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Line Items
|
|
289
|
+
**line_items** (Array<[InvoiceV4LineItem](#line-items-field)>): List of line item details.
|
|
290
|
+
|
|
291
|
+
```rb
|
|
292
|
+
for line_items_elem in result.document.inference.prediction.line_items do
|
|
293
|
+
puts line_items_elem.value
|
|
294
|
+
end
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Locale
|
|
298
|
+
**locale** ([LocaleField](#locale-field)): The locale detected on the document.
|
|
299
|
+
|
|
300
|
+
```rb
|
|
301
|
+
puts result.document.inference.prediction.locale.value
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Reference Numbers
|
|
305
|
+
**reference_numbers** (Array<[StringField](#string-field)>): List of Reference numbers, including PO number.
|
|
306
|
+
|
|
307
|
+
```rb
|
|
308
|
+
for reference_numbers_elem in result.document.inference.prediction.reference_numbers do
|
|
309
|
+
puts reference_numbers_elem.value
|
|
310
|
+
end
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Supplier Address
|
|
314
|
+
**supplier_address** ([StringField](#string-field)): The address of the supplier or merchant.
|
|
315
|
+
|
|
316
|
+
```rb
|
|
317
|
+
result.document.inference.prediction.supplier_address.value
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Supplier Company Registrations
|
|
321
|
+
**supplier_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the supplier.
|
|
322
|
+
|
|
323
|
+
```rb
|
|
324
|
+
for supplier_company_registrations_elem in result.document.inference.prediction.supplier_company_registrations do
|
|
325
|
+
puts supplier_company_registrations_elem.value
|
|
326
|
+
end
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## Supplier Name
|
|
330
|
+
**supplier_name** ([StringField](#string-field)): The name of the supplier or merchant.
|
|
331
|
+
|
|
332
|
+
```rb
|
|
333
|
+
puts result.document.inference.prediction.supplier_name.value
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Supplier Payment Details
|
|
337
|
+
**supplier_payment_details** (Array<[PaymentDetailsField](#payment-details-field)>): List of payment details associated to the supplier.
|
|
338
|
+
|
|
339
|
+
```rb
|
|
340
|
+
for supplier_payment_details_elem in result.document.inference.prediction.supplier_payment_details do
|
|
341
|
+
puts supplier_payment_details_elem.value
|
|
342
|
+
end
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Taxes
|
|
346
|
+
**taxes** (Array<[TaxField](#taxes-field)>): List of tax lines information.
|
|
347
|
+
|
|
348
|
+
```rb
|
|
349
|
+
for taxes_elem in result.document.inference.prediction.taxes do
|
|
350
|
+
puts taxes_elem.to_s
|
|
351
|
+
end
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## Total Amount
|
|
355
|
+
**total_amount** ([AmountField](#amount-field)): The total amount paid: includes taxes, tips, fees, and other charges.
|
|
356
|
+
|
|
357
|
+
```rb
|
|
358
|
+
puts result.document.inference.prediction.total_amount.value
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## Total Net
|
|
362
|
+
**total_net** ([AmountField](#amount-field)): The net amount paid: does not include taxes, fees, and discounts.
|
|
363
|
+
|
|
364
|
+
```rb
|
|
365
|
+
puts result.document.inference.prediction.total_net.value
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
# Questions?
|
|
369
|
+
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: EU License Plate OCR Ruby
|
|
3
|
+
---
|
|
4
|
+
The Ruby OCR SDK supports the [License Plate API](https://platform.mindee.com/mindee/license_plates).
|
|
5
|
+
|
|
6
|
+
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/license_plates/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
# Quick-Start
|
|
10
|
+
```rb
|
|
11
|
+
require 'mindee'
|
|
12
|
+
|
|
13
|
+
# Init a new client
|
|
14
|
+
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
|
|
15
|
+
|
|
16
|
+
# Load a file from disk
|
|
17
|
+
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
|
|
18
|
+
|
|
19
|
+
# Parse the file
|
|
20
|
+
result = mindee_client.parse(
|
|
21
|
+
input_source,
|
|
22
|
+
Mindee::Product::EU::LicensePlate::LicensePlateV1
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Print a full summary of the parsed data in RST format
|
|
26
|
+
puts result.document
|
|
27
|
+
|
|
28
|
+
# Print the document-level parsed data
|
|
29
|
+
# puts result.document.inference.prediction
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Output (RST):**
|
|
33
|
+
```rst
|
|
34
|
+
########
|
|
35
|
+
Document
|
|
36
|
+
########
|
|
37
|
+
:Mindee ID: f0f48232-2c80-4473-9c6f-88a09111b84d
|
|
38
|
+
:Filename: default_sample.jpg
|
|
39
|
+
|
|
40
|
+
Inference
|
|
41
|
+
#########
|
|
42
|
+
:Product: mindee/license_plates v1.0
|
|
43
|
+
:Rotation applied: No
|
|
44
|
+
|
|
45
|
+
Prediction
|
|
46
|
+
==========
|
|
47
|
+
:License Plates: BY-323-YB
|
|
48
|
+
|
|
49
|
+
Page Predictions
|
|
50
|
+
================
|
|
51
|
+
|
|
52
|
+
Page 0
|
|
53
|
+
------
|
|
54
|
+
:License Plates: BY-323-YB
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
# Field Types
|
|
58
|
+
## Standard Fields
|
|
59
|
+
These fields are generic and used in several products.
|
|
60
|
+
|
|
61
|
+
### Basic Field
|
|
62
|
+
Each prediction object contains a set of fields that inherit from the generic `Field` class.
|
|
63
|
+
A typical `Field` object will have the following attributes:
|
|
64
|
+
|
|
65
|
+
* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
|
|
66
|
+
* **confidence** (Float, nil): the confidence score of the field prediction.
|
|
67
|
+
* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
|
|
68
|
+
* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
|
|
69
|
+
* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
|
|
70
|
+
* **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
### String Field
|
|
76
|
+
The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`).
|
|
77
|
+
|
|
78
|
+
# Attributes
|
|
79
|
+
The following fields are extracted for License Plate V1:
|
|
80
|
+
|
|
81
|
+
## License Plates
|
|
82
|
+
**license_plates** (Array<[StringField](#string-field)>): List of all license plates found in the image.
|
|
83
|
+
|
|
84
|
+
```rb
|
|
85
|
+
for license_plates_elem in result.document.inference.prediction.license_plates do
|
|
86
|
+
puts license_plates_elem.value
|
|
87
|
+
end
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
# Questions?
|
|
91
|
+
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Multi Receipts Detector API Ruby
|
|
3
|
+
---
|
|
4
|
+
The Ruby OCR SDK supports the [Multi Receipts Detector API](https://platform.mindee.com/mindee/multi_receipts_detector).
|
|
5
|
+
|
|
6
|
+
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/multi_receipts_detector/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
# Quick-Start
|
|
10
|
+
```rb
|
|
11
|
+
require 'mindee'
|
|
12
|
+
|
|
13
|
+
# Init a new client
|
|
14
|
+
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
|
|
15
|
+
|
|
16
|
+
# Load a file from disk
|
|
17
|
+
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
|
|
18
|
+
|
|
19
|
+
# Parse the file
|
|
20
|
+
result = mindee_client.parse(
|
|
21
|
+
input_source,
|
|
22
|
+
Mindee::Product::MultiReceiptsDetector::MultiReceiptsDetectorV1
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Print a full summary of the parsed data in RST format
|
|
26
|
+
puts result.document
|
|
27
|
+
|
|
28
|
+
# Print the document-level parsed data
|
|
29
|
+
# puts result.document.inference.prediction
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Output (RST):**
|
|
33
|
+
```rst
|
|
34
|
+
########
|
|
35
|
+
Document
|
|
36
|
+
########
|
|
37
|
+
:Mindee ID: d7c5b25f-e0d3-4491-af54-6183afa1aaab
|
|
38
|
+
:Filename: default_sample.jpg
|
|
39
|
+
|
|
40
|
+
Inference
|
|
41
|
+
#########
|
|
42
|
+
:Product: mindee/multi_receipts_detector v1.0
|
|
43
|
+
:Rotation applied: Yes
|
|
44
|
+
|
|
45
|
+
Prediction
|
|
46
|
+
==========
|
|
47
|
+
:List of Receipts: Polygon with 4 points.
|
|
48
|
+
Polygon with 4 points.
|
|
49
|
+
Polygon with 4 points.
|
|
50
|
+
Polygon with 4 points.
|
|
51
|
+
Polygon with 4 points.
|
|
52
|
+
Polygon with 4 points.
|
|
53
|
+
|
|
54
|
+
Page Predictions
|
|
55
|
+
================
|
|
56
|
+
|
|
57
|
+
Page 0
|
|
58
|
+
------
|
|
59
|
+
:List of Receipts: Polygon with 4 points.
|
|
60
|
+
Polygon with 4 points.
|
|
61
|
+
Polygon with 4 points.
|
|
62
|
+
Polygon with 4 points.
|
|
63
|
+
Polygon with 4 points.
|
|
64
|
+
Polygon with 4 points.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
# Field Types
|
|
68
|
+
## Standard Fields
|
|
69
|
+
These fields are generic and used in several products.
|
|
70
|
+
|
|
71
|
+
### Basic Field
|
|
72
|
+
Each prediction object contains a set of fields that inherit from the generic `Field` class.
|
|
73
|
+
A typical `Field` object will have the following attributes:
|
|
74
|
+
|
|
75
|
+
* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
|
|
76
|
+
* **confidence** (Float, nil): the confidence score of the field prediction.
|
|
77
|
+
* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
|
|
78
|
+
* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
|
|
79
|
+
* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
|
|
80
|
+
* **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
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.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### Position Field
|
|
87
|
+
The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, **polygon** and **page_id**. On top of these, it has access to:
|
|
88
|
+
|
|
89
|
+
* **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond canvas).
|
|
90
|
+
* **quadrangle** (`Mindee::Geometry::Quadrilateral`): a free polygon made up of four points.
|
|
91
|
+
|
|
92
|
+
# Attributes
|
|
93
|
+
The following fields are extracted for Multi Receipts Detector V1:
|
|
94
|
+
|
|
95
|
+
## List of Receipts
|
|
96
|
+
**receipts** (Array<[PositionField](#position-field)>): Positions of the receipts on the document.
|
|
97
|
+
|
|
98
|
+
```rb
|
|
99
|
+
for receipts_elem in result.document.inference.prediction.receipts do
|
|
100
|
+
puts receipts_elem.polygon
|
|
101
|
+
end
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
# Questions?
|
|
105
|
+
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)
|