mindee 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -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 +83 -14
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ab7abbf2686b67f4330ceb018dc5de8b799d567d586072199f22dfcb12b647d
|
4
|
+
data.tar.gz: 15d885b0fa5e42cf84a1ca6f4238f0c1681bb4c3587fbdf8cd9b48f69850a1f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0036d0f5b668d81a1fb602689fc33d98e6ff02a03175b219f7c541689d27a4fb76123982610d979b89f97f074d3fc202effa5f3d00ac9da905d99afe20ef0beb
|
7
|
+
data.tar.gz: dc4d2bd7147c6c0d4d589642d0d6b6a343fdfc5fc305e5d03fe1628dd013b70679b5185fd531015957a998ae9c930d570f537e352d7899ff783945179c480470
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Mindee Ruby API Library Changelog
|
2
2
|
|
3
|
+
## v3.2.0 - 2023-09-15
|
4
|
+
### Changes
|
5
|
+
* :sparkles: add support for Multi Receipts Detector V1
|
6
|
+
* :sparkles: add support for Barcode Reader V1
|
7
|
+
* :sparkles: add support for W9 V1
|
8
|
+
* :sparkles: add support for FR ID Card V2
|
9
|
+
* :sparkles: add support for async in CLI
|
10
|
+
* :sparkles: add support for async auto-polling
|
11
|
+
* :sparkles: add direct access to `raw_http` response
|
12
|
+
* :memo: upgrade reference & guide documentation
|
13
|
+
* :test_tube: **EXPERIMENTAL** add PDF repair option
|
14
|
+
|
15
|
+
### Fixes
|
16
|
+
* :bug: fix display issues with `PositionField`
|
17
|
+
|
18
|
+
|
3
19
|
## v3.1.1 - 2023-08-10
|
4
20
|
### Fixes
|
5
21
|
* :bug: fixed non-pdf files being improperly handled by Ruby requests
|
data/README.md
CHANGED
@@ -18,8 +18,9 @@ gem 'mindee'
|
|
18
18
|
```
|
19
19
|
|
20
20
|
And then execute:
|
21
|
-
|
22
|
-
|
21
|
+
```sh
|
22
|
+
bundle install
|
23
|
+
```
|
23
24
|
|
24
25
|
Finally, Ruby away!
|
25
26
|
|
@@ -43,6 +44,28 @@ result = mindee_client.parse(
|
|
43
44
|
puts result.document
|
44
45
|
```
|
45
46
|
|
47
|
+
**Note:** Files can also be loaded from:
|
48
|
+
|
49
|
+
A URL (`https`):
|
50
|
+
```rb
|
51
|
+
input_source = mindee_client.source_from_url("https://my-url")
|
52
|
+
```
|
53
|
+
|
54
|
+
A bytes input stream:
|
55
|
+
```rb
|
56
|
+
input_source = mindee_client.source_from_bytes('/path/to/the/file.ext', "name-of-my-file.ext")
|
57
|
+
```
|
58
|
+
|
59
|
+
A base64 encoded string:
|
60
|
+
```rb
|
61
|
+
input_source = mindee_client.source_from_b64string('/path/to/the/file.ext', "name-of-my-file.ext")
|
62
|
+
```
|
63
|
+
|
64
|
+
A ruby `file` object:
|
65
|
+
```rb
|
66
|
+
input_source = mindee_client.source_from_file(input_file, "name-of-my-file.ext")
|
67
|
+
```
|
68
|
+
|
46
69
|
#### Region-Specific Documents
|
47
70
|
```ruby
|
48
71
|
require 'mindee'
|
@@ -93,15 +116,42 @@ result.document.inference.prediction.fields.each do |field_name, field_data|
|
|
93
116
|
end
|
94
117
|
```
|
95
118
|
|
119
|
+
## CLI Tool
|
120
|
+
|
121
|
+
A command-line interface tool is available to quickly test documents:
|
122
|
+
```sh
|
123
|
+
ruby ./bin/mindee.rb invoice path/to/your/file.ext
|
124
|
+
```
|
125
|
+
|
126
|
+
|
127
|
+
Using the ruby bundler:
|
128
|
+
```sh
|
129
|
+
bundle exec ruby ./bin/mindee.rb invoice path/to/your/file.ext
|
130
|
+
```
|
131
|
+
|
96
132
|
## Further Reading
|
97
133
|
There's more to it than that for those that need more features, or want to
|
98
134
|
customize the experience.
|
99
135
|
|
100
|
-
* [Ruby Overview](https://developers.mindee.com/docs/
|
101
|
-
* [
|
102
|
-
* [
|
103
|
-
* [
|
104
|
-
* [
|
136
|
+
* [Ruby Overview](https://developers.mindee.com/docs/getting-started-ocr-ruby)
|
137
|
+
* [Custom OCR Ruby](https://developers.mindee.com/docs/api-builder-ocr-ruby)
|
138
|
+
* [Invoice OCR Ruby](https://developers.mindee.com/docs/invoice-ocr-ruby)
|
139
|
+
* [Financial Document OCR Ruby](https://developers.mindee.com/docs/financial-document-ocr-ruby)
|
140
|
+
* [Passport OCR Ruby](https://developers.mindee.com/docs/passport-ocr-ruby)
|
141
|
+
* [Proof of Address OCR Ruby](https://developers.mindee.com/docs/proof-of-address-ocr-ruby)
|
142
|
+
* [Receipt OCR Ruby](https://developers.mindee.com/docs/receipt-ocr-ruby)
|
143
|
+
* [EU License Plate OCR Ruby](https://developers.mindee.com/docs/eu-license-plate-ocr-ruby)
|
144
|
+
* [FR Bank Account Details OCR Ruby](https://developers.mindee.com/docs/fr-bank-account-details-ocr-ruby)
|
145
|
+
* [FR Carte Vitale OCR Ruby](https://developers.mindee.com/docs/fr-carte-vitale-ocr-ruby)
|
146
|
+
* [FR ID Card OCR Ruby](https://developers.mindee.com/docs/fr-id-card-ocr-ruby)
|
147
|
+
* [US Bank Check OCR Ruby](https://developers.mindee.com/docs/us-bank-check-ocr-ruby)
|
148
|
+
* [US Driver License OCR Ruby](https://developers.mindee.com/docs/us-driver-license-ocr-ruby)
|
149
|
+
* [US W9 API Ruby](https://developers.mindee.com/docs/us-w9-api-ruby)
|
150
|
+
* [Barcode Reader API Ruby](https://developers.mindee.com/docs/barcode-reader-api-ruby)
|
151
|
+
* [Cropper API Ruby](https://developers.mindee.com/docs/cropper-api-ruby)
|
152
|
+
* [Invoice Splitter API Ruby](https://developers.mindee.com/docs/invoice-splitter-api-ruby)
|
153
|
+
* [Multi Receipts Detector API Ruby](https://developers.mindee.com/docs/multi-receipts-detector-api-ruby)
|
154
|
+
|
105
155
|
|
106
156
|
You can also take a look at the
|
107
157
|
[Reference Documentation](https://mindee.github.io/mindee-api-ruby/).
|
data/bin/mindee.rb
CHANGED
@@ -1,149 +1,226 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'bundler/setup'
|
4
5
|
require 'optparse'
|
5
|
-
|
6
6
|
require 'mindee'
|
7
7
|
|
8
8
|
DOCUMENTS = {
|
9
9
|
"custom" => {
|
10
|
-
|
11
|
-
|
10
|
+
description: "Custom document type from API builder",
|
11
|
+
doc_class: Mindee::Product::Custom::CustomV1,
|
12
|
+
sync: true,
|
13
|
+
async: false,
|
12
14
|
},
|
13
15
|
"proof-of-address" => {
|
14
|
-
|
15
|
-
|
16
|
+
description: 'Proof of Address',
|
17
|
+
doc_class: Mindee::Product::ProofOfAddress::ProofOfAddressV1,
|
18
|
+
sync: true,
|
19
|
+
async: false,
|
20
|
+
},
|
21
|
+
"cropper" => {
|
22
|
+
description: 'Cropper',
|
23
|
+
doc_class: Mindee::Product::Cropper::CropperV1,
|
24
|
+
sync: true,
|
25
|
+
async: false,
|
16
26
|
},
|
17
27
|
"financial-document" => {
|
18
|
-
|
19
|
-
|
28
|
+
description: 'Financial Document',
|
29
|
+
doc_class: Mindee::Product::FinancialDocument::FinancialDocumentV1,
|
30
|
+
sync: true,
|
31
|
+
async: false,
|
20
32
|
},
|
21
33
|
"invoice" => {
|
22
|
-
|
23
|
-
|
34
|
+
description: 'Invoice',
|
35
|
+
doc_class: Mindee::Product::Invoice::InvoiceV4,
|
36
|
+
sync: true,
|
37
|
+
async: false,
|
24
38
|
},
|
25
39
|
"receipt" => {
|
26
|
-
|
27
|
-
|
40
|
+
description: "Expense Receipt",
|
41
|
+
doc_class: Mindee::Product::Receipt::ReceiptV5,
|
42
|
+
sync: true,
|
43
|
+
async: false,
|
28
44
|
},
|
29
45
|
"passport" => {
|
30
|
-
|
31
|
-
|
46
|
+
description: "Passport",
|
47
|
+
doc_class: Mindee::Product::Passport::PassportV1,
|
48
|
+
sync: true,
|
49
|
+
async: false,
|
32
50
|
},
|
33
51
|
"eu-license-plate" => {
|
34
|
-
|
35
|
-
|
52
|
+
description: "EU License Plate",
|
53
|
+
doc_class: Mindee::Product::EU::LicensePlate::LicensePlateV1,
|
54
|
+
sync: true,
|
55
|
+
async: false,
|
36
56
|
},
|
37
57
|
"fr-bank-account-details" => {
|
38
|
-
|
39
|
-
|
58
|
+
description: "FR Bank Account Details",
|
59
|
+
doc_class: Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV2,
|
60
|
+
sync: true,
|
61
|
+
async: false,
|
40
62
|
},
|
41
63
|
"fr-carte-vitale" => {
|
42
|
-
|
43
|
-
|
64
|
+
description: "FR Carte Vitale",
|
65
|
+
doc_class: Mindee::Product::FR::CarteVitale::CarteVitaleV1,
|
66
|
+
sync: true,
|
67
|
+
async: false,
|
44
68
|
},
|
45
69
|
"fr-id-card" => {
|
46
|
-
|
47
|
-
|
70
|
+
description: "FR ID Card",
|
71
|
+
doc_class: Mindee::Product::FR::IdCard::IdCardV2,
|
72
|
+
sync: true,
|
73
|
+
async: false,
|
48
74
|
},
|
49
75
|
"us-bank-check" => {
|
50
|
-
|
51
|
-
|
76
|
+
description: "US Bank Check",
|
77
|
+
doc_class: Mindee::Product::US::BankCheck::BankCheckV1,
|
78
|
+
sync: true,
|
79
|
+
async: false,
|
80
|
+
},
|
81
|
+
"us-driver-license" => {
|
82
|
+
description: "US Driver License",
|
83
|
+
doc_class: Mindee::Product::US::DriverLicense::DriverLicenseV1,
|
84
|
+
sync: true,
|
85
|
+
async: false,
|
86
|
+
},
|
87
|
+
"us-w9" => {
|
88
|
+
description: "US W9 Form",
|
89
|
+
doc_class: Mindee::Product::US::W9::W9V1,
|
90
|
+
sync: true,
|
91
|
+
async: false
|
52
92
|
},
|
53
93
|
"invoice-splitter" => {
|
54
|
-
|
55
|
-
|
94
|
+
description: "US Bank Check",
|
95
|
+
doc_class: Mindee::Product::InvoiceSplitter::InvoiceSplitterV1,
|
96
|
+
sync: false,
|
97
|
+
async: true,
|
56
98
|
},
|
57
99
|
}
|
58
100
|
|
59
|
-
options = {
|
60
|
-
|
61
|
-
|
101
|
+
options = {}
|
102
|
+
DEFAULT_CUTTING = {
|
103
|
+
page_indexes: [0, 1, 2, 3, 4],
|
104
|
+
operation: :KEEP_ONLY,
|
105
|
+
on_min_pages: 0,
|
62
106
|
}
|
63
107
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
opt.on('-c', '--cut-pages', "Cut document pages") do |v|
|
74
|
-
options[:cut_pages] = v
|
75
|
-
end
|
108
|
+
# Initializes custom-specific options
|
109
|
+
# @param cli_parser [OptionParser]
|
110
|
+
def custom_subcommand(cli_parser)
|
111
|
+
cli_parser.on('-v [VERSION]', '--version [VERSION]', 'Model version for the API') do |v|
|
112
|
+
options[:version] = v
|
113
|
+
end
|
114
|
+
cli_parser.on('-a ACCOUNT_NAME', '--account ACCOUNT_NAME', 'API account name for the endpoint') do |v|
|
115
|
+
options[:account_name] = v
|
76
116
|
end
|
77
117
|
end
|
78
118
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
119
|
+
product_parser = {}
|
120
|
+
DOCUMENTS.each do |doc_key, doc_value|
|
121
|
+
product_parser[doc_key] = OptionParser.new do | opts |
|
122
|
+
opts.on('-w', '--all-words', 'Include words in response') do |v|
|
83
123
|
options[:all_words] = v
|
84
124
|
end
|
85
|
-
|
125
|
+
opts.on('-c', '--cut-pages', "Don't cut document pages") do |v|
|
86
126
|
options[:cut_pages] = v
|
87
127
|
end
|
88
|
-
|
128
|
+
opts.on('-k [KEY]', '--key [KEY]', 'API key for the endpoint') do |v|
|
89
129
|
options[:api_key] = v
|
90
130
|
end
|
91
|
-
|
92
|
-
options[:
|
131
|
+
opts.on('-f', '--full', "Print the full data, including pages") do |v|
|
132
|
+
options[:print_full] = true
|
133
|
+
end
|
134
|
+
opts.on('-F', '--fix-pdf', "Attempts to fix broken PDF files before sending them to the server.") do |v|
|
135
|
+
options[:fix_pdf] = true
|
93
136
|
end
|
94
|
-
|
95
|
-
|
137
|
+
if (doc_key != 'custom')
|
138
|
+
opts.banner = "Product: #{doc_value[:description]}. \nUsage: mindee.rb #{doc_key} [options] file"
|
139
|
+
else
|
140
|
+
opts.banner = "#{doc_value[:description]}. \nUsage: mindee.rb custom [options] endpoint_name file"
|
141
|
+
custom_subcommand(opts)
|
142
|
+
end
|
143
|
+
if doc_value[:async]
|
144
|
+
if doc_value[:sync]
|
145
|
+
opts.on("-A", "--async", "Call asynchronously") do |v|
|
146
|
+
options[:parse_async] = v
|
147
|
+
end
|
148
|
+
end
|
96
149
|
end
|
97
150
|
end
|
98
151
|
end
|
99
152
|
|
100
|
-
global_parser = OptionParser.new do |
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
opt.separator('')
|
105
|
-
opt.on('-f', '--full', "Print the full data, including pages") do |v|
|
106
|
-
options[:print_full] = true
|
107
|
-
end
|
153
|
+
global_parser = OptionParser.new do | opts |
|
154
|
+
opts.banner = "Usage: mindee.rb product [options] file"
|
155
|
+
opts.separator "Available products:"
|
156
|
+
opts.separator " #{DOCUMENTS.keys.join("\n ")}"
|
108
157
|
end
|
109
158
|
|
110
|
-
global_parser.order!
|
111
159
|
command = ARGV.shift
|
160
|
+
if !DOCUMENTS.has_key?(command)
|
161
|
+
abort(global_parser.help)
|
162
|
+
end
|
163
|
+
doc_class = DOCUMENTS[command][:doc_class]
|
164
|
+
product_parser[command].parse!
|
165
|
+
|
112
166
|
if command == 'custom'
|
113
|
-
|
114
|
-
|
115
|
-
|
167
|
+
if ARGV.length < 2
|
168
|
+
$stderr.puts "The 'custom' command requires both ENDPOINT_NAME and file arguments."
|
169
|
+
abort(product_parser[command].help)
|
170
|
+
end
|
171
|
+
endpoint_name = ARGV[0]
|
172
|
+
options[:file_path] = ARGV[1]
|
116
173
|
else
|
117
|
-
|
118
|
-
|
174
|
+
if ARGV.length < 1
|
175
|
+
$stderr.puts "file missing"
|
176
|
+
abort(product_parser[command].help)
|
177
|
+
end
|
178
|
+
endpoint_name = nil
|
179
|
+
options[:file_path] = ARGV[0]
|
119
180
|
end
|
120
181
|
|
121
182
|
mindee_client = Mindee::Client.new(api_key: options[:api_key])
|
183
|
+
if (options[:file_path].start_with?("https://"))
|
184
|
+
input_source = mindee_client.source_from_url(options[:file_path])
|
185
|
+
else
|
186
|
+
input_source = mindee_client.source_from_path(options[:file_path], fix_pdf: options[:fix_pdf])
|
187
|
+
end
|
122
188
|
|
123
189
|
if command == 'custom'
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
190
|
+
endpoint_name = 'endpoint_name'
|
191
|
+
custom_endpoint = mindee_client.create_endpoint(
|
192
|
+
account_name: endpoint_name,
|
193
|
+
endpoint_name: options[:account_name],
|
194
|
+
endpoint_version: options[:endpoint_version].nil? ? "1" : options[:endpoint_version]
|
195
|
+
)
|
130
196
|
else
|
131
|
-
|
132
|
-
$stderr.puts 'No file specified.'
|
133
|
-
exit(1)
|
134
|
-
end
|
135
|
-
doc_type = ''
|
136
|
-
file_path = ARGV[0]
|
197
|
+
custom_endpoint = nil
|
137
198
|
end
|
138
199
|
|
139
|
-
default_cutting = {
|
140
|
-
page_indexes: [0, 1, 2, 3, 4],
|
141
|
-
operation: :KEEP_ONLY,
|
142
|
-
on_min_pages: 0,
|
143
|
-
}
|
144
200
|
page_options = options[:cut_pages].nil? ? nil : default_cutting
|
145
|
-
|
146
|
-
|
201
|
+
if options[:parse_async].nil?
|
202
|
+
if !DOCUMENTS[command][:sync]
|
203
|
+
options[:parse_async] = true
|
204
|
+
else
|
205
|
+
options[:parse_async] = false
|
206
|
+
end
|
207
|
+
end
|
208
|
+
if options[:parse_async]
|
209
|
+
result = mindee_client.enqueue_and_parse(
|
210
|
+
input_source,
|
211
|
+
DOCUMENTS[command][:doc_class],
|
212
|
+
endpoint: custom_endpoint,
|
213
|
+
page_options: page_options,
|
214
|
+
)
|
215
|
+
else
|
216
|
+
result = mindee_client.parse(
|
217
|
+
input_source,
|
218
|
+
DOCUMENTS[command][:doc_class],
|
219
|
+
endpoint: custom_endpoint,
|
220
|
+
page_options: page_options,
|
221
|
+
)
|
222
|
+
end
|
223
|
+
|
147
224
|
if options[:print_full]
|
148
225
|
puts result.document
|
149
226
|
else
|
@@ -0,0 +1,137 @@
|
|
1
|
+
---
|
2
|
+
title: FR Bank Account Details OCR Ruby
|
3
|
+
---
|
4
|
+
The Ruby OCR SDK supports the [Bank Account Details API](https://platform.mindee.com/mindee/bank_account_details).
|
5
|
+
|
6
|
+
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_account_details/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
|
7
|
+
![Bank Account Details sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_account_details/default_sample.jpg?raw=true)
|
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::FR::BankAccountDetails::BankAccountDetailsV2
|
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: bc8f7265-8dab-49fe-810c-d50049605578
|
38
|
+
:Filename: default_sample.jpg
|
39
|
+
|
40
|
+
Inference
|
41
|
+
#########
|
42
|
+
:Product: mindee/bank_account_details v2.0
|
43
|
+
:Rotation applied: Yes
|
44
|
+
|
45
|
+
Prediction
|
46
|
+
==========
|
47
|
+
:Account Holder's Names: MME HEGALALDIA L ENVOL
|
48
|
+
:Basic Bank Account Number:
|
49
|
+
:Bank Code: 13335
|
50
|
+
:Branch Code: 00040
|
51
|
+
:Key: 06
|
52
|
+
:Account Number: 08932891361
|
53
|
+
:IBAN: FR7613335000400893289136106
|
54
|
+
:SWIFT Code: CEPAFRPP333
|
55
|
+
|
56
|
+
Page Predictions
|
57
|
+
================
|
58
|
+
|
59
|
+
Page 0
|
60
|
+
------
|
61
|
+
:Account Holder's Names: MME HEGALALDIA L ENVOL
|
62
|
+
:Basic Bank Account Number:
|
63
|
+
:Bank Code: 13335
|
64
|
+
:Branch Code: 00040
|
65
|
+
:Key: 06
|
66
|
+
:Account Number: 08932891361
|
67
|
+
:IBAN: FR7613335000400893289136106
|
68
|
+
:SWIFT Code: CEPAFRPP333
|
69
|
+
```
|
70
|
+
|
71
|
+
# Field Types
|
72
|
+
## Standard Fields
|
73
|
+
These fields are generic and used in several products.
|
74
|
+
|
75
|
+
### Basic Field
|
76
|
+
Each prediction object contains a set of fields that inherit from the generic `Field` class.
|
77
|
+
A typical `Field` object will have the following attributes:
|
78
|
+
|
79
|
+
* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
|
80
|
+
* **confidence** (Float, nil): the confidence score of the field prediction.
|
81
|
+
* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
|
82
|
+
* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
|
83
|
+
* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
|
84
|
+
* **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
|
85
|
+
|
86
|
+
|
87
|
+
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.
|
88
|
+
|
89
|
+
### String Field
|
90
|
+
The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`).
|
91
|
+
|
92
|
+
## Specific Fields
|
93
|
+
Fields which are specific to this product; they are not used in any other product.
|
94
|
+
|
95
|
+
### Basic Bank Account Number Field
|
96
|
+
Full extraction of BBAN, including: branch code, bank code, account and key.
|
97
|
+
|
98
|
+
A `BankAccountDetailsV2Bban` implements the following attributes:
|
99
|
+
|
100
|
+
* `bban_bank_code` (String): The BBAN bank code outputted as a string.
|
101
|
+
* `bban_branch_code` (String): The BBAN branch code outputted as a string.
|
102
|
+
* `bban_key` (String): The BBAN key outputted as a string.
|
103
|
+
* `bban_number` (String): The BBAN Account number outputted as a string.
|
104
|
+
|
105
|
+
# Attributes
|
106
|
+
The following fields are extracted for Bank Account Details V2:
|
107
|
+
|
108
|
+
## Account Holder's Names
|
109
|
+
**account_holders_names** ([StringField](#string-field)): Full extraction of the account holders names.
|
110
|
+
|
111
|
+
```rb
|
112
|
+
puts result.document.inference.prediction.account_holders_names.value
|
113
|
+
```
|
114
|
+
|
115
|
+
## Basic Bank Account Number
|
116
|
+
**bban** ([BankAccountDetailsV2Bban](#basic-bank-account-number-field)): Full extraction of BBAN, including: branch code, bank code, account and key.
|
117
|
+
|
118
|
+
```rb
|
119
|
+
puts result.document.inference.prediction.bban.value
|
120
|
+
```
|
121
|
+
|
122
|
+
## IBAN
|
123
|
+
**iban** ([StringField](#string-field)): Full extraction of the IBAN number.
|
124
|
+
|
125
|
+
```rb
|
126
|
+
puts result.document.inference.prediction.iban.value
|
127
|
+
```
|
128
|
+
|
129
|
+
## SWIFT Code
|
130
|
+
**swift_code** ([StringField](#string-field)): Full extraction of the SWIFT code.
|
131
|
+
|
132
|
+
```rb
|
133
|
+
puts result.document.inference.prediction.swift_code.value
|
134
|
+
```
|
135
|
+
|
136
|
+
# Questions?
|
137
|
+
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)
|