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,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mindee
|
4
|
-
# Document classification (custom docs)
|
5
|
-
class ClassificationField
|
6
|
-
# The classification value
|
7
|
-
# @return [String]
|
8
|
-
attr_reader :value
|
9
|
-
# The confidence score, value will be between 0.0 and 1.0
|
10
|
-
# @return [Float]
|
11
|
-
attr_accessor :confidence
|
12
|
-
|
13
|
-
# @param prediction [Hash]
|
14
|
-
def initialize(prediction)
|
15
|
-
@value = prediction['value']
|
16
|
-
@confidence = prediction['confidence']
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
@value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Field in a list.
|
25
|
-
class ListFieldItem
|
26
|
-
# The confidence score, value will be between 0.0 and 1.0
|
27
|
-
# @return [Float]
|
28
|
-
attr_accessor :confidence
|
29
|
-
# @return [Mindee::Geometry::Quadrilateral]
|
30
|
-
attr_reader :bounding_box
|
31
|
-
# @return [Mindee::Geometry::Polygon]
|
32
|
-
attr_reader :polygon
|
33
|
-
attr_reader :content
|
34
|
-
|
35
|
-
# @param prediction [Hash]
|
36
|
-
def initialize(prediction)
|
37
|
-
@content = prediction['content']
|
38
|
-
@confidence = prediction['confidence']
|
39
|
-
@polygon = Geometry.polygon_from_prediction(prediction['polygon'])
|
40
|
-
@bounding_box = Geometry.get_bounding_box(@polygon) unless @polygon.nil? || @polygon.empty?
|
41
|
-
end
|
42
|
-
|
43
|
-
# @return [String]
|
44
|
-
def to_s
|
45
|
-
@content.to_s
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Field where actual values are kept in a list (custom docs).
|
50
|
-
class ListField
|
51
|
-
# @return [Array<Mindee::ListFieldItem>]
|
52
|
-
attr_reader :values
|
53
|
-
# @return [Integer, nil]
|
54
|
-
attr_reader :page_id
|
55
|
-
# true if the field was reconstructed or computed using other fields.
|
56
|
-
# @return [Boolean]
|
57
|
-
attr_reader :reconstructed
|
58
|
-
# The confidence score, value will be between 0.0 and 1.0
|
59
|
-
# @return [Float]
|
60
|
-
attr_accessor :confidence
|
61
|
-
|
62
|
-
# @param prediction [Hash]
|
63
|
-
# @param page_id [Integer, nil]
|
64
|
-
# @param reconstructed [Boolean]
|
65
|
-
def initialize(prediction, page_id, reconstructed: false)
|
66
|
-
@values = []
|
67
|
-
@confidence = prediction['confidence']
|
68
|
-
@page_id = page_id || prediction['page_id']
|
69
|
-
@reconstructed = reconstructed
|
70
|
-
|
71
|
-
prediction['values'].each do |field|
|
72
|
-
@values.push(ListFieldItem.new(field))
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# @return [Array]
|
77
|
-
def contents_list
|
78
|
-
@values.map(&:content)
|
79
|
-
end
|
80
|
-
|
81
|
-
# @return [String]
|
82
|
-
def contents_str(separator: ' ')
|
83
|
-
@values.map(&:to_s).join(separator)
|
84
|
-
end
|
85
|
-
|
86
|
-
# @return [String]
|
87
|
-
def to_s
|
88
|
-
contents_str(separator: ' ')
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,34 +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
|
-
module EU
|
9
|
-
# License Plate v1 prediction results.
|
10
|
-
class LicensePlateV1 < Prediction
|
11
|
-
# List of all license plates found in the image.
|
12
|
-
# @return [Array<Mindee::TextField>]
|
13
|
-
attr_reader :license_plates
|
14
|
-
|
15
|
-
# @param prediction [Hash]
|
16
|
-
# @param page_id [Integer, nil]
|
17
|
-
def initialize(prediction, page_id)
|
18
|
-
super
|
19
|
-
@license_plates = []
|
20
|
-
prediction['license_plates'].each do |item|
|
21
|
-
@license_plates.push(TextField.new(item, page_id))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_s
|
26
|
-
license_plates = @license_plates.join("\n #{' ' * 16}")
|
27
|
-
out_str = String.new
|
28
|
-
out_str << "\n:License Plates: #{license_plates}".rstrip
|
29
|
-
out_str[1..].to_s
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,237 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../common_fields'
|
4
|
-
require_relative '../base'
|
5
|
-
require_relative 'financial_document_v1_line_item'
|
6
|
-
|
7
|
-
module Mindee
|
8
|
-
module Prediction
|
9
|
-
# Invoice document.
|
10
|
-
class FinancialDocumentV1 < Prediction
|
11
|
-
# Locale information.
|
12
|
-
# @return [Mindee::Locale]
|
13
|
-
attr_reader :locale
|
14
|
-
# The nature of the document.
|
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 document.
|
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 supplier's 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::FinancialDocumentV1LineItem>]
|
64
|
-
attr_reader :line_items
|
65
|
-
# Time as seen on the receipt in HH:MM format.
|
66
|
-
# @return [Mindee::TextField]
|
67
|
-
attr_reader :time
|
68
|
-
# The invoice or receipt category among predefined classes.
|
69
|
-
# @return [Mindee::TextField]
|
70
|
-
attr_reader :category
|
71
|
-
# The invoice or receipt sub-category among predefined classes.
|
72
|
-
# @return [Mindee::TextField]
|
73
|
-
attr_reader :subcategory
|
74
|
-
# A classification field, that can return 4 values:
|
75
|
-
# `EXPENSE RECEIPT`, `CREDIT CARD RECEIPT`, `INVOICE`, `CREDIT NOTE`
|
76
|
-
# @return [Mindee::TextField]
|
77
|
-
attr_reader :document_type # rubocop:todo Lint/DuplicateMethods
|
78
|
-
# Total amount of tip and gratuity. Both typed and handwritten characters are supported.
|
79
|
-
# @return [Mindee::AmountField]
|
80
|
-
attr_reader :tip
|
81
|
-
|
82
|
-
# @param prediction [Hash]
|
83
|
-
# @param page_id [Integer, nil]
|
84
|
-
def initialize(prediction, page_id) # rubocop:todo Metrics/AbcSize
|
85
|
-
super
|
86
|
-
@time = TextField.new(prediction['time'], page_id)
|
87
|
-
@category = TextField.new(prediction['category'], page_id)
|
88
|
-
@subcategory = TextField.new(prediction['subcategory'], page_id)
|
89
|
-
@document_type = TextField.new(prediction['document_type'], page_id)
|
90
|
-
@tip = AmountField.new(prediction['tip'], page_id)
|
91
|
-
@locale = Locale.new(prediction['locale'])
|
92
|
-
@document_type = TextField.new(prediction['document_type'], page_id)
|
93
|
-
@total_amount = AmountField.new(prediction['total_amount'], page_id)
|
94
|
-
@total_net = AmountField.new(prediction['total_net'], page_id)
|
95
|
-
@customer_address = TextField.new(prediction['customer_address'], page_id)
|
96
|
-
@customer_name = TextField.new(prediction['customer_name'], page_id)
|
97
|
-
@date = DateField.new(prediction['date'], page_id)
|
98
|
-
@due_date = DateField.new(prediction['due_date'], page_id)
|
99
|
-
@invoice_number = TextField.new(prediction['invoice_number'], page_id)
|
100
|
-
@supplier_name = TextField.new(prediction['supplier_name'], page_id)
|
101
|
-
@supplier_address = TextField.new(prediction['supplier_address'], page_id)
|
102
|
-
@reference_numbers = []
|
103
|
-
prediction['reference_numbers'].each do |item|
|
104
|
-
@reference_numbers.push(TextField.new(item, page_id))
|
105
|
-
end
|
106
|
-
@customer_company_registrations = []
|
107
|
-
prediction['customer_company_registrations'].each do |item|
|
108
|
-
@customer_company_registrations.push(CompanyRegistration.new(item, page_id))
|
109
|
-
end
|
110
|
-
@taxes = []
|
111
|
-
prediction['taxes'].each do |item|
|
112
|
-
@taxes.push(TaxField.new(item, page_id))
|
113
|
-
end
|
114
|
-
@supplier_payment_details = []
|
115
|
-
prediction['supplier_payment_details'].each do |item|
|
116
|
-
@supplier_payment_details.push(PaymentDetails.new(item, page_id))
|
117
|
-
end
|
118
|
-
@supplier_company_registrations = []
|
119
|
-
prediction['supplier_company_registrations'].each do |item|
|
120
|
-
@supplier_company_registrations.push(CompanyRegistration.new(item, page_id))
|
121
|
-
end
|
122
|
-
@total_tax = AmountField.new(
|
123
|
-
{ value: nil, confidence: 0.0 }, page_id
|
124
|
-
)
|
125
|
-
@line_items = []
|
126
|
-
prediction['line_items'].each do |item|
|
127
|
-
@line_items.push(FinancialDocumentV1LineItem.new(item, page_id))
|
128
|
-
end
|
129
|
-
reconstruct(page_id)
|
130
|
-
end
|
131
|
-
|
132
|
-
def to_s
|
133
|
-
customer_company_registrations = @customer_company_registrations.map(&:value).join('; ')
|
134
|
-
supplier_payment_details = @supplier_payment_details.map(&:to_s).join("\n ")
|
135
|
-
supplier_company_registrations = @supplier_company_registrations.map(&:to_s).join('; ')
|
136
|
-
reference_numbers = @reference_numbers.map(&:to_s).join(', ')
|
137
|
-
taxes = @taxes.join("\n ")
|
138
|
-
out_str = String.new
|
139
|
-
out_str << "\n:Document type: #{@document_type}".rstrip
|
140
|
-
out_str << "\n:Category: #{@category}".rstrip
|
141
|
-
out_str << "\n:Subcategory: #{@subcategory}".rstrip
|
142
|
-
out_str << "\n:Locale: #{@locale}".rstrip
|
143
|
-
out_str << "\n:Date: #{@date}".rstrip
|
144
|
-
out_str << "\n:Due date: #{@due_date}".rstrip
|
145
|
-
out_str << "\n:Time: #{@time}".rstrip
|
146
|
-
out_str << "\n:Number: #{@invoice_number}".rstrip
|
147
|
-
out_str << "\n:Reference numbers: #{reference_numbers}".rstrip
|
148
|
-
out_str << "\n:Supplier name: #{@supplier_name}".rstrip
|
149
|
-
out_str << "\n:Supplier address: #{@supplier_address}".rstrip
|
150
|
-
out_str << "\n:Supplier company registrations: #{supplier_company_registrations}".rstrip
|
151
|
-
out_str << "\n:Supplier payment details: #{supplier_payment_details}".rstrip
|
152
|
-
out_str << "\n:Customer name: #{@customer_name}".rstrip
|
153
|
-
out_str << "\n:Customer address: #{@customer_address}".rstrip
|
154
|
-
out_str << "\n:Customer company registrations: #{customer_company_registrations}".rstrip
|
155
|
-
out_str << "\n:Tip: #{@tip}".rstrip
|
156
|
-
out_str << "\n:Taxes: #{taxes}".rstrip
|
157
|
-
out_str << "\n:Total taxes: #{@total_tax}".rstrip
|
158
|
-
out_str << "\n:Total net: #{@total_net}".rstrip
|
159
|
-
out_str << "\n:Total amount: #{@total_amount}".rstrip
|
160
|
-
out_str << "\n:Line Items:"
|
161
|
-
out_str << line_items_to_s
|
162
|
-
out_str[1..].to_s
|
163
|
-
end
|
164
|
-
|
165
|
-
private
|
166
|
-
|
167
|
-
def line_item_separator(char)
|
168
|
-
" +#{char * 22}+#{char * 9}+#{char * 9}+#{char * 10}+#{char * 18}+#{char * 38}+"
|
169
|
-
end
|
170
|
-
|
171
|
-
def line_items_to_s
|
172
|
-
return '' if @line_items.empty?
|
173
|
-
|
174
|
-
line_items = @line_items.map(&:to_s).join("\n#{line_item_separator('-')}\n ")
|
175
|
-
out_str = String.new
|
176
|
-
out_str << "\n#{line_item_separator('-')}"
|
177
|
-
out_str << "\n | Code#{' ' * 17}| QTY | Price | Amount | Tax (Rate) | Description#{' ' * 26}|"
|
178
|
-
out_str << "\n#{line_item_separator('=')}"
|
179
|
-
out_str << "\n #{line_items}"
|
180
|
-
out_str << "\n#{line_item_separator('-')}"
|
181
|
-
end
|
182
|
-
|
183
|
-
def reconstruct(page_id)
|
184
|
-
construct_total_tax_from_taxes(page_id)
|
185
|
-
return unless page_id.nil?
|
186
|
-
|
187
|
-
construct_total_excl_from_tcc_and_taxes(page_id)
|
188
|
-
construct_total_incl_from_taxes_plus_excl(page_id)
|
189
|
-
construct_total_tax_from_totals(page_id)
|
190
|
-
end
|
191
|
-
|
192
|
-
def construct_total_excl_from_tcc_and_taxes(page_id)
|
193
|
-
return if @total_amount.value.nil? || taxes.empty? || !@total_net.value.nil?
|
194
|
-
|
195
|
-
total_excl = {
|
196
|
-
'value' => @total_amount.value - @taxes.map(&:value).sum,
|
197
|
-
'confidence' => TextField.array_confidence(@taxes) * @total_amount.confidence,
|
198
|
-
}
|
199
|
-
@total_net = AmountField.new(total_excl, page_id, reconstructed: true)
|
200
|
-
end
|
201
|
-
|
202
|
-
def construct_total_incl_from_taxes_plus_excl(page_id)
|
203
|
-
return if @total_net.value.nil? || @taxes.empty? || !@total_amount.value.nil?
|
204
|
-
|
205
|
-
total_incl = {
|
206
|
-
'value' => @taxes.map(&:value).sum + @total_net.value,
|
207
|
-
'confidence' => TextField.array_confidence(@taxes) * @total_net.confidence,
|
208
|
-
}
|
209
|
-
@total_amount = AmountField.new(total_incl, page_id, reconstructed: true)
|
210
|
-
end
|
211
|
-
|
212
|
-
def construct_total_tax_from_taxes(page_id)
|
213
|
-
return if @taxes.empty?
|
214
|
-
|
215
|
-
total_tax = {
|
216
|
-
'value' => @taxes.map(&:value).sum,
|
217
|
-
'confidence' => TextField.array_confidence(@taxes),
|
218
|
-
}
|
219
|
-
return unless total_tax['value'].positive?
|
220
|
-
|
221
|
-
@total_tax = AmountField.new(total_tax, page_id, reconstructed: true)
|
222
|
-
end
|
223
|
-
|
224
|
-
def construct_total_tax_from_totals(page_id)
|
225
|
-
return if !@total_tax.value.nil? || @total_amount.value.nil? || @total_net.value.nil?
|
226
|
-
|
227
|
-
total_tax = {
|
228
|
-
'value' => @total_amount.value - @total_net.value,
|
229
|
-
'confidence' => TextField.array_confidence(@taxes),
|
230
|
-
}
|
231
|
-
return unless total_tax['value'] >= 0
|
232
|
-
|
233
|
-
@total_tax = AmountField.new(total_tax, page_id, reconstructed: true)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
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 FinancialDocumentV1LineItem
|
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,40 +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
|
-
module FR
|
9
|
-
# Bank Account Details v1 prediction results.
|
10
|
-
class BankAccountDetailsV1 < Prediction
|
11
|
-
# The International Bank Account Number (IBAN).
|
12
|
-
# @return [Mindee::TextField]
|
13
|
-
attr_reader :iban
|
14
|
-
# The name of the account holder as seen on the document.
|
15
|
-
# @return [Mindee::TextField]
|
16
|
-
attr_reader :account_holder_name
|
17
|
-
# The bank's SWIFT Business Identifier Code (BIC).
|
18
|
-
# @return [Mindee::TextField]
|
19
|
-
attr_reader :swift
|
20
|
-
|
21
|
-
# @param prediction [Hash]
|
22
|
-
# @param page_id [Integer, nil]
|
23
|
-
def initialize(prediction, page_id)
|
24
|
-
super
|
25
|
-
@iban = TextField.new(prediction['iban'], page_id)
|
26
|
-
@account_holder_name = TextField.new(prediction['account_holder_name'], page_id)
|
27
|
-
@swift = TextField.new(prediction['swift'], page_id)
|
28
|
-
end
|
29
|
-
|
30
|
-
def to_s
|
31
|
-
out_str = String.new
|
32
|
-
out_str << "\n:IBAN: #{@iban}".rstrip
|
33
|
-
out_str << "\n:Account Holder's Name: #{@account_holder_name}".rstrip
|
34
|
-
out_str << "\n:SWIFT Code: #{@swift}".rstrip
|
35
|
-
out_str[1..].to_s
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,49 +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
|
-
module FR
|
9
|
-
# Carte Vitale v1 prediction results.
|
10
|
-
class CarteVitaleV1 < Prediction
|
11
|
-
# The given name(s) of the card holder.
|
12
|
-
# @return [Array<Mindee::TextField>]
|
13
|
-
attr_reader :given_names
|
14
|
-
# The surname of the card holder.
|
15
|
-
# @return [Mindee::TextField]
|
16
|
-
attr_reader :surname
|
17
|
-
# The Social Security Number (Numéro de Sécurité Sociale) of the card holder
|
18
|
-
# @return [Mindee::TextField]
|
19
|
-
attr_reader :social_security
|
20
|
-
# The date the card was issued.
|
21
|
-
# @return [Mindee::DateField]
|
22
|
-
attr_reader :issuance_date
|
23
|
-
|
24
|
-
# @param prediction [Hash]
|
25
|
-
# @param page_id [Integer, nil]
|
26
|
-
def initialize(prediction, page_id)
|
27
|
-
super
|
28
|
-
@given_names = []
|
29
|
-
prediction['given_names'].each do |item|
|
30
|
-
@given_names.push(TextField.new(item, page_id))
|
31
|
-
end
|
32
|
-
@surname = TextField.new(prediction['surname'], page_id)
|
33
|
-
@social_security = TextField.new(prediction['social_security'], page_id)
|
34
|
-
@issuance_date = DateField.new(prediction['issuance_date'], page_id)
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_s
|
38
|
-
given_names = @given_names.join("\n #{' ' * 15}")
|
39
|
-
out_str = String.new
|
40
|
-
out_str << "\n:Given Name(s): #{given_names}".rstrip
|
41
|
-
out_str << "\n:Surname: #{@surname}".rstrip
|
42
|
-
out_str << "\n:Social Security Number: #{@social_security}".rstrip
|
43
|
-
out_str << "\n:Issuance Date: #{@issuance_date}".rstrip
|
44
|
-
out_str[1..].to_s
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|