mindee 2.2.0 → 3.0.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.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +2 -0
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +36 -0
  6. data/README.md +29 -16
  7. data/bin/mindee.rb +23 -26
  8. data/docs/code_samples/bank_account_details_v1.txt +10 -5
  9. data/docs/code_samples/bank_account_details_v2.txt +19 -0
  10. data/docs/code_samples/bank_check_v1.txt +10 -5
  11. data/docs/code_samples/carte_vitale_v1.txt +10 -5
  12. data/docs/code_samples/custom_v1.txt +19 -10
  13. data/docs/code_samples/default.txt +10 -2
  14. data/docs/code_samples/expense_receipts_v4.txt +10 -5
  15. data/docs/code_samples/expense_receipts_v5.txt +11 -6
  16. data/docs/code_samples/financial_document_v1.txt +10 -5
  17. data/docs/code_samples/idcard_fr_v1.txt +10 -5
  18. data/docs/code_samples/invoice_splitter_v1_async.txt +66 -0
  19. data/docs/code_samples/invoices_v4.txt +10 -5
  20. data/docs/code_samples/license_plates_v1.txt +10 -5
  21. data/docs/code_samples/passport_v1.txt +10 -5
  22. data/docs/code_samples/proof_of_address_v1.txt +10 -5
  23. data/docs/ruby-api-builder.md +30 -31
  24. data/docs/ruby-getting-started.md +64 -23
  25. data/docs/ruby-invoice-ocr.md +70 -59
  26. data/docs/ruby-passport-ocr.md +49 -40
  27. data/docs/ruby-receipt-ocr.md +45 -32
  28. data/lib/mindee/client.rb +150 -148
  29. data/lib/mindee/geometry/min_max.rb +23 -0
  30. data/lib/mindee/geometry/point.rb +35 -0
  31. data/lib/mindee/geometry/polygon.rb +23 -0
  32. data/lib/mindee/geometry/quadrilateral.rb +45 -0
  33. data/lib/mindee/geometry/utils.rb +81 -0
  34. data/lib/mindee/geometry.rb +5 -116
  35. data/lib/mindee/http/endpoint.rb +123 -16
  36. data/lib/mindee/http.rb +3 -0
  37. data/lib/mindee/input/sources.rb +87 -73
  38. data/lib/mindee/parsing/common/api_response.rb +109 -0
  39. data/lib/mindee/parsing/common/document.rb +48 -0
  40. data/lib/mindee/parsing/common/error.rb +24 -0
  41. data/lib/mindee/parsing/common/inference.rb +43 -0
  42. data/lib/mindee/parsing/common/ocr/mvision_v1.rb +34 -0
  43. data/lib/mindee/parsing/common/ocr/ocr.rb +169 -0
  44. data/lib/mindee/parsing/common/ocr.rb +3 -0
  45. data/lib/mindee/parsing/common/orientation.rb +26 -0
  46. data/lib/mindee/parsing/common/page.rb +40 -0
  47. data/lib/mindee/parsing/common/prediction.rb +15 -0
  48. data/lib/mindee/parsing/common/product.rb +19 -0
  49. data/lib/mindee/parsing/common.rb +10 -0
  50. data/lib/mindee/parsing/custom/classification_field.rb +28 -0
  51. data/lib/mindee/parsing/custom/list_field.rb +76 -0
  52. data/lib/mindee/parsing/custom.rb +4 -0
  53. data/lib/mindee/parsing/standard/amount_field.rb +26 -0
  54. data/lib/mindee/parsing/standard/base_field.rb +104 -0
  55. data/lib/mindee/parsing/standard/classification_field.rb +16 -0
  56. data/lib/mindee/parsing/standard/company_registration_field.rb +21 -0
  57. data/lib/mindee/parsing/standard/date_field.rb +34 -0
  58. data/lib/mindee/parsing/standard/locale_field.rb +50 -0
  59. data/lib/mindee/parsing/standard/payment_details_field.rb +42 -0
  60. data/lib/mindee/parsing/standard/position_field.rb +44 -0
  61. data/lib/mindee/parsing/standard/tax_field.rb +108 -0
  62. data/lib/mindee/parsing/standard/text_field.rb +16 -0
  63. data/lib/mindee/parsing/standard.rb +12 -0
  64. data/lib/mindee/parsing.rb +3 -2
  65. data/lib/mindee/{input → pdf}/pdf_processing.rb +4 -32
  66. data/lib/mindee/pdf/pdf_tools.rb +34 -0
  67. data/lib/mindee/pdf.rb +3 -0
  68. data/lib/mindee/product/.rubocop.yml +5 -0
  69. data/lib/mindee/product/custom/custom_v1.rb +35 -0
  70. data/lib/mindee/product/custom/custom_v1_document.rb +60 -0
  71. data/lib/mindee/product/custom/custom_v1_page.rb +32 -0
  72. data/lib/mindee/product/eu/license_plate/license_plate_v1.rb +38 -0
  73. data/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb +37 -0
  74. data/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb +34 -0
  75. data/lib/mindee/product/financial_document/financial_document_v1.rb +36 -0
  76. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +188 -0
  77. data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +90 -0
  78. data/lib/mindee/product/financial_document/financial_document_v1_page.rb +32 -0
  79. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +38 -0
  80. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb +43 -0
  81. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb +34 -0
  82. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +38 -0
  83. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +71 -0
  84. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb +58 -0
  85. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb +34 -0
  86. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb +38 -0
  87. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_document.rb +52 -0
  88. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_page.rb +34 -0
  89. data/lib/mindee/product/fr/id_card/id_card_v1.rb +38 -0
  90. data/lib/mindee/product/fr/id_card/id_card_v1_document.rb +82 -0
  91. data/lib/mindee/product/fr/id_card/id_card_v1_page.rb +48 -0
  92. data/lib/mindee/product/invoice/invoice_v4.rb +37 -0
  93. data/lib/mindee/product/invoice/invoice_v4_document.rb +212 -0
  94. data/lib/mindee/product/invoice/invoice_v4_line_item.rb +66 -0
  95. data/lib/mindee/product/invoice/invoice_v4_page.rb +32 -0
  96. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +36 -0
  97. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +65 -0
  98. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb +32 -0
  99. data/lib/mindee/product/passport/passport_v1.rb +36 -0
  100. data/lib/mindee/{parsing/prediction/fr/id_card/id_card_v1.rb → product/passport/passport_v1_document.rb} +45 -45
  101. data/lib/mindee/product/passport/passport_v1_page.rb +32 -0
  102. data/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +36 -0
  103. data/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb +83 -0
  104. data/lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb +32 -0
  105. data/lib/mindee/product/receipt/receipt_v4.rb +36 -0
  106. data/lib/mindee/product/receipt/receipt_v4_document.rb +86 -0
  107. data/lib/mindee/product/receipt/receipt_v4_page.rb +32 -0
  108. data/lib/mindee/product/receipt/receipt_v5.rb +36 -0
  109. data/lib/mindee/product/receipt/receipt_v5_document.rb +138 -0
  110. data/lib/mindee/product/receipt/receipt_v5_line_item.rb +69 -0
  111. data/lib/mindee/product/receipt/receipt_v5_page.rb +32 -0
  112. data/lib/mindee/product/us/bank_check/bank_check_v1.rb +38 -0
  113. data/lib/mindee/product/us/bank_check/bank_check_v1_document.rb +73 -0
  114. data/lib/mindee/product/us/bank_check/bank_check_v1_page.rb +34 -0
  115. data/lib/mindee/product.rb +16 -0
  116. data/lib/mindee/version.rb +2 -1
  117. data/lib/mindee.rb +3 -1
  118. metadata +87 -38
  119. data/docs/code_samples/shipping_containers_v1.txt +0 -14
  120. data/lib/mindee/document_config.rb +0 -60
  121. data/lib/mindee/parsing/document.rb +0 -31
  122. data/lib/mindee/parsing/error.rb +0 -22
  123. data/lib/mindee/parsing/inference.rb +0 -53
  124. data/lib/mindee/parsing/page.rb +0 -46
  125. data/lib/mindee/parsing/prediction/base.rb +0 -30
  126. data/lib/mindee/parsing/prediction/common_fields/amount.rb +0 -21
  127. data/lib/mindee/parsing/prediction/common_fields/base.rb +0 -72
  128. data/lib/mindee/parsing/prediction/common_fields/company_registration.rb +0 -17
  129. data/lib/mindee/parsing/prediction/common_fields/date.rb +0 -30
  130. data/lib/mindee/parsing/prediction/common_fields/locale.rb +0 -45
  131. data/lib/mindee/parsing/prediction/common_fields/payment_details.rb +0 -33
  132. data/lib/mindee/parsing/prediction/common_fields/position.rb +0 -39
  133. data/lib/mindee/parsing/prediction/common_fields/tax.rb +0 -40
  134. data/lib/mindee/parsing/prediction/common_fields/text.rb +0 -12
  135. data/lib/mindee/parsing/prediction/common_fields.rb +0 -11
  136. data/lib/mindee/parsing/prediction/custom/custom_v1.rb +0 -58
  137. data/lib/mindee/parsing/prediction/custom/fields.rb +0 -91
  138. data/lib/mindee/parsing/prediction/eu/license_plate/license_plate_v1.rb +0 -34
  139. data/lib/mindee/parsing/prediction/financial_document/financial_document_v1.rb +0 -237
  140. data/lib/mindee/parsing/prediction/financial_document/financial_document_v1_line_item.rb +0 -58
  141. data/lib/mindee/parsing/prediction/fr/bank_account_details/bank_account_details_v1.rb +0 -40
  142. data/lib/mindee/parsing/prediction/fr/carte_vitale/carte_vitale_v1.rb +0 -49
  143. data/lib/mindee/parsing/prediction/invoice/invoice_v4.rb +0 -212
  144. data/lib/mindee/parsing/prediction/invoice/invoice_v4_line_item.rb +0 -58
  145. data/lib/mindee/parsing/prediction/passport/passport_v1.rb +0 -121
  146. data/lib/mindee/parsing/prediction/proof_of_address/proof_of_address_v1.rb +0 -80
  147. data/lib/mindee/parsing/prediction/receipt/receipt_v4.rb +0 -87
  148. data/lib/mindee/parsing/prediction/receipt/receipt_v5.rb +0 -136
  149. data/lib/mindee/parsing/prediction/receipt/receipt_v5_line_item.rb +0 -37
  150. data/lib/mindee/parsing/prediction/shipping_container/shipping_container_v1.rb +0 -38
  151. data/lib/mindee/parsing/prediction/us/bank_check/bank_check_v1.rb +0 -70
  152. data/lib/mindee/parsing/prediction.rb +0 -15
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module InvoiceSplitter
8
+ # Page Group for Invoice Splitter class
9
+ class PageGroup
10
+ # @return[Array<Integer>]
11
+ attr_reader :page_indexes
12
+
13
+ # @return[Float, nil]
14
+ attr_reader :confidence
15
+
16
+ # @param prediction[Hash]
17
+ def initialize(prediction)
18
+ @page_indexes = prediction['page_indexes']
19
+ @confidence = prediction['confidence'].nil? ? 0.0 : Float(prediction['confidence'])
20
+ end
21
+
22
+ # @return [String]
23
+ def to_s
24
+ out_str = String.new
25
+ out_str << ":Page indexes: #{@page_indexes.join(', ')}"
26
+ out_str
27
+ end
28
+ end
29
+
30
+ # Invoice Splitter V1 document prediction.
31
+ class InvoiceSplitterV1Document < Mindee::Parsing::Common::Prediction
32
+ # @return[Array<Mindee::Product::PageGroup>]
33
+ attr_reader :invoice_page_groups
34
+
35
+ # @param prediction [Hash]
36
+ # @param _page_id [Integer, nil]
37
+ def initialize(prediction, _page_id)
38
+ super()
39
+ construct_invoice_page_groups_from_prediction(prediction)
40
+ end
41
+
42
+ def construct_invoice_page_groups_from_prediction(prediction)
43
+ @invoice_page_groups = []
44
+ return unless prediction.key?('invoice_page_groups') && prediction['invoice_page_groups'].any?
45
+
46
+ prediction['invoice_page_groups'].each do |page_group_prediction|
47
+ @invoice_page_groups.append(PageGroup.new(page_group_prediction))
48
+ end
49
+ end
50
+
51
+ # @return [String]
52
+ def to_s
53
+ out_str = String.new
54
+ out_str << "\n:Invoice Page Groups:"
55
+ if !@invoice_page_groups.nil? && @invoice_page_groups.any?
56
+ @invoice_page_groups.map do |page|
57
+ out_str << "\n #{page}"
58
+ end
59
+ end
60
+ out_str[1..].to_s
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'invoice_splitter_v1_document'
5
+
6
+ module Mindee
7
+ module Product
8
+ module InvoiceSplitter
9
+ # Invoice Splitter V1 page.
10
+ class InvoiceSplitterV1Page < Mindee::Parsing::Common::Page
11
+ # @param prediction [Hash]
12
+ def initialize(prediction)
13
+ super(prediction)
14
+ @prediction = InvoiceSplitterV1PagePrediction.new(
15
+ prediction['prediction'],
16
+ prediction['id']
17
+ )
18
+ end
19
+ end
20
+
21
+ # Invoice Splitter V1 page prediction.
22
+ class InvoiceSplitterV1PagePrediction < InvoiceSplitterV1Document
23
+ # @return [String]
24
+ def to_s
25
+ out_str = String.new
26
+ out_str << "\n#{super}"
27
+ out_str
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'passport_v1_document'
5
+ require_relative 'passport_v1_page'
6
+
7
+ module Mindee
8
+ module Product
9
+ module Passport
10
+ # International Passport V1 prediction inference.
11
+ class PassportV1 < Mindee::Parsing::Common::Inference
12
+ @endpoint_name = 'passport'
13
+ @endpoint_version = '1'
14
+
15
+ # @param prediction [Hash]
16
+ def initialize(prediction)
17
+ super
18
+ @prediction = PassportV1Document.new(prediction['prediction'], nil)
19
+ @pages = []
20
+ prediction['pages'].each do |page|
21
+ @pages.push(PassportV1Page.new(page))
22
+ end
23
+ end
24
+
25
+ class << self
26
+ # Name of the endpoint for this product.
27
+ # @return [String]
28
+ attr_reader :endpoint_name
29
+ # Version for this product.
30
+ # @return [String]
31
+ attr_reader :endpoint_version
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,80 +1,80 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../common_fields'
4
- require_relative '../../base'
3
+ require_relative '../../parsing'
5
4
 
6
5
  module Mindee
7
- module Prediction
8
- module FR
9
- # Carte Nationale d'Identité v1 prediction results.
10
- class IdCardV1 < Prediction
11
- # The side of the document which is visible.
12
- # @return [Mindee::TextField]
13
- attr_reader :document_side
14
- # The identification card number.
15
- # @return [Mindee::TextField]
16
- attr_reader :id_number
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.
21
- # @return [Mindee::TextField]
22
- attr_reader :surname
23
- # The date of birth of the card holder.
24
- # @return [Mindee::DateField]
6
+ module Product
7
+ module Passport
8
+ # International Passport V1 document prediction.
9
+ class PassportV1Document < Mindee::Parsing::Common::Prediction
10
+ include Mindee::Parsing::Standard
11
+ # The date of birth of the passport holder.
12
+ # @return [Mindee::Parsing::Standard::DateField]
25
13
  attr_reader :birth_date
26
- # The place of birth of the card holder.
27
- # @return [Mindee::TextField]
14
+ # The place of birth of the passport holder.
15
+ # @return [Mindee::Parsing::Standard::TextField]
28
16
  attr_reader :birth_place
29
- # The expiry date of the identification card.
30
- # @return [Mindee::DateField]
17
+ # The country's 3 letter code (ISO 3166-1 alpha-3).
18
+ # @return [Mindee::Parsing::Standard::TextField]
19
+ attr_reader :country
20
+ # The expiry date of the passport.
21
+ # @return [Mindee::Parsing::Standard::DateField]
31
22
  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
- # @return [Mindee::TextField]
23
+ # The gender of the passport holder.
24
+ # @return [Mindee::Parsing::Standard::TextField]
37
25
  attr_reader :gender
26
+ # The given name(s) of the passport holder.
27
+ # @return [Array<Mindee::Parsing::Standard::TextField>]
28
+ attr_reader :given_names
29
+ # The passport's identification number.
30
+ # @return [Mindee::Parsing::Standard::TextField]
31
+ attr_reader :id_number
32
+ # The date the passport was issued.
33
+ # @return [Mindee::Parsing::Standard::DateField]
34
+ attr_reader :issuance_date
38
35
  # Machine Readable Zone, first line
39
- # @return [Mindee::TextField]
36
+ # @return [Mindee::Parsing::Standard::TextField]
40
37
  attr_reader :mrz1
41
38
  # Machine Readable Zone, second line
42
- # @return [Mindee::TextField]
39
+ # @return [Mindee::Parsing::Standard::TextField]
43
40
  attr_reader :mrz2
41
+ # The surname of the passport holder.
42
+ # @return [Mindee::Parsing::Standard::TextField]
43
+ attr_reader :surname
44
44
 
45
45
  # @param prediction [Hash]
46
46
  # @param page_id [Integer, nil]
47
47
  def initialize(prediction, page_id)
48
- super
49
- @document_side = TextField.new(prediction['document_side'], page_id) if page_id
50
- @authority = TextField.new(prediction['authority'], page_id)
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)
48
+ super()
57
49
  @birth_date = DateField.new(prediction['birth_date'], page_id)
58
50
  @birth_place = TextField.new(prediction['birth_place'], page_id)
51
+ @country = TextField.new(prediction['country'], page_id)
59
52
  @expiry_date = DateField.new(prediction['expiry_date'], page_id)
60
- @authority = TextField.new(prediction['authority'], page_id)
61
53
  @gender = TextField.new(prediction['gender'], page_id)
54
+ @given_names = []
55
+ prediction['given_names'].each do |item|
56
+ @given_names.push(TextField.new(item, page_id))
57
+ end
58
+ @id_number = TextField.new(prediction['id_number'], page_id)
59
+ @issuance_date = DateField.new(prediction['issuance_date'], page_id)
62
60
  @mrz1 = TextField.new(prediction['mrz1'], page_id)
63
61
  @mrz2 = TextField.new(prediction['mrz2'], page_id)
62
+ @surname = TextField.new(prediction['surname'], page_id)
64
63
  end
65
64
 
65
+ # @return [String]
66
66
  def to_s
67
67
  given_names = @given_names.join("\n #{' ' * 15}")
68
68
  out_str = String.new
69
- out_str << "\n:Document Side: #{@document_side}".rstrip if @document_side
70
- out_str << "\n:Identity Number: #{@id_number}".rstrip
69
+ out_str << "\n:Country Code: #{@country}".rstrip
70
+ out_str << "\n:ID Number: #{@id_number}".rstrip
71
71
  out_str << "\n:Given Name(s): #{given_names}".rstrip
72
72
  out_str << "\n:Surname: #{@surname}".rstrip
73
73
  out_str << "\n:Date of Birth: #{@birth_date}".rstrip
74
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
77
75
  out_str << "\n:Gender: #{@gender}".rstrip
76
+ out_str << "\n:Date of Issue: #{@issuance_date}".rstrip
77
+ out_str << "\n:Expiry Date: #{@expiry_date}".rstrip
78
78
  out_str << "\n:MRZ Line 1: #{@mrz1}".rstrip
79
79
  out_str << "\n:MRZ Line 2: #{@mrz2}".rstrip
80
80
  out_str[1..].to_s
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'passport_v1_document'
5
+
6
+ module Mindee
7
+ module Product
8
+ module Passport
9
+ # International Passport V1 page.
10
+ class PassportV1Page < Mindee::Parsing::Common::Page
11
+ # @param prediction [Hash]
12
+ def initialize(prediction)
13
+ super(prediction)
14
+ @prediction = PassportV1PagePrediction.new(
15
+ prediction['prediction'],
16
+ prediction['id']
17
+ )
18
+ end
19
+ end
20
+
21
+ # International Passport V1 page prediction.
22
+ class PassportV1PagePrediction < PassportV1Document
23
+ # @return [String]
24
+ def to_s
25
+ out_str = String.new
26
+ out_str << "\n#{super}"
27
+ out_str
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'proof_of_address_v1_document'
5
+ require_relative 'proof_of_address_v1_page'
6
+
7
+ module Mindee
8
+ module Product
9
+ module ProofOfAddress
10
+ # Proof of Address V1 prediction inference.
11
+ class ProofOfAddressV1 < Mindee::Parsing::Common::Inference
12
+ @endpoint_name = 'proof_of_address'
13
+ @endpoint_version = '1'
14
+
15
+ # @param prediction [Hash]
16
+ def initialize(prediction)
17
+ super
18
+ @prediction = ProofOfAddressV1Document.new(prediction['prediction'], nil)
19
+ @pages = []
20
+ prediction['pages'].each do |page|
21
+ @pages.push(ProofOfAddressV1Page.new(page))
22
+ end
23
+ end
24
+
25
+ class << self
26
+ # Name of the endpoint for this product.
27
+ # @return [String]
28
+ attr_reader :endpoint_name
29
+ # Version for this product.
30
+ # @return [String]
31
+ attr_reader :endpoint_version
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module ProofOfAddress
8
+ # Proof of Address V1 document prediction.
9
+ class ProofOfAddressV1Document < Mindee::Parsing::Common::Prediction
10
+ include Mindee::Parsing::Standard
11
+ # The date the document was issued.
12
+ # @return [Mindee::Parsing::Standard::DateField]
13
+ attr_reader :date
14
+ # List of dates found on the document.
15
+ # @return [Array<Mindee::Parsing::Standard::DateField>]
16
+ attr_reader :dates
17
+ # The address of the document's issuer.
18
+ # @return [Mindee::Parsing::Standard::TextField]
19
+ attr_reader :issuer_address
20
+ # List of company registrations found for the issuer.
21
+ # @return [Array<Mindee::Parsing::Standard::CompanyRegistration>]
22
+ attr_reader :issuer_company_registration
23
+ # The name of the person or company issuing the document.
24
+ # @return [Mindee::Parsing::Standard::TextField]
25
+ attr_reader :issuer_name
26
+ # The locale detected on the document.
27
+ # @return [Mindee::Parsing::Standard::Locale]
28
+ attr_reader :locale
29
+ # The address of the recipient.
30
+ # @return [Mindee::Parsing::Standard::TextField]
31
+ attr_reader :recipient_address
32
+ # List of company registrations found for the recipient.
33
+ # @return [Array<Mindee::Parsing::Standard::CompanyRegistration>]
34
+ attr_reader :recipient_company_registration
35
+ # The name of the person or company receiving the document.
36
+ # @return [Mindee::Parsing::Standard::TextField]
37
+ attr_reader :recipient_name
38
+
39
+ # @param prediction [Hash]
40
+ # @param page_id [Integer, nil]
41
+ def initialize(prediction, page_id)
42
+ super()
43
+ @date = DateField.new(prediction['date'], page_id)
44
+ @dates = []
45
+ prediction['dates'].each do |item|
46
+ @dates.push(DateField.new(item, page_id))
47
+ end
48
+ @issuer_address = TextField.new(prediction['issuer_address'], page_id)
49
+ @issuer_company_registration = []
50
+ prediction['issuer_company_registration'].each do |item|
51
+ @issuer_company_registration.push(CompanyRegistration.new(item, page_id))
52
+ end
53
+ @issuer_name = TextField.new(prediction['issuer_name'], page_id)
54
+ @locale = Locale.new(prediction['locale'], page_id)
55
+ @recipient_address = TextField.new(prediction['recipient_address'], page_id)
56
+ @recipient_company_registration = []
57
+ prediction['recipient_company_registration'].each do |item|
58
+ @recipient_company_registration.push(CompanyRegistration.new(item, page_id))
59
+ end
60
+ @recipient_name = TextField.new(prediction['recipient_name'], page_id)
61
+ end
62
+
63
+ # @return [String]
64
+ def to_s
65
+ issuer_company_registration = @issuer_company_registration.join("\n #{' ' * 30}")
66
+ recipient_company_registration = @recipient_company_registration.join("\n #{' ' * 33}")
67
+ dates = @dates.join("\n #{' ' * 7}")
68
+ out_str = String.new
69
+ out_str << "\n:Locale: #{@locale}".rstrip
70
+ out_str << "\n:Issuer Name: #{@issuer_name}".rstrip
71
+ out_str << "\n:Issuer Company Registrations: #{issuer_company_registration}".rstrip
72
+ out_str << "\n:Issuer Address: #{@issuer_address}".rstrip
73
+ out_str << "\n:Recipient Name: #{@recipient_name}".rstrip
74
+ out_str << "\n:Recipient Company Registrations: #{recipient_company_registration}".rstrip
75
+ out_str << "\n:Recipient Address: #{@recipient_address}".rstrip
76
+ out_str << "\n:Dates: #{dates}".rstrip
77
+ out_str << "\n:Date of Issue: #{@date}".rstrip
78
+ out_str[1..].to_s
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'proof_of_address_v1_document'
5
+
6
+ module Mindee
7
+ module Product
8
+ module ProofOfAddress
9
+ # Proof of Address V1 page.
10
+ class ProofOfAddressV1Page < Mindee::Parsing::Common::Page
11
+ # @param prediction [Hash]
12
+ def initialize(prediction)
13
+ super(prediction)
14
+ @prediction = ProofOfAddressV1PagePrediction.new(
15
+ prediction['prediction'],
16
+ prediction['id']
17
+ )
18
+ end
19
+ end
20
+
21
+ # Proof of Address V1 page prediction.
22
+ class ProofOfAddressV1PagePrediction < ProofOfAddressV1Document
23
+ # @return [String]
24
+ def to_s
25
+ out_str = String.new
26
+ out_str << "\n#{super}"
27
+ out_str
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'receipt_v4_document'
5
+ require_relative 'receipt_v4_page'
6
+
7
+ module Mindee
8
+ module Product
9
+ module Receipt
10
+ # Expense Receipt V4 prediction inference.
11
+ class ReceiptV4 < Mindee::Parsing::Common::Inference
12
+ @endpoint_name = 'expense_receipts'
13
+ @endpoint_version = '4'
14
+
15
+ # @param prediction [Hash]
16
+ def initialize(prediction)
17
+ super
18
+ @prediction = ReceiptV4Document.new(prediction['prediction'], nil)
19
+ @pages = []
20
+ prediction['pages'].each do |page|
21
+ @pages.push(ReceiptV4Page.new(page))
22
+ end
23
+ end
24
+
25
+ class << self
26
+ # Name of the endpoint for this product.
27
+ # @return [String]
28
+ attr_reader :endpoint_name
29
+ # Version for this product.
30
+ # @return [String]
31
+ attr_reader :endpoint_version
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+
5
+ module Mindee
6
+ module Product
7
+ module Receipt
8
+ # Expense Receipt V4 document prediction.
9
+ class ReceiptV4Document < Mindee::Parsing::Common::Prediction
10
+ include Mindee::Parsing::Standard
11
+ # Where the purchase was made, the language, and the currency.
12
+ # @return [Mindee::Parsing::Standard::Locale]
13
+ attr_reader :locale
14
+ # Total including taxes
15
+ # @return [Mindee::Parsing::Standard::AmountField]
16
+ attr_reader :total_amount
17
+ # Total amount of the purchase excluding taxes.
18
+ # @return [Mindee::Parsing::Standard::AmountField]
19
+ attr_reader :total_net
20
+ # Total tax amount of the purchase.
21
+ # @return [Mindee::Parsing::Standard::AmountField]
22
+ attr_reader :total_tax
23
+ # The purchase date.
24
+ # @return [Mindee::Parsing::Standard::DateField]
25
+ attr_reader :date
26
+ # The name of the supplier or merchant, as seen on the receipt.
27
+ # @return [Mindee::Parsing::Standard::TextField]
28
+ attr_reader :supplier
29
+ # List of taxes detected on the receipt.
30
+ # @return [Mindee::Parsing::Standard::Taxes]
31
+ attr_reader :taxes
32
+ # Time as seen on the receipt in HH:MM format.
33
+ # @return [Mindee::Parsing::Standard::TextField]
34
+ attr_reader :time
35
+ # The receipt category among predefined classes.
36
+ # @return [Mindee::Parsing::Standard::ClassificationField]
37
+ attr_reader :category
38
+ # The receipt sub-category among predefined classes.
39
+ # @return [Mindee::Parsing::Standard::ClassificationField]
40
+ attr_reader :subcategory
41
+ # Whether the document is an expense receipt or a credit card receipt.
42
+ # @return [Mindee::Parsing::Standard::ClassificationField]
43
+ attr_reader :document_type
44
+ # Total amount of tip and gratuity. Both typed and handwritten characters are supported.
45
+ # @return [Mindee::Parsing::Standard::AmountField]
46
+ attr_reader :tip
47
+
48
+ # @param prediction [Hash]
49
+ # @param page_id [Integer, nil]
50
+ def initialize(prediction, page_id)
51
+ super()
52
+ @locale = Locale.new(prediction['locale'])
53
+ @total_amount = AmountField.new(prediction['total_amount'], page_id)
54
+ @total_net = AmountField.new(prediction['total_net'], page_id)
55
+ @total_tax = AmountField.new(prediction['total_tax'], page_id)
56
+ @tip = AmountField.new(prediction['tip'], page_id)
57
+ @date = DateField.new(prediction['date'], page_id)
58
+ @category = ClassificationField.new(prediction['category'], page_id)
59
+ @subcategory = ClassificationField.new(prediction['subcategory'], page_id)
60
+ @document_type = ClassificationField.new(prediction['document_type'], page_id)
61
+ @supplier = TextField.new(prediction['supplier'], page_id)
62
+ @time = TextField.new(prediction['time'], page_id)
63
+ @taxes = Taxes.new(prediction['taxes'], page_id)
64
+ end
65
+
66
+ # @return [String]
67
+ def to_s
68
+ out_str = String.new
69
+ out_str << "\n:Locale: #{@locale}".rstrip
70
+ out_str << "\n:Date: #{@date}".rstrip
71
+ out_str << "\n:Category: #{@category}".rstrip
72
+ out_str << "\n:Subcategory: #{@subcategory}".rstrip
73
+ out_str << "\n:Document type: #{@document_type}".rstrip
74
+ out_str << "\n:Time: #{@time}".rstrip
75
+ out_str << "\n:Supplier name: #{@supplier}".rstrip
76
+ out_str << "\n:Taxes:#{@taxes}".rstrip
77
+ out_str << "\n:Total net: #{@total_net}".rstrip
78
+ out_str << "\n:Total tax: #{@total_tax}".rstrip
79
+ out_str << "\n:Tip: #{@tip}".rstrip
80
+ out_str << "\n:Total amount: #{@total_amount}".rstrip
81
+ out_str[1..].to_s
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'receipt_v4_document'
5
+
6
+ module Mindee
7
+ module Product
8
+ module Receipt
9
+ # Expense Receipt V4 page.
10
+ class ReceiptV4Page < Mindee::Parsing::Common::Page
11
+ # @param prediction [Hash]
12
+ def initialize(prediction)
13
+ super(prediction)
14
+ @prediction = ReceiptV4PagePrediction.new(
15
+ prediction['prediction'],
16
+ prediction['id']
17
+ )
18
+ end
19
+ end
20
+
21
+ # Expense Receipt V4 page prediction.
22
+ class ReceiptV4PagePrediction < ReceiptV4Document
23
+ # @return [String]
24
+ def to_s
25
+ out_str = String.new
26
+ out_str << "\n#{super}"
27
+ out_str
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../parsing'
4
+ require_relative 'receipt_v5_document'
5
+ require_relative 'receipt_v5_page'
6
+
7
+ module Mindee
8
+ module Product
9
+ module Receipt
10
+ # Expense Receipt V5 prediction inference.
11
+ class ReceiptV5 < Mindee::Parsing::Common::Inference
12
+ @endpoint_name = 'expense_receipts'
13
+ @endpoint_version = '5'
14
+
15
+ # @param prediction [Hash]
16
+ def initialize(prediction)
17
+ super
18
+ @prediction = ReceiptV5Document.new(prediction['prediction'], nil)
19
+ @pages = []
20
+ prediction['pages'].each do |page|
21
+ @pages.push(ReceiptV5Page.new(page))
22
+ end
23
+ end
24
+
25
+ class << self
26
+ # Name of the endpoint for this product.
27
+ # @return [String]
28
+ attr_reader :endpoint_name
29
+ # Version for this product.
30
+ # @return [String]
31
+ attr_reader :endpoint_version
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end