mindee 2.2.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +2 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +36 -0
- data/README.md +29 -16
- data/bin/mindee.rb +23 -26
- data/docs/code_samples/bank_account_details_v1.txt +10 -5
- data/docs/code_samples/bank_account_details_v2.txt +19 -0
- data/docs/code_samples/bank_check_v1.txt +10 -5
- data/docs/code_samples/carte_vitale_v1.txt +10 -5
- data/docs/code_samples/custom_v1.txt +19 -10
- data/docs/code_samples/default.txt +10 -2
- data/docs/code_samples/expense_receipts_v4.txt +10 -5
- data/docs/code_samples/expense_receipts_v5.txt +11 -6
- data/docs/code_samples/financial_document_v1.txt +10 -5
- data/docs/code_samples/idcard_fr_v1.txt +10 -5
- data/docs/code_samples/invoice_splitter_v1_async.txt +66 -0
- data/docs/code_samples/invoices_v4.txt +10 -5
- data/docs/code_samples/license_plates_v1.txt +10 -5
- data/docs/code_samples/passport_v1.txt +10 -5
- data/docs/code_samples/proof_of_address_v1.txt +10 -5
- data/docs/ruby-api-builder.md +30 -31
- data/docs/ruby-getting-started.md +64 -23
- data/docs/ruby-invoice-ocr.md +70 -59
- data/docs/ruby-passport-ocr.md +49 -40
- data/docs/ruby-receipt-ocr.md +45 -32
- data/lib/mindee/client.rb +150 -148
- data/lib/mindee/geometry/min_max.rb +23 -0
- data/lib/mindee/geometry/point.rb +35 -0
- data/lib/mindee/geometry/polygon.rb +23 -0
- data/lib/mindee/geometry/quadrilateral.rb +45 -0
- data/lib/mindee/geometry/utils.rb +81 -0
- data/lib/mindee/geometry.rb +5 -116
- data/lib/mindee/http/endpoint.rb +123 -16
- data/lib/mindee/http.rb +3 -0
- data/lib/mindee/input/sources.rb +87 -73
- data/lib/mindee/parsing/common/api_response.rb +109 -0
- data/lib/mindee/parsing/common/document.rb +48 -0
- data/lib/mindee/parsing/common/error.rb +24 -0
- data/lib/mindee/parsing/common/inference.rb +43 -0
- data/lib/mindee/parsing/common/ocr/mvision_v1.rb +34 -0
- data/lib/mindee/parsing/common/ocr/ocr.rb +169 -0
- data/lib/mindee/parsing/common/ocr.rb +3 -0
- data/lib/mindee/parsing/common/orientation.rb +26 -0
- data/lib/mindee/parsing/common/page.rb +40 -0
- data/lib/mindee/parsing/common/prediction.rb +15 -0
- data/lib/mindee/parsing/common/product.rb +19 -0
- data/lib/mindee/parsing/common.rb +10 -0
- data/lib/mindee/parsing/custom/classification_field.rb +28 -0
- data/lib/mindee/parsing/custom/list_field.rb +76 -0
- data/lib/mindee/parsing/custom.rb +4 -0
- data/lib/mindee/parsing/standard/amount_field.rb +26 -0
- data/lib/mindee/parsing/standard/base_field.rb +104 -0
- data/lib/mindee/parsing/standard/classification_field.rb +16 -0
- data/lib/mindee/parsing/standard/company_registration_field.rb +21 -0
- data/lib/mindee/parsing/standard/date_field.rb +34 -0
- data/lib/mindee/parsing/standard/locale_field.rb +50 -0
- data/lib/mindee/parsing/standard/payment_details_field.rb +42 -0
- data/lib/mindee/parsing/standard/position_field.rb +44 -0
- data/lib/mindee/parsing/standard/tax_field.rb +108 -0
- data/lib/mindee/parsing/standard/text_field.rb +16 -0
- data/lib/mindee/parsing/standard.rb +12 -0
- data/lib/mindee/parsing.rb +3 -2
- data/lib/mindee/{input → pdf}/pdf_processing.rb +4 -32
- data/lib/mindee/pdf/pdf_tools.rb +34 -0
- data/lib/mindee/pdf.rb +3 -0
- data/lib/mindee/product/.rubocop.yml +5 -0
- data/lib/mindee/product/custom/custom_v1.rb +35 -0
- data/lib/mindee/product/custom/custom_v1_document.rb +60 -0
- data/lib/mindee/product/custom/custom_v1_page.rb +32 -0
- data/lib/mindee/product/eu/license_plate/license_plate_v1.rb +38 -0
- data/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb +37 -0
- data/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb +34 -0
- data/lib/mindee/product/financial_document/financial_document_v1.rb +36 -0
- data/lib/mindee/product/financial_document/financial_document_v1_document.rb +188 -0
- data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +90 -0
- data/lib/mindee/product/financial_document/financial_document_v1_page.rb +32 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +38 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb +43 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb +34 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +38 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +71 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb +58 -0
- data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb +34 -0
- data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb +38 -0
- data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_document.rb +52 -0
- data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_page.rb +34 -0
- data/lib/mindee/product/fr/id_card/id_card_v1.rb +38 -0
- data/lib/mindee/product/fr/id_card/id_card_v1_document.rb +82 -0
- data/lib/mindee/product/fr/id_card/id_card_v1_page.rb +48 -0
- data/lib/mindee/product/invoice/invoice_v4.rb +37 -0
- data/lib/mindee/product/invoice/invoice_v4_document.rb +212 -0
- data/lib/mindee/product/invoice/invoice_v4_line_item.rb +66 -0
- data/lib/mindee/product/invoice/invoice_v4_page.rb +32 -0
- data/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +36 -0
- data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +65 -0
- data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb +32 -0
- data/lib/mindee/product/passport/passport_v1.rb +36 -0
- data/lib/mindee/{parsing/prediction/fr/id_card/id_card_v1.rb → product/passport/passport_v1_document.rb} +45 -45
- data/lib/mindee/product/passport/passport_v1_page.rb +32 -0
- data/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +36 -0
- data/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb +83 -0
- data/lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb +32 -0
- data/lib/mindee/product/receipt/receipt_v4.rb +36 -0
- data/lib/mindee/product/receipt/receipt_v4_document.rb +86 -0
- data/lib/mindee/product/receipt/receipt_v4_page.rb +32 -0
- data/lib/mindee/product/receipt/receipt_v5.rb +36 -0
- data/lib/mindee/product/receipt/receipt_v5_document.rb +138 -0
- data/lib/mindee/product/receipt/receipt_v5_line_item.rb +69 -0
- data/lib/mindee/product/receipt/receipt_v5_page.rb +32 -0
- data/lib/mindee/product/us/bank_check/bank_check_v1.rb +38 -0
- data/lib/mindee/product/us/bank_check/bank_check_v1_document.rb +73 -0
- data/lib/mindee/product/us/bank_check/bank_check_v1_page.rb +34 -0
- data/lib/mindee/product.rb +16 -0
- data/lib/mindee/version.rb +2 -1
- data/lib/mindee.rb +3 -1
- metadata +87 -38
- data/docs/code_samples/shipping_containers_v1.txt +0 -14
- data/lib/mindee/document_config.rb +0 -60
- data/lib/mindee/parsing/document.rb +0 -31
- data/lib/mindee/parsing/error.rb +0 -22
- data/lib/mindee/parsing/inference.rb +0 -53
- data/lib/mindee/parsing/page.rb +0 -46
- data/lib/mindee/parsing/prediction/base.rb +0 -30
- data/lib/mindee/parsing/prediction/common_fields/amount.rb +0 -21
- data/lib/mindee/parsing/prediction/common_fields/base.rb +0 -72
- data/lib/mindee/parsing/prediction/common_fields/company_registration.rb +0 -17
- data/lib/mindee/parsing/prediction/common_fields/date.rb +0 -30
- data/lib/mindee/parsing/prediction/common_fields/locale.rb +0 -45
- data/lib/mindee/parsing/prediction/common_fields/payment_details.rb +0 -33
- data/lib/mindee/parsing/prediction/common_fields/position.rb +0 -39
- data/lib/mindee/parsing/prediction/common_fields/tax.rb +0 -40
- data/lib/mindee/parsing/prediction/common_fields/text.rb +0 -12
- data/lib/mindee/parsing/prediction/common_fields.rb +0 -11
- data/lib/mindee/parsing/prediction/custom/custom_v1.rb +0 -58
- data/lib/mindee/parsing/prediction/custom/fields.rb +0 -91
- data/lib/mindee/parsing/prediction/eu/license_plate/license_plate_v1.rb +0 -34
- data/lib/mindee/parsing/prediction/financial_document/financial_document_v1.rb +0 -237
- data/lib/mindee/parsing/prediction/financial_document/financial_document_v1_line_item.rb +0 -58
- data/lib/mindee/parsing/prediction/fr/bank_account_details/bank_account_details_v1.rb +0 -40
- data/lib/mindee/parsing/prediction/fr/carte_vitale/carte_vitale_v1.rb +0 -49
- data/lib/mindee/parsing/prediction/invoice/invoice_v4.rb +0 -212
- data/lib/mindee/parsing/prediction/invoice/invoice_v4_line_item.rb +0 -58
- data/lib/mindee/parsing/prediction/passport/passport_v1.rb +0 -121
- data/lib/mindee/parsing/prediction/proof_of_address/proof_of_address_v1.rb +0 -80
- data/lib/mindee/parsing/prediction/receipt/receipt_v4.rb +0 -87
- data/lib/mindee/parsing/prediction/receipt/receipt_v5.rb +0 -136
- data/lib/mindee/parsing/prediction/receipt/receipt_v5_line_item.rb +0 -37
- data/lib/mindee/parsing/prediction/shipping_container/shipping_container_v1.rb +0 -38
- data/lib/mindee/parsing/prediction/us/bank_check/bank_check_v1.rb +0 -70
- data/lib/mindee/parsing/prediction.rb +0 -15
@@ -1,212 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../common_fields'
|
4
|
-
require_relative '../base'
|
5
|
-
require_relative 'invoice_v4_line_item'
|
6
|
-
|
7
|
-
module Mindee
|
8
|
-
module Prediction
|
9
|
-
# Invoice document.
|
10
|
-
class InvoiceV4 < Prediction
|
11
|
-
# Locale information.
|
12
|
-
# @return [Mindee::Locale]
|
13
|
-
attr_reader :locale
|
14
|
-
# The nature of the invoice.
|
15
|
-
# @return [Mindee::TextField]
|
16
|
-
attr_reader :document_type
|
17
|
-
# The total amount with tax included.
|
18
|
-
# @return [Mindee::AmountField]
|
19
|
-
attr_reader :total_amount
|
20
|
-
# The total amount without the tax value.
|
21
|
-
# @return [Mindee::AmountField]
|
22
|
-
attr_reader :total_net
|
23
|
-
# The total tax.
|
24
|
-
# @return [Mindee::AmountField]
|
25
|
-
attr_reader :total_tax
|
26
|
-
# The creation date of the invoice.
|
27
|
-
# @return [Mindee::DateField]
|
28
|
-
attr_reader :date
|
29
|
-
# The invoice number.
|
30
|
-
# @return [Mindee::TextField]
|
31
|
-
attr_reader :invoice_number
|
32
|
-
# List of Reference numbers including PO number.
|
33
|
-
# @return [Mindee::TextField]
|
34
|
-
attr_reader :reference_numbers
|
35
|
-
# The due date of the invoice.
|
36
|
-
# @return [Mindee::DateField]
|
37
|
-
attr_reader :due_date
|
38
|
-
# The list of taxes.
|
39
|
-
# @return [Array<Mindee::TaxField>]
|
40
|
-
attr_reader :taxes
|
41
|
-
# The name of the customer.
|
42
|
-
# @return [Mindee::TextField]
|
43
|
-
attr_reader :customer_name
|
44
|
-
# The address of the customer.
|
45
|
-
# @return [Mindee::TextField]
|
46
|
-
attr_reader :customer_address
|
47
|
-
# The company registration information for the customer.
|
48
|
-
# @return [Array<Mindee::CompanyRegistration>]
|
49
|
-
attr_reader :customer_company_registrations
|
50
|
-
# The supplier's name.
|
51
|
-
# @return [Mindee::TextField]
|
52
|
-
attr_reader :supplier_name
|
53
|
-
# The supplier's address.
|
54
|
-
# @return [Mindee::TextField]
|
55
|
-
attr_reader :supplier_address
|
56
|
-
# The payment information.
|
57
|
-
# @return [Array<Mindee::PaymentDetails>]
|
58
|
-
attr_reader :supplier_payment_details
|
59
|
-
# The supplier's company registration information.
|
60
|
-
# @return [Array<Mindee::CompanyRegistration>]
|
61
|
-
attr_reader :supplier_company_registrations
|
62
|
-
# Line items details.
|
63
|
-
# @return [Array<Mindee::InvoiceV4LineItem>]
|
64
|
-
attr_reader :line_items
|
65
|
-
|
66
|
-
# @param prediction [Hash]
|
67
|
-
# @param page_id [Integer, nil]
|
68
|
-
def initialize(prediction, page_id)
|
69
|
-
super
|
70
|
-
@locale = Locale.new(prediction['locale'])
|
71
|
-
@document_type = TextField.new(prediction['document_type'], page_id)
|
72
|
-
@total_amount = AmountField.new(prediction['total_amount'], page_id)
|
73
|
-
@total_net = AmountField.new(prediction['total_net'], page_id)
|
74
|
-
@customer_address = TextField.new(prediction['customer_address'], page_id)
|
75
|
-
@customer_name = TextField.new(prediction['customer_name'], page_id)
|
76
|
-
@date = DateField.new(prediction['date'], page_id)
|
77
|
-
@due_date = DateField.new(prediction['due_date'], page_id)
|
78
|
-
@invoice_number = TextField.new(prediction['invoice_number'], page_id)
|
79
|
-
@supplier_name = TextField.new(prediction['supplier_name'], page_id)
|
80
|
-
@supplier_address = TextField.new(prediction['supplier_address'], page_id)
|
81
|
-
@reference_numbers = []
|
82
|
-
prediction['reference_numbers'].each do |item|
|
83
|
-
@reference_numbers.push(TextField.new(item, page_id))
|
84
|
-
end
|
85
|
-
@customer_company_registrations = []
|
86
|
-
prediction['customer_company_registrations'].each do |item|
|
87
|
-
@customer_company_registrations.push(CompanyRegistration.new(item, page_id))
|
88
|
-
end
|
89
|
-
@taxes = []
|
90
|
-
prediction['taxes'].each do |item|
|
91
|
-
@taxes.push(TaxField.new(item, page_id))
|
92
|
-
end
|
93
|
-
@supplier_payment_details = []
|
94
|
-
prediction['supplier_payment_details'].each do |item|
|
95
|
-
@supplier_payment_details.push(PaymentDetails.new(item, page_id))
|
96
|
-
end
|
97
|
-
@supplier_company_registrations = []
|
98
|
-
prediction['supplier_company_registrations'].each do |item|
|
99
|
-
@supplier_company_registrations.push(CompanyRegistration.new(item, page_id))
|
100
|
-
end
|
101
|
-
@total_tax = AmountField.new(
|
102
|
-
{ value: nil, confidence: 0.0 }, page_id
|
103
|
-
)
|
104
|
-
@line_items = []
|
105
|
-
prediction['line_items'].each do |item|
|
106
|
-
@line_items.push(InvoiceV4LineItem.new(item, page_id))
|
107
|
-
end
|
108
|
-
reconstruct(page_id)
|
109
|
-
end
|
110
|
-
|
111
|
-
def to_s
|
112
|
-
customer_company_registrations = @customer_company_registrations.map(&:value).join('; ')
|
113
|
-
supplier_payment_details = @supplier_payment_details.map(&:to_s).join("\n ")
|
114
|
-
supplier_company_registrations = @supplier_company_registrations.map(&:to_s).join('; ')
|
115
|
-
reference_numbers = @reference_numbers.map(&:to_s).join(', ')
|
116
|
-
taxes = @taxes.join("\n ")
|
117
|
-
out_str = String.new
|
118
|
-
out_str << "\n:Locale: #{@locale}".rstrip
|
119
|
-
out_str << "\n:Document type: #{@document_type}".rstrip
|
120
|
-
out_str << "\n:Invoice number: #{@invoice_number}".rstrip
|
121
|
-
out_str << "\n:Reference numbers: #{reference_numbers}".rstrip
|
122
|
-
out_str << "\n:Invoice date: #{@date}".rstrip
|
123
|
-
out_str << "\n:Invoice due date: #{@due_date}".rstrip
|
124
|
-
out_str << "\n:Supplier name: #{@supplier_name}".rstrip
|
125
|
-
out_str << "\n:Supplier address: #{@supplier_address}".rstrip
|
126
|
-
out_str << "\n:Supplier company registrations: #{supplier_company_registrations}".rstrip
|
127
|
-
out_str << "\n:Supplier payment details: #{supplier_payment_details}".rstrip
|
128
|
-
out_str << "\n:Customer name: #{@customer_name}".rstrip
|
129
|
-
out_str << "\n:Customer address: #{@customer_address}".rstrip
|
130
|
-
out_str << "\n:Customer company registrations: #{customer_company_registrations}".rstrip
|
131
|
-
out_str << "\n:Taxes: #{taxes}".rstrip
|
132
|
-
out_str << "\n:Total net: #{@total_net}".rstrip
|
133
|
-
out_str << "\n:Total taxes: #{@total_tax}".rstrip
|
134
|
-
out_str << "\n:Total amount: #{@total_amount}".rstrip
|
135
|
-
out_str << "\n:Line Items:"
|
136
|
-
out_str << line_items_to_s
|
137
|
-
out_str[1..].to_s
|
138
|
-
end
|
139
|
-
|
140
|
-
private
|
141
|
-
|
142
|
-
def line_item_separator(char)
|
143
|
-
" +#{char * 22}+#{char * 9}+#{char * 9}+#{char * 10}+#{char * 18}+#{char * 38}+"
|
144
|
-
end
|
145
|
-
|
146
|
-
def line_items_to_s
|
147
|
-
return '' if @line_items.empty?
|
148
|
-
|
149
|
-
line_items = @line_items.map(&:to_s).join("\n#{line_item_separator('-')}\n ")
|
150
|
-
out_str = String.new
|
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('-')}"
|
156
|
-
end
|
157
|
-
|
158
|
-
def reconstruct(page_id)
|
159
|
-
construct_total_tax_from_taxes(page_id)
|
160
|
-
return unless page_id.nil?
|
161
|
-
|
162
|
-
construct_total_excl_from_tcc_and_taxes(page_id)
|
163
|
-
construct_total_incl_from_taxes_plus_excl(page_id)
|
164
|
-
construct_total_tax_from_totals(page_id)
|
165
|
-
end
|
166
|
-
|
167
|
-
def construct_total_excl_from_tcc_and_taxes(page_id)
|
168
|
-
return if @total_amount.value.nil? || taxes.empty? || !@total_net.value.nil?
|
169
|
-
|
170
|
-
total_excl = {
|
171
|
-
'value' => @total_amount.value - @taxes.map(&:value).sum,
|
172
|
-
'confidence' => TextField.array_confidence(@taxes) * @total_amount.confidence,
|
173
|
-
}
|
174
|
-
@total_net = AmountField.new(total_excl, page_id, reconstructed: true)
|
175
|
-
end
|
176
|
-
|
177
|
-
def construct_total_incl_from_taxes_plus_excl(page_id)
|
178
|
-
return if @total_net.value.nil? || @taxes.empty? || !@total_amount.value.nil?
|
179
|
-
|
180
|
-
total_incl = {
|
181
|
-
'value' => @taxes.map(&:value).sum + @total_net.value,
|
182
|
-
'confidence' => TextField.array_confidence(@taxes) * @total_net.confidence,
|
183
|
-
}
|
184
|
-
@total_amount = AmountField.new(total_incl, page_id, reconstructed: true)
|
185
|
-
end
|
186
|
-
|
187
|
-
def construct_total_tax_from_taxes(page_id)
|
188
|
-
return if @taxes.empty?
|
189
|
-
|
190
|
-
total_tax = {
|
191
|
-
'value' => @taxes.map(&:value).sum,
|
192
|
-
'confidence' => TextField.array_confidence(@taxes),
|
193
|
-
}
|
194
|
-
return unless total_tax['value'].positive?
|
195
|
-
|
196
|
-
@total_tax = AmountField.new(total_tax, page_id, reconstructed: true)
|
197
|
-
end
|
198
|
-
|
199
|
-
def construct_total_tax_from_totals(page_id)
|
200
|
-
return if !@total_tax.value.nil? || @total_amount.value.nil? || @total_net.value.nil?
|
201
|
-
|
202
|
-
total_tax = {
|
203
|
-
'value' => @total_amount.value - @total_net.value,
|
204
|
-
'confidence' => TextField.array_confidence(@taxes),
|
205
|
-
}
|
206
|
-
return unless total_tax['value'] >= 0
|
207
|
-
|
208
|
-
@total_tax = AmountField.new(total_tax, page_id, reconstructed: true)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../common_fields/base'
|
4
|
-
|
5
|
-
module Mindee
|
6
|
-
# Line items for invoices
|
7
|
-
class InvoiceV4LineItem
|
8
|
-
# @return [String] The product code referring to the item.
|
9
|
-
attr_reader :product_code
|
10
|
-
# @return [String]
|
11
|
-
attr_reader :description
|
12
|
-
# @return [Float]
|
13
|
-
attr_reader :quantity
|
14
|
-
# @return [Float]
|
15
|
-
attr_reader :unit_price
|
16
|
-
# @return [Float]
|
17
|
-
attr_reader :total_amount
|
18
|
-
# @return [Float] The item tax rate percentage.
|
19
|
-
attr_reader :tax_rate
|
20
|
-
# @return [Float]
|
21
|
-
attr_reader :tax_amount
|
22
|
-
# @return [Float]
|
23
|
-
attr_reader :confidence
|
24
|
-
# @return [Integer]
|
25
|
-
attr_reader :page_id
|
26
|
-
# @return [Mindee::Geometry::Quadrilateral]
|
27
|
-
attr_reader :bounding_box
|
28
|
-
# @return [Array<Mindee::Geometry::Polygon>]
|
29
|
-
attr_reader :polygon
|
30
|
-
|
31
|
-
def initialize(prediction, page_id)
|
32
|
-
@product_code = prediction['product_code']
|
33
|
-
@quantity = prediction['quantity']
|
34
|
-
@unit_price = prediction['unit_price']
|
35
|
-
@total_amount = prediction['total_amount']
|
36
|
-
@tax_amount = prediction['tax_amount']
|
37
|
-
@tax_rate = prediction['tax_rate']
|
38
|
-
@description = prediction['description']
|
39
|
-
@page_id = page_id
|
40
|
-
end
|
41
|
-
|
42
|
-
# @return String
|
43
|
-
def to_s
|
44
|
-
tax = Field.float_to_string(@tax_amount)
|
45
|
-
tax << " (#{Field.float_to_string(@tax_rate)}%)" unless @tax_rate.nil?
|
46
|
-
description = @description.nil? ? '' : @description
|
47
|
-
description = "#{description[0..32]}..." if description.size > 35
|
48
|
-
out_str = String.new
|
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
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../common_fields'
|
4
|
-
require_relative '../base'
|
5
|
-
|
6
|
-
module Mindee
|
7
|
-
module Prediction
|
8
|
-
# Passport document.
|
9
|
-
class PassportV1 < Prediction
|
10
|
-
# The country of issue.
|
11
|
-
# @return [Mindee::TextField]
|
12
|
-
attr_reader :country
|
13
|
-
# The passport number.
|
14
|
-
# @return [Mindee::TextField]
|
15
|
-
attr_reader :id_number
|
16
|
-
# The expiration date of the passport.
|
17
|
-
# @return [Mindee::DateField]
|
18
|
-
attr_reader :expiry_date
|
19
|
-
# The issuance date of the passport.
|
20
|
-
# @return [Mindee::DateField]
|
21
|
-
attr_reader :issuance_date
|
22
|
-
# The surname (last name) of the passport holder.
|
23
|
-
# @return [Mindee::TextField]
|
24
|
-
attr_reader :surname
|
25
|
-
# List of first (given) names of the passport holder.
|
26
|
-
# @return [Mindee::TextField]
|
27
|
-
attr_reader :given_names
|
28
|
-
# The full name of the passport holder.
|
29
|
-
# @return [Array<Mindee::TextField>]
|
30
|
-
attr_reader :full_name
|
31
|
-
# The date of birth of the passport holder.
|
32
|
-
# @return [Mindee::DateField]
|
33
|
-
attr_reader :birth_date
|
34
|
-
# The place of birth of the passport holder.
|
35
|
-
# @return [Mindee::TextField]
|
36
|
-
attr_reader :birth_place
|
37
|
-
# The sex or gender of the passport holder.
|
38
|
-
# @return [Mindee::TextField]
|
39
|
-
attr_reader :gender
|
40
|
-
# The value of the first MRZ line.
|
41
|
-
# @return [Mindee::TextField]
|
42
|
-
attr_reader :mrz1
|
43
|
-
# The value of the second MRZ line.
|
44
|
-
# @return [Mindee::TextField]
|
45
|
-
attr_reader :mrz2
|
46
|
-
# All the MRZ values combined.
|
47
|
-
# @return [Mindee::TextField]
|
48
|
-
attr_reader :mrz
|
49
|
-
|
50
|
-
# @param prediction [Hash]
|
51
|
-
# @param page_id [Integer, nil]
|
52
|
-
def initialize(prediction, page_id)
|
53
|
-
super
|
54
|
-
@country = TextField.new(prediction['country'], page_id)
|
55
|
-
@id_number = TextField.new(prediction['id_number'], page_id)
|
56
|
-
@birth_date = DateField.new(prediction['birth_date'], page_id)
|
57
|
-
@expiry_date = DateField.new(prediction['expiry_date'], page_id)
|
58
|
-
@issuance_date = DateField.new(prediction['issuance_date'], page_id)
|
59
|
-
@birth_place = TextField.new(prediction['birth_place'], page_id)
|
60
|
-
@gender = TextField.new(prediction['gender'], page_id)
|
61
|
-
@surname = TextField.new(prediction['surname'], page_id)
|
62
|
-
@mrz1 = TextField.new(prediction['mrz1'], page_id)
|
63
|
-
@mrz2 = TextField.new(prediction['mrz2'], page_id)
|
64
|
-
@given_names = []
|
65
|
-
prediction['given_names'].each do |item|
|
66
|
-
@given_names.push(TextField.new(item, page_id))
|
67
|
-
end
|
68
|
-
@full_name = construct_full_name(page_id)
|
69
|
-
@mrz = construct_mrz(page_id)
|
70
|
-
end
|
71
|
-
|
72
|
-
def to_s
|
73
|
-
given_names = @given_names.join(' ')
|
74
|
-
out_str = String.new
|
75
|
-
out_str << "\n:Full name: #{@full_name}".rstrip
|
76
|
-
out_str << "\n:Given names: #{given_names}".rstrip
|
77
|
-
out_str << "\n:Surname: #{@surname}".rstrip
|
78
|
-
out_str << "\n:Country: #{@country}".rstrip
|
79
|
-
out_str << "\n:ID Number: #{@id_number}".rstrip
|
80
|
-
out_str << "\n:Issuance date: #{@issuance_date}".rstrip
|
81
|
-
out_str << "\n:Birth date: #{@birth_date}".rstrip
|
82
|
-
out_str << "\n:Expiry date: #{@expiry_date}".rstrip
|
83
|
-
out_str << "\n:MRZ 1: #{@mrz1}".rstrip
|
84
|
-
out_str << "\n:MRZ 2: #{@mrz2}".rstrip
|
85
|
-
out_str << "\n:MRZ: #{@mrz}".rstrip
|
86
|
-
out_str[1..].to_s
|
87
|
-
end
|
88
|
-
|
89
|
-
# @return [Boolean]
|
90
|
-
def expired?
|
91
|
-
return true unless @expiry_date.date_object
|
92
|
-
|
93
|
-
@expiry_date.date_object < Date.today
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def construct_full_name(page_id)
|
99
|
-
return unless @surname.value &&
|
100
|
-
!@given_names.empty? &&
|
101
|
-
@given_names[0].value
|
102
|
-
|
103
|
-
full_name = {
|
104
|
-
'value' => "#{@given_names[0].value} #{@surname.value}",
|
105
|
-
'confidence' => TextField.array_confidence([@surname, @given_names[0]]),
|
106
|
-
}
|
107
|
-
TextField.new(full_name, page_id, reconstructed: true)
|
108
|
-
end
|
109
|
-
|
110
|
-
def construct_mrz(page_id)
|
111
|
-
return if @mrz1.value.nil? || @mrz2.value.nil?
|
112
|
-
|
113
|
-
mrz = {
|
114
|
-
'value' => @mrz1.value + @mrz2.value,
|
115
|
-
'confidence' => Mindee::TextField.array_confidence([@mrz1, @mrz2]),
|
116
|
-
}
|
117
|
-
TextField.new(mrz, page_id, reconstructed: true)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../common_fields'
|
4
|
-
require_relative '../base'
|
5
|
-
|
6
|
-
module Mindee
|
7
|
-
module Prediction
|
8
|
-
# Proof of Address v1 prediction results.
|
9
|
-
class ProofOfAddressV1 < Prediction
|
10
|
-
# The locale detected on the document.
|
11
|
-
# @return [Mindee::Locale]
|
12
|
-
attr_reader :locale
|
13
|
-
# The name of the person or company issuing the document.
|
14
|
-
# @return [Mindee::TextField]
|
15
|
-
attr_reader :issuer_name
|
16
|
-
# List of company registrations found for the issuer.
|
17
|
-
# @return [Array<Mindee::CompanyRegistrationField>]
|
18
|
-
attr_reader :issuer_company_registration
|
19
|
-
# The address of the document's issuer.
|
20
|
-
# @return [Mindee::TextField]
|
21
|
-
attr_reader :issuer_address
|
22
|
-
# The name of the person or company receiving the document.
|
23
|
-
# @return [Mindee::TextField]
|
24
|
-
attr_reader :recipient_name
|
25
|
-
# List of company registrations found for the recipient.
|
26
|
-
# @return [Array<Mindee::CompanyRegistrationField>]
|
27
|
-
attr_reader :recipient_company_registration
|
28
|
-
# The address of the recipient.
|
29
|
-
# @return [Mindee::TextField]
|
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
|
37
|
-
|
38
|
-
# @param prediction [Hash]
|
39
|
-
# @param page_id [Integer, nil]
|
40
|
-
def initialize(prediction, page_id)
|
41
|
-
super
|
42
|
-
@locale = Locale.new(prediction['locale'], page_id)
|
43
|
-
@issuer_name = TextField.new(prediction['issuer_name'], page_id)
|
44
|
-
@issuer_company_registration = []
|
45
|
-
prediction['issuer_company_registration'].each do |item|
|
46
|
-
@issuer_company_registration.push(CompanyRegistration.new(item, page_id))
|
47
|
-
end
|
48
|
-
@issuer_address = TextField.new(prediction['issuer_address'], page_id)
|
49
|
-
@recipient_name = TextField.new(prediction['recipient_name'], page_id)
|
50
|
-
@recipient_company_registration = []
|
51
|
-
prediction['recipient_company_registration'].each do |item|
|
52
|
-
@recipient_company_registration.push(CompanyRegistration.new(item, page_id))
|
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)
|
60
|
-
end
|
61
|
-
|
62
|
-
def to_s
|
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}")
|
66
|
-
out_str = String.new
|
67
|
-
out_str << "\n:Locale: #{@locale}".rstrip
|
68
|
-
out_str << "\n:Issuer Name: #{@issuer_name}".rstrip
|
69
|
-
out_str << "\n:Issuer Company Registrations: #{issuer_company_registration}".rstrip
|
70
|
-
out_str << "\n:Issuer Address: #{@issuer_address}".rstrip
|
71
|
-
out_str << "\n:Recipient Name: #{@recipient_name}".rstrip
|
72
|
-
out_str << "\n:Recipient Company Registrations: #{recipient_company_registration}".rstrip
|
73
|
-
out_str << "\n:Recipient Address: #{@recipient_address}".rstrip
|
74
|
-
out_str << "\n:Dates: #{dates}".rstrip
|
75
|
-
out_str << "\n:Date of Issue: #{@date}".rstrip
|
76
|
-
out_str[1..].to_s
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../common_fields'
|
4
|
-
require_relative '../base'
|
5
|
-
|
6
|
-
module Mindee
|
7
|
-
module Prediction
|
8
|
-
# Receipt document.
|
9
|
-
class ReceiptV4 < Prediction
|
10
|
-
# Where the purchase was made, the language, and the currency.
|
11
|
-
# @return [Mindee::Locale]
|
12
|
-
attr_reader :locale
|
13
|
-
# Total including taxes
|
14
|
-
# @return [Mindee::AmountField]
|
15
|
-
attr_reader :total_amount
|
16
|
-
# Total amount of the purchase excluding taxes.
|
17
|
-
# @return [Mindee::AmountField]
|
18
|
-
attr_reader :total_net
|
19
|
-
# Total tax amount of the purchase.
|
20
|
-
# @return [Mindee::AmountField]
|
21
|
-
attr_reader :total_tax
|
22
|
-
# The purchase date.
|
23
|
-
# @return [Mindee::DateField]
|
24
|
-
attr_reader :date
|
25
|
-
# The name of the supplier or merchant, as seen on the receipt.
|
26
|
-
# @return [Mindee::TextField]
|
27
|
-
attr_reader :supplier
|
28
|
-
# List of taxes detected on the receipt.
|
29
|
-
# @return [Array<Mindee::TaxField>]
|
30
|
-
attr_reader :taxes
|
31
|
-
# Time as seen on the receipt in HH:MM format.
|
32
|
-
# @return [Mindee::TextField]
|
33
|
-
attr_reader :time
|
34
|
-
# The receipt category among predefined classes.
|
35
|
-
# @return [Mindee::TextField]
|
36
|
-
attr_reader :category
|
37
|
-
# The receipt sub-category among predefined classes.
|
38
|
-
# @return [Mindee::TextField]
|
39
|
-
attr_reader :subcategory
|
40
|
-
# Whether the document is an expense receipt or a credit card receipt.
|
41
|
-
# @return [Mindee::TextField]
|
42
|
-
attr_reader :document_type
|
43
|
-
# Total amount of tip and gratuity. Both typed and handwritten characters are supported.
|
44
|
-
# @return [Mindee::AmountField]
|
45
|
-
attr_reader :tip
|
46
|
-
|
47
|
-
# @param prediction [Hash]
|
48
|
-
# @param page_id [Integer, nil]
|
49
|
-
def initialize(prediction, page_id)
|
50
|
-
super
|
51
|
-
@locale = Locale.new(prediction['locale'])
|
52
|
-
@total_amount = AmountField.new(prediction['total_amount'], page_id)
|
53
|
-
@total_net = AmountField.new(prediction['total_net'], page_id)
|
54
|
-
@total_tax = AmountField.new(prediction['total_tax'], page_id)
|
55
|
-
@tip = AmountField.new(prediction['tip'], page_id)
|
56
|
-
@date = DateField.new(prediction['date'], page_id)
|
57
|
-
@category = TextField.new(prediction['category'], page_id)
|
58
|
-
@subcategory = TextField.new(prediction['subcategory'], page_id)
|
59
|
-
@document_type = TextField.new(prediction['document_type'], page_id)
|
60
|
-
@supplier = TextField.new(prediction['supplier'], page_id)
|
61
|
-
@time = TextField.new(prediction['time'], page_id)
|
62
|
-
@taxes = []
|
63
|
-
prediction['taxes'].each do |item|
|
64
|
-
@taxes.push(TaxField.new(item, page_id))
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def to_s
|
69
|
-
taxes = @taxes.join("\n ")
|
70
|
-
out_str = String.new
|
71
|
-
out_str << "\n:Locale: #{@locale}".rstrip
|
72
|
-
out_str << "\n:Date: #{@date}".rstrip
|
73
|
-
out_str << "\n:Category: #{@category}".rstrip
|
74
|
-
out_str << "\n:Subcategory: #{@subcategory}".rstrip
|
75
|
-
out_str << "\n:Document type: #{@document_type}".rstrip
|
76
|
-
out_str << "\n:Time: #{@time}".rstrip
|
77
|
-
out_str << "\n:Supplier name: #{@supplier}".rstrip
|
78
|
-
out_str << "\n:Taxes: #{taxes}".rstrip
|
79
|
-
out_str << "\n:Total net: #{@total_net}".rstrip
|
80
|
-
out_str << "\n:Total taxes: #{@total_tax}".rstrip
|
81
|
-
out_str << "\n:Tip: #{@tip}".rstrip
|
82
|
-
out_str << "\n:Total amount: #{@total_amount}".rstrip
|
83
|
-
out_str[1..].to_s
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|