mindee 2.1.0 → 2.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/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/.yardopts +0 -1
- data/CHANGELOG.md +16 -0
- data/README.md +13 -9
- data/Rakefile +9 -1
- data/bin/mindee.rb +1 -1
- data/docs/code_samples/bank_account_details_v1.txt +14 -0
- data/docs/code_samples/bank_check_v1.txt +14 -0
- data/docs/code_samples/carte_vitale_v1.txt +14 -0
- data/docs/code_samples/custom_v1.txt +24 -0
- data/docs/code_samples/default.txt +16 -0
- data/docs/code_samples/expense_receipts_v4.txt +14 -0
- data/docs/code_samples/expense_receipts_v5.txt +14 -0
- data/docs/code_samples/financial_document_v1.txt +14 -0
- data/docs/code_samples/idcard_fr_v1.txt +14 -0
- data/docs/code_samples/invoices_v4.txt +14 -0
- data/docs/code_samples/license_plates_v1.txt +14 -0
- data/docs/code_samples/passport_v1.txt +14 -0
- data/docs/code_samples/proof_of_address_v1.txt +14 -0
- data/docs/code_samples/shipping_containers_v1.txt +14 -0
- data/docs/ruby-getting-started.md +1 -1
- data/docs/ruby-receipt-ocr.md +30 -17
- data/lib/mindee/client.rb +3 -0
- data/lib/mindee/parsing/prediction/common_fields/locale.rb +1 -1
- data/lib/mindee/parsing/prediction/eu/license_plate/license_plate_v1.rb +4 -4
- data/lib/mindee/parsing/prediction/financial_document/financial_document_v1.rb +22 -30
- data/lib/mindee/parsing/prediction/{invoice/invoice_line_item.rb → financial_document/financial_document_v1_line_item.rb} +9 -9
- data/lib/mindee/parsing/prediction/fr/bank_account_details/bank_account_details_v1.rb +6 -6
- data/lib/mindee/parsing/prediction/fr/carte_vitale/carte_vitale_v1.rb +8 -8
- data/lib/mindee/parsing/prediction/fr/id_card/id_card_v1.rb +35 -34
- data/lib/mindee/parsing/prediction/invoice/invoice_v4.rb +14 -18
- data/lib/mindee/parsing/prediction/{financial_document/invoice_line_item.rb → invoice/invoice_v4_line_item.rb} +9 -9
- data/lib/mindee/parsing/prediction/passport/passport_v1.rb +0 -63
- data/lib/mindee/parsing/prediction/proof_of_address/proof_of_address_v1.rb +36 -38
- data/lib/mindee/parsing/prediction/receipt/receipt_v5.rb +136 -0
- data/lib/mindee/parsing/prediction/receipt/receipt_v5_line_item.rb +37 -0
- data/lib/mindee/parsing/prediction/shipping_container/shipping_container_v1.rb +2 -2
- data/lib/mindee/parsing/prediction.rb +1 -0
- data/lib/mindee/version.rb +1 -1
- data/mindee.gemspec +5 -6
- metadata +32 -30
|
@@ -4,7 +4,7 @@ require_relative '../common_fields/base'
|
|
|
4
4
|
|
|
5
5
|
module Mindee
|
|
6
6
|
# Line items for invoices
|
|
7
|
-
class
|
|
7
|
+
class FinancialDocumentV1LineItem
|
|
8
8
|
# @return [String] The product code referring to the item.
|
|
9
9
|
attr_reader :product_code
|
|
10
10
|
# @return [String]
|
|
@@ -39,20 +39,20 @@ module Mindee
|
|
|
39
39
|
@page_id = page_id
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# @return String
|
|
42
43
|
def to_s
|
|
43
44
|
tax = Field.float_to_string(@tax_amount)
|
|
44
45
|
tax << " (#{Field.float_to_string(@tax_rate)}%)" unless @tax_rate.nil?
|
|
45
|
-
|
|
46
46
|
description = @description.nil? ? '' : @description
|
|
47
47
|
description = "#{description[0..32]}..." if description.size > 35
|
|
48
|
-
|
|
49
48
|
out_str = String.new
|
|
50
|
-
out_str << format('%-
|
|
51
|
-
out_str << " #{format('%-
|
|
52
|
-
out_str << " #{format('%-
|
|
53
|
-
out_str << " #{format('%-
|
|
54
|
-
out_str << " #{format('%-
|
|
55
|
-
out_str << " #{description}"
|
|
49
|
+
out_str << format('| %- 20s', @product_code)
|
|
50
|
+
out_str << " #{format('| %- 7s', Field.float_to_string(@quantity))}"
|
|
51
|
+
out_str << " #{format('| %- 7s', Field.float_to_string(@unit_price))}"
|
|
52
|
+
out_str << " #{format('| %- 8s', Field.float_to_string(@total_amount))}"
|
|
53
|
+
out_str << " #{format('| %- 16s', tax)}"
|
|
54
|
+
out_str << " #{format('| %- 37s', description)}"
|
|
55
|
+
out_str << '|'
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|
|
@@ -6,15 +6,15 @@ require_relative '../../base'
|
|
|
6
6
|
module Mindee
|
|
7
7
|
module Prediction
|
|
8
8
|
module FR
|
|
9
|
-
#
|
|
9
|
+
# Bank Account Details v1 prediction results.
|
|
10
10
|
class BankAccountDetailsV1 < Prediction
|
|
11
|
-
# The
|
|
11
|
+
# The International Bank Account Number (IBAN).
|
|
12
12
|
# @return [Mindee::TextField]
|
|
13
13
|
attr_reader :iban
|
|
14
|
-
# The account holder
|
|
14
|
+
# The name of the account holder as seen on the document.
|
|
15
15
|
# @return [Mindee::TextField]
|
|
16
16
|
attr_reader :account_holder_name
|
|
17
|
-
# The bank's SWIFT
|
|
17
|
+
# The bank's SWIFT Business Identifier Code (BIC).
|
|
18
18
|
# @return [Mindee::TextField]
|
|
19
19
|
attr_reader :swift
|
|
20
20
|
|
|
@@ -30,8 +30,8 @@ module Mindee
|
|
|
30
30
|
def to_s
|
|
31
31
|
out_str = String.new
|
|
32
32
|
out_str << "\n:IBAN: #{@iban}".rstrip
|
|
33
|
-
out_str << "\n:Account
|
|
34
|
-
out_str << "\n:SWIFT: #{@swift}".rstrip
|
|
33
|
+
out_str << "\n:Account Holder's Name: #{@account_holder_name}".rstrip
|
|
34
|
+
out_str << "\n:SWIFT Code: #{@swift}".rstrip
|
|
35
35
|
out_str[1..].to_s
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -6,18 +6,18 @@ require_relative '../../base'
|
|
|
6
6
|
module Mindee
|
|
7
7
|
module Prediction
|
|
8
8
|
module FR
|
|
9
|
-
#
|
|
9
|
+
# Carte Vitale v1 prediction results.
|
|
10
10
|
class CarteVitaleV1 < Prediction
|
|
11
|
-
#
|
|
11
|
+
# The given name(s) of the card holder.
|
|
12
12
|
# @return [Array<Mindee::TextField>]
|
|
13
13
|
attr_reader :given_names
|
|
14
|
-
# The surname
|
|
14
|
+
# The surname of the card holder.
|
|
15
15
|
# @return [Mindee::TextField]
|
|
16
16
|
attr_reader :surname
|
|
17
|
-
# The
|
|
17
|
+
# The Social Security Number (Numéro de Sécurité Sociale) of the card holder
|
|
18
18
|
# @return [Mindee::TextField]
|
|
19
19
|
attr_reader :social_security
|
|
20
|
-
# The
|
|
20
|
+
# The date the card was issued.
|
|
21
21
|
# @return [Mindee::DateField]
|
|
22
22
|
attr_reader :issuance_date
|
|
23
23
|
|
|
@@ -35,12 +35,12 @@ module Mindee
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def to_s
|
|
38
|
-
given_names = @given_names.
|
|
38
|
+
given_names = @given_names.join("\n #{' ' * 15}")
|
|
39
39
|
out_str = String.new
|
|
40
|
-
out_str << "\n:Given
|
|
40
|
+
out_str << "\n:Given Name(s): #{given_names}".rstrip
|
|
41
41
|
out_str << "\n:Surname: #{@surname}".rstrip
|
|
42
42
|
out_str << "\n:Social Security Number: #{@social_security}".rstrip
|
|
43
|
-
out_str << "\n:Issuance
|
|
43
|
+
out_str << "\n:Issuance Date: #{@issuance_date}".rstrip
|
|
44
44
|
out_str[1..].to_s
|
|
45
45
|
end
|
|
46
46
|
end
|
|
@@ -6,39 +6,39 @@ require_relative '../../base'
|
|
|
6
6
|
module Mindee
|
|
7
7
|
module Prediction
|
|
8
8
|
module FR
|
|
9
|
-
#
|
|
9
|
+
# Carte Nationale d'Identité v1 prediction results.
|
|
10
10
|
class IdCardV1 < Prediction
|
|
11
|
-
# The
|
|
12
|
-
# @return [Array<Mindee::TextField>]
|
|
13
|
-
attr_reader :authority
|
|
14
|
-
# Indicates if it is the recto side, the verso side or both.
|
|
11
|
+
# The side of the document which is visible.
|
|
15
12
|
# @return [Mindee::TextField]
|
|
16
13
|
attr_reader :document_side
|
|
17
|
-
# The card number.
|
|
14
|
+
# The identification card number.
|
|
18
15
|
# @return [Mindee::TextField]
|
|
19
16
|
attr_reader :id_number
|
|
20
|
-
# The
|
|
21
|
-
# @return [Mindee::
|
|
22
|
-
attr_reader :
|
|
23
|
-
# The surname
|
|
17
|
+
# The given name(s) of the card holder.
|
|
18
|
+
# @return [Array<Mindee::TextField>]
|
|
19
|
+
attr_reader :given_names
|
|
20
|
+
# The surname of the card holder.
|
|
24
21
|
# @return [Mindee::TextField]
|
|
25
22
|
attr_reader :surname
|
|
26
|
-
#
|
|
27
|
-
# @return [Mindee::TextField]
|
|
28
|
-
attr_reader :given_names
|
|
29
|
-
# The date of birth of the cardholder.
|
|
23
|
+
# The date of birth of the card holder.
|
|
30
24
|
# @return [Mindee::DateField]
|
|
31
25
|
attr_reader :birth_date
|
|
32
|
-
# The place of birth of the
|
|
26
|
+
# The place of birth of the card holder.
|
|
33
27
|
# @return [Mindee::TextField]
|
|
34
28
|
attr_reader :birth_place
|
|
35
|
-
# The
|
|
29
|
+
# The expiry date of the identification card.
|
|
30
|
+
# @return [Mindee::DateField]
|
|
31
|
+
attr_reader :expiry_date
|
|
32
|
+
# The name of the issuing authority.
|
|
33
|
+
# @return [Mindee::TextField]
|
|
34
|
+
attr_reader :authority
|
|
35
|
+
# The gender of the card holder.
|
|
36
36
|
# @return [Mindee::TextField]
|
|
37
37
|
attr_reader :gender
|
|
38
|
-
#
|
|
38
|
+
# Machine Readable Zone, first line
|
|
39
39
|
# @return [Mindee::TextField]
|
|
40
40
|
attr_reader :mrz1
|
|
41
|
-
#
|
|
41
|
+
# Machine Readable Zone, second line
|
|
42
42
|
# @return [Mindee::TextField]
|
|
43
43
|
attr_reader :mrz2
|
|
44
44
|
|
|
@@ -49,33 +49,34 @@ module Mindee
|
|
|
49
49
|
@document_side = TextField.new(prediction['document_side'], page_id) if page_id
|
|
50
50
|
@authority = TextField.new(prediction['authority'], page_id)
|
|
51
51
|
@id_number = TextField.new(prediction['id_number'], page_id)
|
|
52
|
+
@given_names = []
|
|
53
|
+
prediction['given_names'].each do |item|
|
|
54
|
+
@given_names.push(TextField.new(item, page_id))
|
|
55
|
+
end
|
|
56
|
+
@surname = TextField.new(prediction['surname'], page_id)
|
|
52
57
|
@birth_date = DateField.new(prediction['birth_date'], page_id)
|
|
53
|
-
@expiry_date = DateField.new(prediction['expiry_date'], page_id)
|
|
54
58
|
@birth_place = TextField.new(prediction['birth_place'], page_id)
|
|
59
|
+
@expiry_date = DateField.new(prediction['expiry_date'], page_id)
|
|
60
|
+
@authority = TextField.new(prediction['authority'], page_id)
|
|
55
61
|
@gender = TextField.new(prediction['gender'], page_id)
|
|
56
|
-
@surname = TextField.new(prediction['surname'], page_id)
|
|
57
62
|
@mrz1 = TextField.new(prediction['mrz1'], page_id)
|
|
58
63
|
@mrz2 = TextField.new(prediction['mrz2'], page_id)
|
|
59
|
-
@given_names = []
|
|
60
|
-
prediction['given_names'].each do |item|
|
|
61
|
-
@given_names.push(TextField.new(item, page_id))
|
|
62
|
-
end
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
def to_s
|
|
66
|
-
given_names = @given_names.
|
|
67
|
+
given_names = @given_names.join("\n #{' ' * 15}")
|
|
67
68
|
out_str = String.new
|
|
68
|
-
out_str << "\n:Document
|
|
69
|
-
out_str << "\n:
|
|
70
|
-
out_str << "\n:Given
|
|
69
|
+
out_str << "\n:Document Side: #{@document_side}".rstrip if @document_side
|
|
70
|
+
out_str << "\n:Identity Number: #{@id_number}".rstrip
|
|
71
|
+
out_str << "\n:Given Name(s): #{given_names}".rstrip
|
|
71
72
|
out_str << "\n:Surname: #{@surname}".rstrip
|
|
73
|
+
out_str << "\n:Date of Birth: #{@birth_date}".rstrip
|
|
74
|
+
out_str << "\n:Place of Birth: #{@birth_place}".rstrip
|
|
75
|
+
out_str << "\n:Expiry Date: #{@expiry_date}".rstrip
|
|
76
|
+
out_str << "\n:Issuing Authority: #{@authority}".rstrip
|
|
72
77
|
out_str << "\n:Gender: #{@gender}".rstrip
|
|
73
|
-
out_str << "\n:
|
|
74
|
-
out_str << "\n:
|
|
75
|
-
out_str << "\n:Birth place: #{@birth_place}".rstrip
|
|
76
|
-
out_str << "\n:Expiry date: #{@expiry_date}".rstrip
|
|
77
|
-
out_str << "\n:MRZ 1: #{@mrz1}".rstrip
|
|
78
|
-
out_str << "\n:MRZ 2: #{@mrz2}".rstrip
|
|
78
|
+
out_str << "\n:MRZ Line 1: #{@mrz1}".rstrip
|
|
79
|
+
out_str << "\n:MRZ Line 2: #{@mrz2}".rstrip
|
|
79
80
|
out_str[1..].to_s
|
|
80
81
|
end
|
|
81
82
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative '../common_fields'
|
|
4
|
-
require_relative 'invoice_line_item'
|
|
5
4
|
require_relative '../base'
|
|
5
|
+
require_relative 'invoice_v4_line_item'
|
|
6
6
|
|
|
7
7
|
module Mindee
|
|
8
8
|
module Prediction
|
|
@@ -60,7 +60,7 @@ module Mindee
|
|
|
60
60
|
# @return [Array<Mindee::CompanyRegistration>]
|
|
61
61
|
attr_reader :supplier_company_registrations
|
|
62
62
|
# Line items details.
|
|
63
|
-
# @return [Array<Mindee::
|
|
63
|
+
# @return [Array<Mindee::InvoiceV4LineItem>]
|
|
64
64
|
attr_reader :line_items
|
|
65
65
|
|
|
66
66
|
# @param prediction [Hash]
|
|
@@ -78,7 +78,6 @@ module Mindee
|
|
|
78
78
|
@invoice_number = TextField.new(prediction['invoice_number'], page_id)
|
|
79
79
|
@supplier_name = TextField.new(prediction['supplier_name'], page_id)
|
|
80
80
|
@supplier_address = TextField.new(prediction['supplier_address'], page_id)
|
|
81
|
-
|
|
82
81
|
@reference_numbers = []
|
|
83
82
|
prediction['reference_numbers'].each do |item|
|
|
84
83
|
@reference_numbers.push(TextField.new(item, page_id))
|
|
@@ -99,14 +98,12 @@ module Mindee
|
|
|
99
98
|
prediction['supplier_company_registrations'].each do |item|
|
|
100
99
|
@supplier_company_registrations.push(CompanyRegistration.new(item, page_id))
|
|
101
100
|
end
|
|
102
|
-
|
|
103
101
|
@total_tax = AmountField.new(
|
|
104
102
|
{ value: nil, confidence: 0.0 }, page_id
|
|
105
103
|
)
|
|
106
|
-
|
|
107
104
|
@line_items = []
|
|
108
105
|
prediction['line_items'].each do |item|
|
|
109
|
-
@line_items.push(
|
|
106
|
+
@line_items.push(InvoiceV4LineItem.new(item, page_id))
|
|
110
107
|
end
|
|
111
108
|
reconstruct(page_id)
|
|
112
109
|
end
|
|
@@ -124,39 +121,38 @@ module Mindee
|
|
|
124
121
|
out_str << "\n:Reference numbers: #{reference_numbers}".rstrip
|
|
125
122
|
out_str << "\n:Invoice date: #{@date}".rstrip
|
|
126
123
|
out_str << "\n:Invoice due date: #{@due_date}".rstrip
|
|
127
|
-
|
|
128
124
|
out_str << "\n:Supplier name: #{@supplier_name}".rstrip
|
|
129
125
|
out_str << "\n:Supplier address: #{@supplier_address}".rstrip
|
|
130
126
|
out_str << "\n:Supplier company registrations: #{supplier_company_registrations}".rstrip
|
|
131
127
|
out_str << "\n:Supplier payment details: #{supplier_payment_details}".rstrip
|
|
132
|
-
|
|
133
128
|
out_str << "\n:Customer name: #{@customer_name}".rstrip
|
|
134
129
|
out_str << "\n:Customer address: #{@customer_address}".rstrip
|
|
135
130
|
out_str << "\n:Customer company registrations: #{customer_company_registrations}".rstrip
|
|
136
|
-
|
|
137
131
|
out_str << "\n:Taxes: #{taxes}".rstrip
|
|
138
132
|
out_str << "\n:Total net: #{@total_net}".rstrip
|
|
139
133
|
out_str << "\n:Total taxes: #{@total_tax}".rstrip
|
|
140
134
|
out_str << "\n:Total amount: #{@total_amount}".rstrip
|
|
135
|
+
out_str << "\n:Line Items:"
|
|
141
136
|
out_str << line_items_to_s
|
|
142
|
-
|
|
143
137
|
out_str[1..].to_s
|
|
144
138
|
end
|
|
145
139
|
|
|
146
140
|
private
|
|
147
141
|
|
|
142
|
+
def line_item_separator(char)
|
|
143
|
+
" +#{char * 22}+#{char * 9}+#{char * 9}+#{char * 10}+#{char * 18}+#{char * 38}+"
|
|
144
|
+
end
|
|
145
|
+
|
|
148
146
|
def line_items_to_s
|
|
149
147
|
return '' if @line_items.empty?
|
|
150
148
|
|
|
151
|
-
|
|
152
|
-
line_items = @line_items.map(&:to_s).join("\n")
|
|
149
|
+
line_items = @line_items.map(&:to_s).join("\n#{line_item_separator('-')}\n ")
|
|
153
150
|
out_str = String.new
|
|
154
|
-
out_str << "\n
|
|
155
|
-
out_str << "\n#{
|
|
156
|
-
out_str << "\
|
|
157
|
-
out_str << "\n#{
|
|
158
|
-
out_str << "\n#{
|
|
159
|
-
out_str << "\n#{line_item_separator}" unless line_items.empty?
|
|
151
|
+
out_str << "\n#{line_item_separator('-')}"
|
|
152
|
+
out_str << "\n | Code#{' ' * 17}| QTY | Price | Amount | Tax (Rate) | Description #{' ' * 25}|"
|
|
153
|
+
out_str << "\n#{line_item_separator('=')}"
|
|
154
|
+
out_str << "\n #{line_items}"
|
|
155
|
+
out_str << "\n#{line_item_separator('-')}"
|
|
160
156
|
end
|
|
161
157
|
|
|
162
158
|
def reconstruct(page_id)
|
|
@@ -4,7 +4,7 @@ require_relative '../common_fields/base'
|
|
|
4
4
|
|
|
5
5
|
module Mindee
|
|
6
6
|
# Line items for invoices
|
|
7
|
-
class
|
|
7
|
+
class InvoiceV4LineItem
|
|
8
8
|
# @return [String] The product code referring to the item.
|
|
9
9
|
attr_reader :product_code
|
|
10
10
|
# @return [String]
|
|
@@ -39,20 +39,20 @@ module Mindee
|
|
|
39
39
|
@page_id = page_id
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# @return String
|
|
42
43
|
def to_s
|
|
43
44
|
tax = Field.float_to_string(@tax_amount)
|
|
44
45
|
tax << " (#{Field.float_to_string(@tax_rate)}%)" unless @tax_rate.nil?
|
|
45
|
-
|
|
46
46
|
description = @description.nil? ? '' : @description
|
|
47
47
|
description = "#{description[0..32]}..." if description.size > 35
|
|
48
|
-
|
|
49
48
|
out_str = String.new
|
|
50
|
-
out_str << format('%-
|
|
51
|
-
out_str << " #{format('%-
|
|
52
|
-
out_str << " #{format('%-
|
|
53
|
-
out_str << " #{format('%-
|
|
54
|
-
out_str << " #{format('%-
|
|
55
|
-
out_str << " #{description}"
|
|
49
|
+
out_str << format('| %- 20s', @product_code)
|
|
50
|
+
out_str << " #{format('| %- 7s', Field.float_to_string(@quantity))}"
|
|
51
|
+
out_str << " #{format('| %- 7s', Field.float_to_string(@unit_price))}"
|
|
52
|
+
out_str << " #{format('| %- 8s', Field.float_to_string(@total_amount))}"
|
|
53
|
+
out_str << " #{format('| %- 16s', tax)}"
|
|
54
|
+
out_str << " #{format('| %- 37s', description)}"
|
|
55
|
+
out_str << '|'
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'mrz'
|
|
4
|
-
|
|
5
3
|
require_relative '../common_fields'
|
|
6
4
|
require_relative '../base'
|
|
7
5
|
|
|
8
|
-
# We need to do this disgusting thing to avoid the following error message:
|
|
9
|
-
# td3 line one does not match the required format (MRZ::InvalidFormatError)
|
|
10
|
-
#
|
|
11
|
-
# See:
|
|
12
|
-
# https://github.com/streetspotr/mrz/issues/2
|
|
13
|
-
# https://github.com/streetspotr/mrz/pull/3
|
|
14
|
-
#
|
|
15
|
-
MRZ::TD3Parser::FORMAT_ONE = %r{\A(.{2})(.{3})([^<]+)<(.*)\z}.freeze
|
|
16
|
-
|
|
17
6
|
module Mindee
|
|
18
7
|
module Prediction
|
|
19
8
|
# Passport document.
|
|
@@ -78,7 +67,6 @@ module Mindee
|
|
|
78
67
|
end
|
|
79
68
|
@full_name = construct_full_name(page_id)
|
|
80
69
|
@mrz = construct_mrz(page_id)
|
|
81
|
-
check_mrz
|
|
82
70
|
end
|
|
83
71
|
|
|
84
72
|
def to_s
|
|
@@ -107,57 +95,6 @@ module Mindee
|
|
|
107
95
|
|
|
108
96
|
private
|
|
109
97
|
|
|
110
|
-
def check_mrz
|
|
111
|
-
return if @mrz1.value.nil? || @mrz2.value.nil?
|
|
112
|
-
|
|
113
|
-
mrz = MRZ.parse([@mrz1.value, @mrz2.value])
|
|
114
|
-
checks = {
|
|
115
|
-
mrz_valid: valid_mrz?(mrz),
|
|
116
|
-
mrz_valid_birth_date: valid_birth_date?(mrz),
|
|
117
|
-
mrz_valid_expiry_date: valid_expiry_date?(mrz),
|
|
118
|
-
mrz_valid_id_number: valid_id_number?(mrz),
|
|
119
|
-
mrz_valid_surname: valid_surname?(mrz),
|
|
120
|
-
mrz_valid_country: valid_country?(mrz),
|
|
121
|
-
}
|
|
122
|
-
@checklist.merge!(checks)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def valid_mrz?(mrz)
|
|
126
|
-
check = mrz.valid?
|
|
127
|
-
@mrz.confidence = 1.0 if check
|
|
128
|
-
check
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def valid_birth_date?(mrz)
|
|
132
|
-
check = mrz.valid_birth_date? && mrz.birth_date == @birth_date.date_object
|
|
133
|
-
@birth_date.confidence = 1.0 if check
|
|
134
|
-
check
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def valid_expiry_date?(mrz)
|
|
138
|
-
check = mrz.valid_expiration_date? && mrz.expiration_date == @expiry_date.date_object
|
|
139
|
-
@expiry_date.confidence = 1.0 if check
|
|
140
|
-
check
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def valid_id_number?(mrz)
|
|
144
|
-
check = mrz.valid_document_number? && mrz.document_number == @id_number.value
|
|
145
|
-
@id_number.confidence = 1.0 if check
|
|
146
|
-
check
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def valid_surname?(mrz)
|
|
150
|
-
check = mrz.last_name == @surname.value
|
|
151
|
-
@surname.confidence = 1.0 if check
|
|
152
|
-
check
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def valid_country?(mrz)
|
|
156
|
-
check = mrz.nationality == @country.value
|
|
157
|
-
@country.confidence = 1.0 if check
|
|
158
|
-
check
|
|
159
|
-
end
|
|
160
|
-
|
|
161
98
|
def construct_full_name(page_id)
|
|
162
99
|
return unless @surname.value &&
|
|
163
100
|
!@given_names.empty? &&
|
|
@@ -1,80 +1,78 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'mrz'
|
|
4
|
-
|
|
5
3
|
require_relative '../common_fields'
|
|
6
4
|
require_relative '../base'
|
|
7
5
|
|
|
8
6
|
module Mindee
|
|
9
7
|
module Prediction
|
|
10
|
-
#
|
|
8
|
+
# Proof of Address v1 prediction results.
|
|
11
9
|
class ProofOfAddressV1 < Prediction
|
|
12
|
-
#
|
|
10
|
+
# The locale detected on the document.
|
|
13
11
|
# @return [Mindee::Locale]
|
|
14
12
|
attr_reader :locale
|
|
15
|
-
#
|
|
16
|
-
# @return [Mindee::DateField]
|
|
17
|
-
attr_reader :date
|
|
18
|
-
# All extracted ISO date yyyy-mm-dd. Works both for European and US dates.
|
|
19
|
-
# @return [Array<Mindee::DateField>]
|
|
20
|
-
attr_reader :dates
|
|
21
|
-
# Address of the document's issuer.
|
|
13
|
+
# The name of the person or company issuing the document.
|
|
22
14
|
# @return [Mindee::TextField]
|
|
23
|
-
attr_reader :
|
|
24
|
-
#
|
|
25
|
-
# @return [Array<Mindee::
|
|
15
|
+
attr_reader :issuer_name
|
|
16
|
+
# List of company registrations found for the issuer.
|
|
17
|
+
# @return [Array<Mindee::CompanyRegistrationField>]
|
|
26
18
|
attr_reader :issuer_company_registration
|
|
27
|
-
#
|
|
19
|
+
# The address of the document's issuer.
|
|
28
20
|
# @return [Mindee::TextField]
|
|
29
|
-
attr_reader :
|
|
30
|
-
#
|
|
21
|
+
attr_reader :issuer_address
|
|
22
|
+
# The name of the person or company receiving the document.
|
|
31
23
|
# @return [Mindee::TextField]
|
|
32
|
-
attr_reader :
|
|
33
|
-
#
|
|
34
|
-
# @return [Array<Mindee::
|
|
24
|
+
attr_reader :recipient_name
|
|
25
|
+
# List of company registrations found for the recipient.
|
|
26
|
+
# @return [Array<Mindee::CompanyRegistrationField>]
|
|
35
27
|
attr_reader :recipient_company_registration
|
|
36
|
-
#
|
|
28
|
+
# The address of the recipient.
|
|
37
29
|
# @return [Mindee::TextField]
|
|
38
|
-
attr_reader :
|
|
30
|
+
attr_reader :recipient_address
|
|
31
|
+
# List of dates found on the document.
|
|
32
|
+
# @return [Array<Mindee::DateField>]
|
|
33
|
+
attr_reader :dates
|
|
34
|
+
# The date the document was issued.
|
|
35
|
+
# @return [Mindee::DateField]
|
|
36
|
+
attr_reader :date
|
|
39
37
|
|
|
40
38
|
# @param prediction [Hash]
|
|
41
39
|
# @param page_id [Integer, nil]
|
|
42
40
|
def initialize(prediction, page_id)
|
|
43
41
|
super
|
|
44
|
-
@locale = Locale.new(prediction['locale'])
|
|
45
|
-
@date = DateField.new(prediction['date'], page_id)
|
|
46
|
-
@dates = []
|
|
47
|
-
prediction['dates'].each do |item|
|
|
48
|
-
@dates.push(DateField.new(item, page_id))
|
|
49
|
-
end
|
|
42
|
+
@locale = Locale.new(prediction['locale'], page_id)
|
|
50
43
|
@issuer_name = TextField.new(prediction['issuer_name'], page_id)
|
|
51
|
-
@issuer_address = TextField.new(prediction['issuer_address'], page_id)
|
|
52
44
|
@issuer_company_registration = []
|
|
53
45
|
prediction['issuer_company_registration'].each do |item|
|
|
54
46
|
@issuer_company_registration.push(CompanyRegistration.new(item, page_id))
|
|
55
47
|
end
|
|
48
|
+
@issuer_address = TextField.new(prediction['issuer_address'], page_id)
|
|
56
49
|
@recipient_name = TextField.new(prediction['recipient_name'], page_id)
|
|
57
|
-
@recipient_address = TextField.new(prediction['recipient_address'], page_id)
|
|
58
50
|
@recipient_company_registration = []
|
|
59
51
|
prediction['recipient_company_registration'].each do |item|
|
|
60
52
|
@recipient_company_registration.push(CompanyRegistration.new(item, page_id))
|
|
61
53
|
end
|
|
54
|
+
@recipient_address = TextField.new(prediction['recipient_address'], page_id)
|
|
55
|
+
@dates = []
|
|
56
|
+
prediction['dates'].each do |item|
|
|
57
|
+
@dates.push(DateField.new(item, page_id))
|
|
58
|
+
end
|
|
59
|
+
@date = DateField.new(prediction['date'], page_id)
|
|
62
60
|
end
|
|
63
61
|
|
|
64
62
|
def to_s
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
dates = @dates.join("\n
|
|
63
|
+
issuer_company_registration = @issuer_company_registration.join("\n #{' ' * 30}")
|
|
64
|
+
recipient_company_registration = @recipient_company_registration.join("\n #{' ' * 33}")
|
|
65
|
+
dates = @dates.join("\n #{' ' * 7}")
|
|
68
66
|
out_str = String.new
|
|
69
67
|
out_str << "\n:Locale: #{@locale}".rstrip
|
|
70
|
-
out_str << "\n:Issuer
|
|
68
|
+
out_str << "\n:Issuer Name: #{@issuer_name}".rstrip
|
|
69
|
+
out_str << "\n:Issuer Company Registrations: #{issuer_company_registration}".rstrip
|
|
71
70
|
out_str << "\n:Issuer Address: #{@issuer_address}".rstrip
|
|
72
|
-
out_str << "\n:
|
|
73
|
-
out_str << "\n:Recipient
|
|
71
|
+
out_str << "\n:Recipient Name: #{@recipient_name}".rstrip
|
|
72
|
+
out_str << "\n:Recipient Company Registrations: #{recipient_company_registration}".rstrip
|
|
74
73
|
out_str << "\n:Recipient Address: #{@recipient_address}".rstrip
|
|
75
|
-
out_str << "\n:Recipient Company Registrations: #{recipient_company_registrations}".rstrip
|
|
76
|
-
out_str << "\n:Issuance date: #{@date}".rstrip
|
|
77
74
|
out_str << "\n:Dates: #{dates}".rstrip
|
|
75
|
+
out_str << "\n:Date of Issue: #{@date}".rstrip
|
|
78
76
|
out_str[1..].to_s
|
|
79
77
|
end
|
|
80
78
|
end
|