mindee 3.1.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +1 -0
  4. data/CHANGELOG.md +26 -0
  5. data/README.md +57 -7
  6. data/bin/mindee.rb +160 -83
  7. data/docs/bank_account_details_v2.md +137 -0
  8. data/docs/bank_check_v1.md +179 -0
  9. data/docs/barcode_reader_v1.md +104 -0
  10. data/docs/carte_grise_v1.md +454 -0
  11. data/docs/carte_vitale_v1.md +123 -0
  12. data/docs/code_samples/barcode_reader_v1.txt +19 -0
  13. data/docs/code_samples/carte_grise_v1.txt +19 -0
  14. data/docs/code_samples/cropper_v1.txt +16 -0
  15. data/docs/code_samples/idcard_fr_v2.txt +19 -0
  16. data/docs/code_samples/invoice_splitter_v1_async.txt +6 -54
  17. data/docs/code_samples/multi_receipts_detector_v1.txt +19 -0
  18. data/docs/code_samples/us_w9_v1.txt +16 -0
  19. data/docs/cropper_v1.md +97 -0
  20. data/docs/custom_v1.md +109 -0
  21. data/docs/expense_receipts_v5.md +306 -0
  22. data/docs/financial_document_v1.md +384 -0
  23. data/docs/{ruby-getting-started.md → getting_started.md} +22 -6
  24. data/docs/idcard_fr_v2.md +253 -0
  25. data/docs/invoice_splitter_v1.md +85 -0
  26. data/docs/invoices_v4.md +338 -0
  27. data/docs/license_plates_v1.md +91 -0
  28. data/docs/multi_receipts_detector_v1.md +105 -0
  29. data/docs/passport_v1.md +186 -0
  30. data/docs/proof_of_address_v1.md +207 -0
  31. data/docs/us_driver_license_v1.md +268 -0
  32. data/docs/us_w9_v1.md +207 -0
  33. data/lib/mindee/client.rb +95 -16
  34. data/lib/mindee/geometry/quadrilateral.rb +5 -0
  35. data/lib/mindee/http/.rubocop.yml +8 -0
  36. data/lib/mindee/http/endpoint.rb +19 -7
  37. data/lib/mindee/http/error.rb +104 -0
  38. data/lib/mindee/http.rb +1 -0
  39. data/lib/mindee/input/sources.rb +83 -14
  40. data/lib/mindee/parsing/common/api_response.rb +12 -1
  41. data/lib/mindee/parsing/common/document.rb +4 -1
  42. data/lib/mindee/parsing/common/inference.rb +2 -2
  43. data/lib/mindee/parsing/common/ocr/ocr.rb +1 -0
  44. data/lib/mindee/parsing/common.rb +0 -1
  45. data/lib/mindee/parsing/custom/list_field.rb +7 -5
  46. data/lib/mindee/parsing/standard/base_field.rb +1 -1
  47. data/lib/mindee/parsing/standard/company_registration_field.rb +1 -1
  48. data/lib/mindee/parsing/standard/locale_field.rb +1 -1
  49. data/lib/mindee/parsing/standard/payment_details_field.rb +1 -1
  50. data/lib/mindee/parsing/standard/position_field.rb +10 -3
  51. data/lib/mindee/parsing/standard/{text_field.rb → string_field.rb} +1 -1
  52. data/lib/mindee/parsing/standard.rb +1 -1
  53. data/lib/mindee/pdf/pdf_processing.rb +2 -1
  54. data/lib/mindee/product/barcode_reader/barcode_reader_v1.rb +37 -0
  55. data/lib/mindee/product/barcode_reader/barcode_reader_v1_document.rb +44 -0
  56. data/lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb +32 -0
  57. data/lib/mindee/product/cropper/cropper_v1.rb +37 -0
  58. data/lib/mindee/product/cropper/cropper_v1_document.rb +13 -0
  59. data/lib/mindee/product/cropper/cropper_v1_page.rb +49 -0
  60. data/lib/mindee/product/custom/custom_v1.rb +1 -0
  61. data/lib/mindee/product/eu/license_plate/license_plate_v1.rb +1 -0
  62. data/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb +2 -2
  63. data/lib/mindee/product/financial_document/financial_document_v1.rb +1 -0
  64. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +26 -26
  65. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +1 -0
  66. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb +6 -6
  67. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +1 -0
  68. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb +6 -6
  69. data/lib/mindee/product/fr/carte_grise/carte_grise_v1.rb +39 -0
  70. data/lib/mindee/product/fr/carte_grise/carte_grise_v1_document.rb +235 -0
  71. data/lib/mindee/product/fr/carte_grise/carte_grise_v1_page.rb +34 -0
  72. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb +1 -0
  73. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_document.rb +6 -6
  74. data/lib/mindee/product/fr/id_card/id_card_v1.rb +1 -0
  75. data/lib/mindee/product/fr/id_card/id_card_v1_document.rb +16 -16
  76. data/lib/mindee/product/fr/id_card/id_card_v2.rb +39 -0
  77. data/lib/mindee/product/fr/id_card/id_card_v2_document.rb +107 -0
  78. data/lib/mindee/product/fr/id_card/id_card_v2_page.rb +53 -0
  79. data/lib/mindee/product/invoice/invoice_v4.rb +2 -2
  80. data/lib/mindee/product/invoice/invoice_v4_document.rb +115 -155
  81. data/lib/mindee/product/invoice/invoice_v4_line_item.rb +54 -30
  82. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +1 -0
  83. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +5 -3
  84. data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rb +37 -0
  85. data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rb +35 -0
  86. data/lib/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rb +32 -0
  87. data/lib/mindee/product/passport/passport_v1.rb +1 -0
  88. data/lib/mindee/product/passport/passport_v1_document.rb +16 -16
  89. data/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +1 -0
  90. data/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb +14 -14
  91. data/lib/mindee/product/receipt/receipt_v4_document.rb +6 -6
  92. data/lib/mindee/product/receipt/receipt_v5.rb +1 -0
  93. data/lib/mindee/product/receipt/receipt_v5_document.rb +12 -12
  94. data/lib/mindee/product/us/bank_check/bank_check_v1.rb +1 -0
  95. data/lib/mindee/product/us/bank_check/bank_check_v1_document.rb +8 -8
  96. data/lib/mindee/product/us/driver_license/driver_license_v1.rb +1 -0
  97. data/lib/mindee/product/us/driver_license/driver_license_v1_document.rb +28 -28
  98. data/lib/mindee/product/us/w9/w9_v1.rb +39 -0
  99. data/lib/mindee/product/us/w9/w9_v1_document.rb +15 -0
  100. data/lib/mindee/product/us/w9/w9_v1_page.rb +102 -0
  101. data/lib/mindee/product.rb +6 -0
  102. data/lib/mindee/version.rb +5 -1
  103. data/lib/mindee.rb +45 -1
  104. metadata +48 -9
  105. data/docs/ruby-api-builder.md +0 -123
  106. data/docs/ruby-invoice-ocr.md +0 -271
  107. data/docs/ruby-passport-ocr.md +0 -165
  108. data/docs/ruby-receipt-ocr.md +0 -196
  109. data/lib/mindee/parsing/common/error.rb +0 -24
@@ -6,61 +6,13 @@ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
6
6
  # Load a file from disk
7
7
  input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
8
 
9
- # Put the document class in a local variable to keep the code DRY
10
- doc_class = Mindee::Product::InvoiceSplitter::InvoiceSplitterV1
11
-
12
- # Limit the amount of API calls to retrieve your document
13
- MAX_RETRIES = 10
14
-
15
- # How many seconds to wait in-between tries
16
- INTERVAL_SECS = 6
17
-
18
- # Counter to keep track of how many times we try to retrieve the document
19
- times_tried = 1
20
-
21
- queue_result = mindee_client.enqueue(
9
+ result = mindee_client.enqueue_and_parse(
22
10
  input_source,
23
- doc_class
11
+ Mindee::Product::InvoiceSplitter::InvoiceSplitterV1
24
12
  )
25
13
 
26
- # Get the id of the queue (job)
27
- queue_id = queue_result.job.id
28
-
29
- # Recursive function that tries to retrieve the completed document.
30
- # If the document is not "complete", try again
31
- def get_doc_from_async_queue(
32
- queue_id,
33
- mindee_client,
34
- doc_class,
35
- times_tried=0,
36
- interval_secs=INTERVAL_SECS,
37
- max_retries=MAX_RETRIES
38
- )
39
- # Have we exceeded our retry count?
40
- if times_tried >= max_retries
41
- raise "Maximum retries reached #{times_tried}"
42
- end
43
-
44
- # Wait for a few seconds before fetching
45
- sleep interval_secs
46
-
47
- # Fetch and parse the result, using the same type
48
- parsed_result = mindee_client.parse_queued(queue_id, doc_class)
49
-
50
- # Check whether the result is ready
51
- if parsed_result.job.status == Mindee::Parsing::Common::JobStatus::COMPLETED
52
- # Print a brief summary of the parsed data
53
- puts parsed_result.document
54
- return
55
- # Otherwise, try again...
56
- else
57
- get_doc_from_async_queue(
58
- queue_id, mindee_client,
59
- doc_class,
60
- times_tried+1
61
- )
62
- end
63
- end
14
+ # Print a full summary of the parsed data in RST format
15
+ puts result.document
64
16
 
65
- # Start the recursion...
66
- get_doc_from_async_queue(queue_id, mindee_client, doc_class)
17
+ # Print the document-level parsed data
18
+ # puts result.document.inference.prediction
@@ -0,0 +1,19 @@
1
+ require 'mindee'
2
+
3
+ # Init a new client
4
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
+
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::MultiReceiptsDetector::MultiReceiptsDetectorV1
13
+ )
14
+
15
+ # Print a full summary of the parsed data in RST format
16
+ puts result.document
17
+
18
+ # Print the document-level parsed data
19
+ # puts result.document.inference.prediction
@@ -0,0 +1,16 @@
1
+ require 'mindee'
2
+
3
+ # Init a new client
4
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
+
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::US::W9::W9V1
13
+ )
14
+
15
+ # Print a full summary of the parsed data in RST format
16
+ puts result.document
@@ -0,0 +1,97 @@
1
+ ---
2
+ title: Cropper OCR Ruby
3
+ ---
4
+ The Ruby OCR SDK supports the [Cropper API](https://platform.mindee.com/mindee/cropper).
5
+
6
+ Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/cropper/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
7
+ ![Cropper sample](https://github.com/mindee/client-lib-test-data/blob/main/products/cropper/default_sample.jpg?raw=true)
8
+
9
+ # Quick-Start
10
+ ```rb
11
+ require 'mindee'
12
+
13
+ # Init a new client
14
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
15
+
16
+ # Load a file from disk
17
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
18
+
19
+ # Parse the file
20
+ result = mindee_client.parse(
21
+ input_source,
22
+ Mindee::Product::Cropper::CropperV1
23
+ )
24
+
25
+ # Print a full summary of the parsed data in RST format
26
+ puts result.document
27
+ ```
28
+
29
+ **Output (RST):**
30
+ ```rst
31
+ ########
32
+ Document
33
+ ########
34
+ :Mindee ID: 149ce775-8302-4798-8649-7eda9fb84a1a
35
+ :Filename: default_sample.jpg
36
+
37
+ Inference
38
+ #########
39
+ :Product: mindee/cropper v1.0
40
+ :Rotation applied: No
41
+
42
+ Prediction
43
+ ==========
44
+
45
+ Page Predictions
46
+ ================
47
+
48
+ Page 0
49
+ ------
50
+ :Document Cropper: Polygon with 26 points.
51
+ Polygon with 25 points.
52
+ ```
53
+
54
+ # Field Types
55
+ ## Standard Fields
56
+ These fields are generic and used in several products.
57
+
58
+ ### Basic Field
59
+ Each prediction object contains a set of fields that inherit from the generic `Field` class.
60
+ A typical `Field` object will have the following attributes:
61
+
62
+ * **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
63
+ * **confidence** (Float, nil): the confidence score of the field prediction.
64
+ * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
65
+ * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
66
+ * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
67
+ * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
68
+
69
+
70
+ Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
71
+
72
+
73
+ ### Position Field
74
+ The position field `PositionField` does not implement all the basic `Field` attributes, only **bounding_box**, **polygon** and **page_id**. On top of these, it has access to:
75
+
76
+ * **rectangle** (`Mindee::Geometry::Quadrilateral`): a Polygon with four points that may be oriented (even beyond canvas).
77
+ * **quadrangle** (`Mindee::Geometry::Quadrilateral`): a free polygon made up of four points.
78
+
79
+ ## Page-Level Fields
80
+ Some fields are constrained to the page level, and so will not be retrievable to through the document.
81
+
82
+ # Attributes
83
+ The following fields are extracted for Cropper V1:
84
+
85
+ ## Document Cropper
86
+ [📄](#page-level-fields "This field is only present on individual pages.")**cropping** (Array<[PositionField](#position-field)>): List of documents found in the image.
87
+
88
+ ```rb
89
+ for page in result.document.inference.pages do
90
+ for cropping_elem in page.prediction.cropping do
91
+ puts cropping_elem.polygon
92
+ end
93
+ end
94
+ ```
95
+
96
+ # Questions?
97
+ [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)
data/docs/custom_v1.md ADDED
@@ -0,0 +1,109 @@
1
+ ---
2
+ title: Custom API Ruby
3
+ ---
4
+ The Ruby OCR SDK supports [custom-built APIs](https://developers.mindee.com/docs/build-your-first-document-parsing-api).
5
+ If your document isn't covered by one of Mindee's Off-the-Shelf APIs, you can create your own API using the[API Builder](https://platform.mindee.com/api-builder).
6
+
7
+ # Quick-Start
8
+
9
+ ```rb
10
+ require 'mindee'
11
+
12
+ # Init a new client
13
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
14
+
15
+ # Load a file from disk
16
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
17
+
18
+ # Initialize a custom endpoint for this product
19
+ custom_endpoint = mindee_client.create_endpoint(
20
+ account_name: 'my-account',
21
+ endpoint_name: 'my-endpoint'
22
+ )
23
+
24
+ # Parse the file
25
+ result = mindee_client.parse(
26
+ input_source,
27
+ Mindee::Product::Custom::CustomV1,
28
+ endpoint: custom_endpoint
29
+ )
30
+
31
+ # Print a full summary of the parsed data in RST format
32
+ puts result.document
33
+
34
+ # Print the document-level parsed data
35
+ # puts result.document.inference.prediction
36
+
37
+ # Looping over all prediction values
38
+ result.document.inference.prediction.fields.each do |field_name, field_data|
39
+ puts field_name
40
+ puts field_data.values
41
+ puts field_data.to_s
42
+ end
43
+ ```
44
+
45
+ # Custom Endpoints
46
+
47
+ You may have noticed in the previous step that in order to access a custom build, you will need to provide an account and an endpoint name at the very least.
48
+
49
+ Although it is optional, the version number should match the latest version of your build in most use-cases.
50
+ If it is not set, it will default to "1".
51
+
52
+
53
+ # Field Types
54
+
55
+ ## Custom Fields
56
+
57
+ ### List Field
58
+
59
+ A `ListField` is a special type of custom list that implements the following:
60
+
61
+ * **confidence** (`Float`): the confidence score of the field prediction.
62
+ * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
63
+ * **values** (`Array<`[ListFieldItem](#list-field-item)`>`): list of value fields
64
+
65
+ Since the inner contents can vary, the value isn't accessed through a property, but rather through the following functions:
66
+ * **contents_list()** (`[Array, Hash, String, nil]`): returns a list of values for each element.
67
+ * **contents_str(separator:' ')** (`String`): returns a list of concatenated values, with an optional **separator** `String` between them.
68
+ * **to_s()**: returns a string representation of all values, with an empty space between each of them.
69
+
70
+ #### List Field Item
71
+
72
+ Values of `ListField`s are stored in a `ListFieldItem` structure, which is implemented as follows:
73
+ * **content** (`String`): extracted content of the prediction
74
+ * **confidence** (`Float`): the confidence score of the prediction
75
+ * **bounding_box** (`Quadrilateral`): 4 relative vertices corrdinates of a rectangle containing the word in the document.
76
+ * **polygon** (`Polygon`): vertices of a polygon containing the word.
77
+ * **page_id** (`Integer`): the ID of the page, is `nil` when at document-level.
78
+
79
+ ### Classification Field
80
+
81
+ A `ClassificationField` is a special type of custom classification that implements the following:
82
+
83
+ * **value** (`String`): the value of the classification. Corresponds to one of the values specified during training.
84
+ * **confidence** (`Float`): the confidence score of the field prediction.
85
+ * **to_s()**: returns a string representation of all values, with an empty space between each of them.
86
+
87
+ # Attributes
88
+
89
+ Custom builds always have access to at least two attributes:
90
+
91
+ ## Fields
92
+
93
+ **fields** ({`String`=> [ListField](#list-field)}):
94
+
95
+ ```rb
96
+ puts result.document.inference.prediction.fields[:my_field].value
97
+ ```
98
+
99
+ ## Classifications
100
+
101
+ **classifications** ({`String` => [ClassificationField](#classification-field)}): The purchase category among predefined classes.
102
+
103
+ ```js
104
+ console.log(result.document.inference.prediction.classifications["my-classification"].to_s);
105
+ ```
106
+
107
+ # Questions?
108
+
109
+ [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)
@@ -0,0 +1,306 @@
1
+ ---
2
+ title: Receipt OCR Ruby
3
+ ---
4
+ The Ruby OCR SDK supports the [Receipt API](https://platform.mindee.com/mindee/expense_receipts).
5
+
6
+ Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
7
+ ![Receipt sample](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg?raw=true)
8
+
9
+ # Quick-Start
10
+ ```rb
11
+ require 'mindee'
12
+
13
+ # Init a new client
14
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
15
+
16
+ # Load a file from disk
17
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
18
+
19
+ # Parse the file
20
+ result = mindee_client.parse(
21
+ input_source,
22
+ Mindee::Product::Receipt::ReceiptV5
23
+ )
24
+
25
+ # Print a full summary of the parsed data in RST format
26
+ puts result.document
27
+
28
+ # Print the document-level parsed data
29
+ # puts result.document.inference.prediction
30
+ ```
31
+
32
+ **Output (RST):**
33
+ ```rst
34
+ ########
35
+ Document
36
+ ########
37
+ :Mindee ID: ce41e37a-65d8-4de1-b34b-1c92ab04b1ae
38
+ :Filename: default_sample.jpg
39
+
40
+ Inference
41
+ #########
42
+ :Product: mindee/expense_receipts v5.0
43
+ :Rotation applied: Yes
44
+
45
+ Prediction
46
+ ==========
47
+ :Expense Locale: en-GB; en; GB; GBP;
48
+ :Purchase Category: food
49
+ :Purchase Subcategory: restaurant
50
+ :Document Type: EXPENSE RECEIPT
51
+ :Purchase Date: 2016-02-26
52
+ :Purchase Time: 15:20
53
+ :Total Amount: 10.20
54
+ :Total Net: 8.50
55
+ :Total Tax: 1.70
56
+ :Tip and Gratuity:
57
+ :Taxes:
58
+ +---------------+--------+----------+---------------+
59
+ | Base | Code | Rate (%) | Amount |
60
+ +===============+========+==========+===============+
61
+ | 8.50 | VAT | 20.00 | 1.70 |
62
+ +---------------+--------+----------+---------------+
63
+ :Supplier Name: CLACHAN
64
+ :Supplier Company Registrations: 232153895
65
+ 232153895
66
+ :Supplier Address: 34 kingley street w1b 5qh
67
+ :Supplier Phone Number: 02074940834
68
+ :Line Items:
69
+ +--------------------------------------+----------+--------------+------------+
70
+ | Description | Quantity | Total Amount | Unit Price |
71
+ +======================================+==========+==============+============+
72
+ | Meantime Pale | 2.00 | 10.20 | |
73
+ +--------------------------------------+----------+--------------+------------+
74
+
75
+ Page Predictions
76
+ ================
77
+
78
+ Page 0
79
+ ------
80
+ :Expense Locale: en-GB; en; GB; GBP;
81
+ :Purchase Category: food
82
+ :Purchase Subcategory: restaurant
83
+ :Document Type: EXPENSE RECEIPT
84
+ :Purchase Date: 2016-02-26
85
+ :Purchase Time: 15:20
86
+ :Total Amount: 10.20
87
+ :Total Net: 8.50
88
+ :Total Tax: 1.70
89
+ :Tip and Gratuity:
90
+ :Taxes:
91
+ +---------------+--------+----------+---------------+
92
+ | Base | Code | Rate (%) | Amount |
93
+ +===============+========+==========+===============+
94
+ | 8.50 | VAT | 20.00 | 1.70 |
95
+ +---------------+--------+----------+---------------+
96
+ :Supplier Name: CLACHAN
97
+ :Supplier Company Registrations: 232153895
98
+ 232153895
99
+ :Supplier Address: 34 kingley street w1b 5qh
100
+ :Supplier Phone Number: 02074940834
101
+ :Line Items:
102
+ +--------------------------------------+----------+--------------+------------+
103
+ | Description | Quantity | Total Amount | Unit Price |
104
+ +======================================+==========+==============+============+
105
+ | Meantime Pale | 2.00 | 10.20 | |
106
+ +--------------------------------------+----------+--------------+------------+
107
+ ```
108
+
109
+ # Field Types
110
+ ## Standard Fields
111
+ These fields are generic and used in several products.
112
+
113
+ ### Basic Field
114
+ Each prediction object contains a set of fields that inherit from the generic `Field` class.
115
+ A typical `Field` object will have the following attributes:
116
+
117
+ * **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
118
+ * **confidence** (Float, nil): the confidence score of the field prediction.
119
+ * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
120
+ * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
121
+ * **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
122
+ * **reconstructed** (`Boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
123
+
124
+
125
+ Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
126
+
127
+
128
+ ### Amount Field
129
+ The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`).
130
+
131
+
132
+ ### Classification Field
133
+ The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **page_id**.
134
+
135
+ > Note: a classification field's `value is always a `String`.
136
+
137
+
138
+ ### Company Registration Field
139
+ Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the following:
140
+
141
+ * **type** (`String`): the type of company.
142
+
143
+ ### Date Field
144
+ Aside from the basic `Field` attributes, the date field `DateField` also implements the following:
145
+
146
+ * **date_object** (`Date`): an accessible representation of the value as a JavaScript object.
147
+
148
+ ### Locale Field
149
+ The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `Field` attributes, but it comes with its own:
150
+
151
+ * **language** (`String`): ISO 639-1 language code (e.g.: `en` for English). Can be `nil`.
152
+ * **country** (`String`): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.: `GRB` or `GB` for "Great Britain"). Can be `nil`.
153
+ * **currency** (`String`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `nil`.
154
+
155
+ ### String Field
156
+ The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`).
157
+
158
+ ### Taxes Field
159
+ #### Tax
160
+ Aside from the basic `Field` attributes, the tax field `TaxField` also implements the following:
161
+
162
+ * **rate** (`Float`): the tax rate applied to an item can be expressed as a percentage. Can be `nil`.
163
+ * **code** (`String`): tax code (or equivalent, depending on the origin of the document). Can be `nil`.
164
+ * **base** (`Float`): base amount used for the tax. Can be `nil`.
165
+
166
+ > Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure.
167
+
168
+ #### Taxes (Array)
169
+ The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several objects, it has access to a custom `to_s` method that can render a `TaxField` object as a table line.
170
+
171
+ ## Specific Fields
172
+ Fields which are specific to this product; they are not used in any other product.
173
+
174
+ ### Line Items Field
175
+ List of line item details.
176
+
177
+ A `ReceiptV5LineItem` implements the following attributes:
178
+
179
+ * `description` (String): The item description.
180
+ * `quantity` (Float): The item quantity.
181
+ * `total_amount` (Float): The item total amount.
182
+ * `unit_price` (Float): The item unit price.
183
+
184
+ # Attributes
185
+ The following fields are extracted for Receipt V5:
186
+
187
+ ## Purchase Category
188
+ **category** ([ClassificationField](#classification-field)): The purchase category among predefined classes.
189
+
190
+ ```rb
191
+ puts result.document.inference.prediction.category.value
192
+ ```
193
+
194
+ ## Purchase Date
195
+ **date** ([DateField](#date-field)): The date the purchase was made.
196
+
197
+ ```rb
198
+ puts result.document.inference.prediction.date.value
199
+ ```
200
+
201
+ ## Document Type
202
+ **document_type** ([ClassificationField](#classification-field)): One of: 'CREDIT CARD RECEIPT', 'EXPENSE RECEIPT'.
203
+
204
+ ```rb
205
+ puts result.document.inference.prediction.document_type.value
206
+ ```
207
+
208
+ ## Line Items
209
+ **line_items** (Array<[ReceiptV5LineItem](#line-items-field)>): List of line item details.
210
+
211
+ ```rb
212
+ for line_items_elem in result.document.inference.prediction.line_items do
213
+ puts line_items_elem.value
214
+ end
215
+ ```
216
+
217
+ ## Expense Locale
218
+ **locale** ([LocaleField](#locale-field)): The locale detected on the document.
219
+
220
+ ```rb
221
+ puts result.document.inference.prediction.locale.value
222
+ ```
223
+
224
+ ## Purchase Subcategory
225
+ **subcategory** ([ClassificationField](#classification-field)): The purchase subcategory among predefined classes for transport and food.
226
+
227
+ ```rb
228
+ puts result.document.inference.prediction.subcategory.value
229
+ ```
230
+
231
+ ## Supplier Address
232
+ **supplier_address** ([StringField](#string-field)): The address of the supplier or merchant.
233
+
234
+ ```rb
235
+ puts result.document.inference.prediction.supplier_address.value
236
+ ```
237
+
238
+ ## Supplier Company Registrations
239
+ **supplier_company_registrations** (Array<[CompanyRegistrationField](#company-registration-field)>): List of company registrations associated to the supplier.
240
+
241
+ ```rb
242
+ for supplier_company_registrations_elem in result.document.inference.prediction.supplier_company_registrations do
243
+ puts supplier_company_registrations_elem.value
244
+ end
245
+ ```
246
+
247
+ ## Supplier Name
248
+ **supplier_name** ([StringField](#string-field)): The name of the supplier or merchant.
249
+
250
+ ```rb
251
+ puts result.document.inference.prediction.supplier_name.value
252
+ ```
253
+
254
+ ## Supplier Phone Number
255
+ **supplier_phone_number** ([StringField](#string-field)): The phone number of the supplier or merchant.
256
+
257
+ ```rb
258
+ puts result.document.inference.prediction.supplier_phone_number.value
259
+ ```
260
+
261
+ ## Taxes
262
+ **taxes** (Array<[TaxField](#taxes-field)>): List of tax lines information.
263
+
264
+ ```rb
265
+ for taxes_elem in result.document.inference.prediction.taxes do
266
+ puts taxes_elem.to_s
267
+ end
268
+ ```
269
+
270
+ ## Purchase Time
271
+ **time** ([StringField](#string-field)): The time the purchase was made.
272
+
273
+ ```rb
274
+ puts result.document.inference.prediction.time.value
275
+ ```
276
+
277
+ ## Tip and Gratuity
278
+ **tip** ([AmountField](#amount-field)): The total amount of tip and gratuity.
279
+
280
+ ```rb
281
+ puts result.document.inference.prediction.tip.value
282
+ ```
283
+
284
+ ## Total Amount
285
+ **total_amount** ([AmountField](#amount-field)): The total amount paid: includes taxes, discounts, fees, tips, and gratuity.
286
+
287
+ ```rb
288
+ puts result.document.inference.prediction.total_amount.value
289
+ ```
290
+
291
+ ## Total Net
292
+ **total_net** ([AmountField](#amount-field)): The net amount paid: does not include taxes, fees, and discounts.
293
+
294
+ ```rb
295
+ puts result.document.inference.prediction.total_net.value
296
+ ```
297
+
298
+ ## Total Tax
299
+ **total_tax** ([AmountField](#amount-field)): The total amount of taxes.
300
+
301
+ ```rb
302
+ puts result.document.inference.prediction.total_tax.value
303
+ ```
304
+
305
+ # Questions?
306
+ [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)