mindee 4.7.2 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +6 -6
- data/Rakefile +1 -0
- data/lib/mindee/errors/mindee_http_error_v2.rb +23 -4
- data/lib/mindee/errors/mindee_http_unknown_error_v2.rb +18 -0
- data/lib/mindee/http/endpoint.rb +1 -0
- data/lib/mindee/parsing/v2/error_item.rb +21 -0
- data/lib/mindee/parsing/v2/error_response.rb +18 -3
- data/lib/mindee/parsing/v2/inference_result.rb +4 -0
- data/lib/mindee/parsing/v2/rag_metadata.rb +17 -0
- data/lib/mindee/version.rb +1 -1
- data/mindee.gemspec +1 -0
- data/sig/mindee/errors/mindee_http_error_v2.rbs +4 -1
- data/sig/mindee/errors/mindee_http_unknown_error_v2.rbs +9 -0
- data/sig/mindee/http/endpoint.rbs +1 -0
- data/sig/mindee/parsing/v2/error_item.rbs +13 -0
- data/sig/mindee/parsing/v2/error_response.rbs +3 -0
- data/sig/mindee/parsing/v2/inference_result.rbs +1 -0
- data/sig/mindee/parsing/v2/rag_metadata.rbs +13 -0
- metadata +22 -34
- data/docs/advanced_file_operations.md +0 -109
- data/docs/getting_started.md +0 -257
- data/docs/global_products/barcode_reader_v1.md +0 -125
- data/docs/global_products/bill_of_lading_v1.md +0 -276
- data/docs/global_products/business_card_v1.md +0 -194
- data/docs/global_products/cropper_v1.md +0 -123
- data/docs/global_products/delivery_notes_v1.md +0 -168
- data/docs/global_products/driver_license_v1.md +0 -212
- data/docs/global_products/expense_receipts_v5.md +0 -415
- data/docs/global_products/financial_document_v1.md +0 -615
- data/docs/global_products/international_id_v2.md +0 -264
- data/docs/global_products/invoice_splitter_v1.md +0 -127
- data/docs/global_products/invoices_v4.md +0 -576
- data/docs/global_products/multi_receipts_detector_v1.md +0 -131
- data/docs/global_products/nutrition_facts_v1.md +0 -399
- data/docs/global_products/passport_v1.md +0 -207
- data/docs/global_products/resume_v1.md +0 -384
- data/docs/global_products/universal.md +0 -113
- data/docs/global_products.md +0 -6
- data/docs/loading_a_document.md +0 -330
- data/docs/localized_products/bank_account_details_v2.md +0 -158
- data/docs/localized_products/bank_check_v1.md +0 -205
- data/docs/localized_products/bank_statement_fr_v2.md +0 -269
- data/docs/localized_products/carte_grise_v1.md +0 -475
- data/docs/localized_products/energy_bill_fra_v1.md +0 -342
- data/docs/localized_products/french_healthcard_v1.md +0 -142
- data/docs/localized_products/idcard_fr_v2.md +0 -284
- data/docs/localized_products/ind_passport_v1.md +0 -307
- data/docs/localized_products/payslip_fra_v3.md +0 -344
- data/docs/localized_products/us_healthcare_cards_v1.md +0 -258
- data/docs/localized_products/us_mail_v3.md +0 -152
- data/docs/localized_products.md +0 -6
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Nutrition Facts Label
|
|
3
|
-
category: 622b805aaec68102ea7fcbc2
|
|
4
|
-
slug: ruby-nutrition-facts-label-ocr
|
|
5
|
-
parentDoc: 67b49df15b843f3fa9cd622b
|
|
6
|
-
---
|
|
7
|
-
The Ruby Client Library supports the [Nutrition Facts Label API](https://platform.mindee.com/mindee/nutrition_facts).
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
> 📝 Product Specs
|
|
11
|
-
>
|
|
12
|
-
> | Specification | Details |
|
|
13
|
-
> | ------------------------------ | -------------------------------------------------- |
|
|
14
|
-
> | Endpoint Name | `nutrition_facts` |
|
|
15
|
-
> | Recommended Version | `v1.0` |
|
|
16
|
-
> | Supports Polling/Webhooks | ✔️ Yes |
|
|
17
|
-
> | Support Synchronous HTTP Calls | ❌ No |
|
|
18
|
-
> | Geography | 🌐 Global |
|
|
19
|
-
|
|
20
|
-
> 🔐 Polling Limitations
|
|
21
|
-
>
|
|
22
|
-
> | Setting | Parameter name | Default Value |
|
|
23
|
-
> | ------------------------------- | ----------------------- | ------------- |
|
|
24
|
-
> | Initial Delay Before Polling | `initial_delay_seconds` | 2 seconds |
|
|
25
|
-
> | Default Delay Between Calls | `delay_sec` | 1.5 seconds |
|
|
26
|
-
> | Polling Attempts Before Timeout | `max_retries` | 80 retries |
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/nutrition_facts/default_sample.jpg),
|
|
30
|
-
we are going to illustrate how to extract the data that we want using the Ruby Client Library.
|
|
31
|
-

|
|
32
|
-
|
|
33
|
-
# Quick-Start
|
|
34
|
-
```rb
|
|
35
|
-
#
|
|
36
|
-
# Install the Ruby client library by running:
|
|
37
|
-
# gem install mindee
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
require 'mindee'
|
|
41
|
-
|
|
42
|
-
# Init a new client
|
|
43
|
-
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
|
|
44
|
-
|
|
45
|
-
# Load a file from disk
|
|
46
|
-
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
|
|
47
|
-
|
|
48
|
-
# Parse the file
|
|
49
|
-
result = mindee_client.parse(
|
|
50
|
-
input_source,
|
|
51
|
-
Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
# Print a full summary of the parsed data in RST format
|
|
55
|
-
puts result.document
|
|
56
|
-
|
|
57
|
-
# Print the document-level parsed data
|
|
58
|
-
# puts result.document.inference.prediction
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
**Output (RST):**
|
|
62
|
-
```rst
|
|
63
|
-
########
|
|
64
|
-
Document
|
|
65
|
-
########
|
|
66
|
-
:Mindee ID: 38a12fe0-5d69-4ca4-9b30-12f1b659311c
|
|
67
|
-
:Filename: default_sample.jpg
|
|
68
|
-
|
|
69
|
-
Inference
|
|
70
|
-
#########
|
|
71
|
-
:Product: mindee/nutrition_facts v1.0
|
|
72
|
-
:Rotation applied: No
|
|
73
|
-
|
|
74
|
-
Prediction
|
|
75
|
-
==========
|
|
76
|
-
:Serving per Box: 2.00
|
|
77
|
-
:Serving Size:
|
|
78
|
-
:Amount: 228.00
|
|
79
|
-
:Unit: g
|
|
80
|
-
:Calories:
|
|
81
|
-
:Daily Value:
|
|
82
|
-
:Per 100g:
|
|
83
|
-
:Per Serving: 250.00
|
|
84
|
-
:Total Fat:
|
|
85
|
-
:Daily Value:
|
|
86
|
-
:Per 100g:
|
|
87
|
-
:Per Serving: 12.00
|
|
88
|
-
:Saturated Fat:
|
|
89
|
-
:Daily Value: 15.00
|
|
90
|
-
:Per 100g:
|
|
91
|
-
:Per Serving: 3.00
|
|
92
|
-
:Trans Fat:
|
|
93
|
-
:Daily Value:
|
|
94
|
-
:Per 100g:
|
|
95
|
-
:Per Serving: 3.00
|
|
96
|
-
:Cholesterol:
|
|
97
|
-
:Daily Value: 10.00
|
|
98
|
-
:Per 100g:
|
|
99
|
-
:Per Serving: 30.00
|
|
100
|
-
:Total Carbohydrate:
|
|
101
|
-
:Daily Value: 10.00
|
|
102
|
-
:Per 100g:
|
|
103
|
-
:Per Serving: 31.00
|
|
104
|
-
:Dietary Fiber:
|
|
105
|
-
:Daily Value: 0.00
|
|
106
|
-
:Per 100g:
|
|
107
|
-
:Per Serving: 0.00
|
|
108
|
-
:Total Sugars:
|
|
109
|
-
:Daily Value:
|
|
110
|
-
:Per 100g:
|
|
111
|
-
:Per Serving: 5.00
|
|
112
|
-
:Added Sugars:
|
|
113
|
-
:Daily Value:
|
|
114
|
-
:Per 100g:
|
|
115
|
-
:Per Serving:
|
|
116
|
-
:Protein:
|
|
117
|
-
:Daily Value:
|
|
118
|
-
:Per 100g:
|
|
119
|
-
:Per Serving: 5.00
|
|
120
|
-
:sodium:
|
|
121
|
-
:Daily Value: 20.00
|
|
122
|
-
:Per 100g:
|
|
123
|
-
:Per Serving: 470.00
|
|
124
|
-
:Unit: mg
|
|
125
|
-
:nutrients:
|
|
126
|
-
+-------------+----------------------+----------+-------------+------+
|
|
127
|
-
| Daily Value | Name | Per 100g | Per Serving | Unit |
|
|
128
|
-
+=============+======================+==========+=============+======+
|
|
129
|
-
| 12.00 | Vitamin A | | 4.00 | mcg |
|
|
130
|
-
+-------------+----------------------+----------+-------------+------+
|
|
131
|
-
| 12.00 | Vitamin C | | 2.00 | mg |
|
|
132
|
-
+-------------+----------------------+----------+-------------+------+
|
|
133
|
-
| 12.00 | Calcium | | 45.60 | mg |
|
|
134
|
-
+-------------+----------------------+----------+-------------+------+
|
|
135
|
-
| 12.00 | Iron | | 0.90 | mg |
|
|
136
|
-
+-------------+----------------------+----------+-------------+------+
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
# Field Types
|
|
140
|
-
## Standard Fields
|
|
141
|
-
These fields are generic and used in several products.
|
|
142
|
-
|
|
143
|
-
### Basic Field
|
|
144
|
-
Each prediction object contains a set of fields that inherit from the generic `Field` class.
|
|
145
|
-
A typical `Field` object will have the following attributes:
|
|
146
|
-
|
|
147
|
-
* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted.
|
|
148
|
-
* **confidence** (Float, nil): the confidence score of the field prediction.
|
|
149
|
-
* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
|
|
150
|
-
* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
|
|
151
|
-
* **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level.
|
|
152
|
-
* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it).
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
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.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
### Amount Field
|
|
159
|
-
The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`).
|
|
160
|
-
|
|
161
|
-
## Specific Fields
|
|
162
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
163
|
-
|
|
164
|
-
### Serving Size Field
|
|
165
|
-
The size of a single serving of the product.
|
|
166
|
-
|
|
167
|
-
A `NutritionFactsLabelV1ServingSize` implements the following attributes:
|
|
168
|
-
|
|
169
|
-
* `amount` (Float): The amount of a single serving.
|
|
170
|
-
* `unit` (String): The unit for the amount of a single serving.
|
|
171
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
172
|
-
|
|
173
|
-
### Calories Field
|
|
174
|
-
The amount of calories in the product.
|
|
175
|
-
|
|
176
|
-
A `NutritionFactsLabelV1Calorie` implements the following attributes:
|
|
177
|
-
|
|
178
|
-
* `daily_value` (Float): DVs are the recommended amounts of calories to consume or not to exceed each day.
|
|
179
|
-
* `per_100g` (Float): The amount of calories per 100g of the product.
|
|
180
|
-
* `per_serving` (Float): The amount of calories per serving of the product.
|
|
181
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
182
|
-
|
|
183
|
-
### Total Fat Field
|
|
184
|
-
The total amount of fat in the product.
|
|
185
|
-
|
|
186
|
-
A `NutritionFactsLabelV1TotalFat` implements the following attributes:
|
|
187
|
-
|
|
188
|
-
* `daily_value` (Float): DVs are the recommended amounts of total fat to consume or not to exceed each day.
|
|
189
|
-
* `per_100g` (Float): The amount of total fat per 100g of the product.
|
|
190
|
-
* `per_serving` (Float): The amount of total fat per serving of the product.
|
|
191
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
192
|
-
|
|
193
|
-
### Saturated Fat Field
|
|
194
|
-
The amount of saturated fat in the product.
|
|
195
|
-
|
|
196
|
-
A `NutritionFactsLabelV1SaturatedFat` implements the following attributes:
|
|
197
|
-
|
|
198
|
-
* `daily_value` (Float): DVs are the recommended amounts of saturated fat to consume or not to exceed each day.
|
|
199
|
-
* `per_100g` (Float): The amount of saturated fat per 100g of the product.
|
|
200
|
-
* `per_serving` (Float): The amount of saturated fat per serving of the product.
|
|
201
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
202
|
-
|
|
203
|
-
### Trans Fat Field
|
|
204
|
-
The amount of trans fat in the product.
|
|
205
|
-
|
|
206
|
-
A `NutritionFactsLabelV1TransFat` implements the following attributes:
|
|
207
|
-
|
|
208
|
-
* `daily_value` (Float): DVs are the recommended amounts of trans fat to consume or not to exceed each day.
|
|
209
|
-
* `per_100g` (Float): The amount of trans fat per 100g of the product.
|
|
210
|
-
* `per_serving` (Float): The amount of trans fat per serving of the product.
|
|
211
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
212
|
-
|
|
213
|
-
### Cholesterol Field
|
|
214
|
-
The amount of cholesterol in the product.
|
|
215
|
-
|
|
216
|
-
A `NutritionFactsLabelV1Cholesterol` implements the following attributes:
|
|
217
|
-
|
|
218
|
-
* `daily_value` (Float): DVs are the recommended amounts of cholesterol to consume or not to exceed each day.
|
|
219
|
-
* `per_100g` (Float): The amount of cholesterol per 100g of the product.
|
|
220
|
-
* `per_serving` (Float): The amount of cholesterol per serving of the product.
|
|
221
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
222
|
-
|
|
223
|
-
### Total Carbohydrate Field
|
|
224
|
-
The total amount of carbohydrates in the product.
|
|
225
|
-
|
|
226
|
-
A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes:
|
|
227
|
-
|
|
228
|
-
* `daily_value` (Float): DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day.
|
|
229
|
-
* `per_100g` (Float): The amount of total carbohydrates per 100g of the product.
|
|
230
|
-
* `per_serving` (Float): The amount of total carbohydrates per serving of the product.
|
|
231
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
232
|
-
|
|
233
|
-
### Dietary Fiber Field
|
|
234
|
-
The amount of dietary fiber in the product.
|
|
235
|
-
|
|
236
|
-
A `NutritionFactsLabelV1DietaryFiber` implements the following attributes:
|
|
237
|
-
|
|
238
|
-
* `daily_value` (Float): DVs are the recommended amounts of dietary fiber to consume or not to exceed each day.
|
|
239
|
-
* `per_100g` (Float): The amount of dietary fiber per 100g of the product.
|
|
240
|
-
* `per_serving` (Float): The amount of dietary fiber per serving of the product.
|
|
241
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
242
|
-
|
|
243
|
-
### Total Sugars Field
|
|
244
|
-
The total amount of sugars in the product.
|
|
245
|
-
|
|
246
|
-
A `NutritionFactsLabelV1TotalSugar` implements the following attributes:
|
|
247
|
-
|
|
248
|
-
* `daily_value` (Float): DVs are the recommended amounts of total sugars to consume or not to exceed each day.
|
|
249
|
-
* `per_100g` (Float): The amount of total sugars per 100g of the product.
|
|
250
|
-
* `per_serving` (Float): The amount of total sugars per serving of the product.
|
|
251
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
252
|
-
|
|
253
|
-
### Added Sugars Field
|
|
254
|
-
The amount of added sugars in the product.
|
|
255
|
-
|
|
256
|
-
A `NutritionFactsLabelV1AddedSugar` implements the following attributes:
|
|
257
|
-
|
|
258
|
-
* `daily_value` (Float): DVs are the recommended amounts of added sugars to consume or not to exceed each day.
|
|
259
|
-
* `per_100g` (Float): The amount of added sugars per 100g of the product.
|
|
260
|
-
* `per_serving` (Float): The amount of added sugars per serving of the product.
|
|
261
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
262
|
-
|
|
263
|
-
### Protein Field
|
|
264
|
-
The amount of protein in the product.
|
|
265
|
-
|
|
266
|
-
A `NutritionFactsLabelV1Protein` implements the following attributes:
|
|
267
|
-
|
|
268
|
-
* `daily_value` (Float): DVs are the recommended amounts of protein to consume or not to exceed each day.
|
|
269
|
-
* `per_100g` (Float): The amount of protein per 100g of the product.
|
|
270
|
-
* `per_serving` (Float): The amount of protein per serving of the product.
|
|
271
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
272
|
-
|
|
273
|
-
### sodium Field
|
|
274
|
-
The amount of sodium in the product.
|
|
275
|
-
|
|
276
|
-
A `NutritionFactsLabelV1Sodium` implements the following attributes:
|
|
277
|
-
|
|
278
|
-
* `daily_value` (Float): DVs are the recommended amounts of sodium to consume or not to exceed each day.
|
|
279
|
-
* `per_100g` (Float): The amount of sodium per 100g of the product.
|
|
280
|
-
* `per_serving` (Float): The amount of sodium per serving of the product.
|
|
281
|
-
* `unit` (String): The unit of measurement for the amount of sodium.
|
|
282
|
-
Fields which are specific to this product; they are not used in any other product.
|
|
283
|
-
|
|
284
|
-
### nutrients Field
|
|
285
|
-
The amount of nutrients in the product.
|
|
286
|
-
|
|
287
|
-
A `NutritionFactsLabelV1Nutrient` implements the following attributes:
|
|
288
|
-
|
|
289
|
-
* `daily_value` (Float): DVs are the recommended amounts of nutrients to consume or not to exceed each day.
|
|
290
|
-
* `name` (String): The name of nutrients of the product.
|
|
291
|
-
* `per_100g` (Float): The amount of nutrients per 100g of the product.
|
|
292
|
-
* `per_serving` (Float): The amount of nutrients per serving of the product.
|
|
293
|
-
* `unit` (String): The unit of measurement for the amount of nutrients.
|
|
294
|
-
|
|
295
|
-
# Attributes
|
|
296
|
-
The following fields are extracted for Nutrition Facts Label V1:
|
|
297
|
-
|
|
298
|
-
## Added Sugars
|
|
299
|
-
**added_sugars** ([NutritionFactsLabelV1AddedSugar](#added-sugars-field)): The amount of added sugars in the product.
|
|
300
|
-
|
|
301
|
-
```rb
|
|
302
|
-
puts result.document.inference.prediction.added_sugars.value
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
## Calories
|
|
306
|
-
**calories** ([NutritionFactsLabelV1Calorie](#calories-field)): The amount of calories in the product.
|
|
307
|
-
|
|
308
|
-
```rb
|
|
309
|
-
puts result.document.inference.prediction.calories.value
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
## Cholesterol
|
|
313
|
-
**cholesterol** ([NutritionFactsLabelV1Cholesterol](#cholesterol-field)): The amount of cholesterol in the product.
|
|
314
|
-
|
|
315
|
-
```rb
|
|
316
|
-
puts result.document.inference.prediction.cholesterol.value
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
## Dietary Fiber
|
|
320
|
-
**dietary_fiber** ([NutritionFactsLabelV1DietaryFiber](#dietary-fiber-field)): The amount of dietary fiber in the product.
|
|
321
|
-
|
|
322
|
-
```rb
|
|
323
|
-
puts result.document.inference.prediction.dietary_fiber.value
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
## nutrients
|
|
327
|
-
**nutrients** (Array<[NutritionFactsLabelV1Nutrient](#nutrients-field)>): The amount of nutrients in the product.
|
|
328
|
-
|
|
329
|
-
```rb
|
|
330
|
-
result.document.inference.prediction.nutrients do |nutrients_elem|
|
|
331
|
-
puts nutrients_elem.value
|
|
332
|
-
end
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
## Protein
|
|
336
|
-
**protein** ([NutritionFactsLabelV1Protein](#protein-field)): The amount of protein in the product.
|
|
337
|
-
|
|
338
|
-
```rb
|
|
339
|
-
puts result.document.inference.prediction.protein.value
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
## Saturated Fat
|
|
343
|
-
**saturated_fat** ([NutritionFactsLabelV1SaturatedFat](#saturated-fat-field)): The amount of saturated fat in the product.
|
|
344
|
-
|
|
345
|
-
```rb
|
|
346
|
-
puts result.document.inference.prediction.saturated_fat.value
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
## Serving per Box
|
|
350
|
-
**serving_per_box** ([AmountField](#amount-field)): The number of servings in each box of the product.
|
|
351
|
-
|
|
352
|
-
```rb
|
|
353
|
-
puts result.document.inference.prediction.serving_per_box.value
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
## Serving Size
|
|
357
|
-
**serving_size** ([NutritionFactsLabelV1ServingSize](#serving-size-field)): The size of a single serving of the product.
|
|
358
|
-
|
|
359
|
-
```rb
|
|
360
|
-
puts result.document.inference.prediction.serving_size.value
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
## sodium
|
|
364
|
-
**sodium** ([NutritionFactsLabelV1Sodium](#sodium-field)): The amount of sodium in the product.
|
|
365
|
-
|
|
366
|
-
```rb
|
|
367
|
-
puts result.document.inference.prediction.sodium.value
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
## Total Carbohydrate
|
|
371
|
-
**total_carbohydrate** ([NutritionFactsLabelV1TotalCarbohydrate](#total-carbohydrate-field)): The total amount of carbohydrates in the product.
|
|
372
|
-
|
|
373
|
-
```rb
|
|
374
|
-
puts result.document.inference.prediction.total_carbohydrate.value
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
## Total Fat
|
|
378
|
-
**total_fat** ([NutritionFactsLabelV1TotalFat](#total-fat-field)): The total amount of fat in the product.
|
|
379
|
-
|
|
380
|
-
```rb
|
|
381
|
-
puts result.document.inference.prediction.total_fat.value
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
## Total Sugars
|
|
385
|
-
**total_sugars** ([NutritionFactsLabelV1TotalSugar](#total-sugars-field)): The total amount of sugars in the product.
|
|
386
|
-
|
|
387
|
-
```rb
|
|
388
|
-
puts result.document.inference.prediction.total_sugars.value
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
## Trans Fat
|
|
392
|
-
**trans_fat** ([NutritionFactsLabelV1TransFat](#trans-fat-field)): The amount of trans fat in the product.
|
|
393
|
-
|
|
394
|
-
```rb
|
|
395
|
-
puts result.document.inference.prediction.trans_fat.value
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
# Questions?
|
|
399
|
-
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Passport
|
|
3
|
-
category: 622b805aaec68102ea7fcbc2
|
|
4
|
-
slug: ruby-passport-ocr
|
|
5
|
-
parentDoc: 67b49df15b843f3fa9cd622b
|
|
6
|
-
---
|
|
7
|
-
The Ruby Client Library supports the [Passport API](https://platform.mindee.com/mindee/passport).
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
> 📝 Product Specs
|
|
11
|
-
>
|
|
12
|
-
> | Specification | Details |
|
|
13
|
-
> | ------------------------------ | -------------------------------------------------- |
|
|
14
|
-
> | Endpoint Name | `passport` |
|
|
15
|
-
> | Recommended Version | `v1.1` |
|
|
16
|
-
> | Supports Polling/Webhooks | ❌ No |
|
|
17
|
-
> | Support Synchronous HTTP Calls | ✔️ Yes |
|
|
18
|
-
> | Geography | 🌐 Global |
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/passport/default_sample.jpg),
|
|
22
|
-
we are going to illustrate how to extract the data that we want using the Ruby Client Library.
|
|
23
|
-

|
|
24
|
-
|
|
25
|
-
# Quick-Start
|
|
26
|
-
```rb
|
|
27
|
-
#
|
|
28
|
-
# Install the Ruby client library by running:
|
|
29
|
-
# gem install mindee
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
require 'mindee'
|
|
33
|
-
|
|
34
|
-
# Init a new client
|
|
35
|
-
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
|
|
36
|
-
|
|
37
|
-
# Load a file from disk
|
|
38
|
-
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
|
|
39
|
-
|
|
40
|
-
# Parse the file
|
|
41
|
-
result = mindee_client.parse(
|
|
42
|
-
input_source,
|
|
43
|
-
Mindee::Product::Passport::PassportV1
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
# Print a full summary of the parsed data in RST format
|
|
47
|
-
puts result.document
|
|
48
|
-
|
|
49
|
-
# Print the document-level parsed data
|
|
50
|
-
# puts result.document.inference.prediction
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**Output (RST):**
|
|
54
|
-
```rst
|
|
55
|
-
########
|
|
56
|
-
Document
|
|
57
|
-
########
|
|
58
|
-
:Mindee ID: 18e41f6c-16cd-4f8e-8cd2-00ca02a35764
|
|
59
|
-
:Filename: default_sample.jpg
|
|
60
|
-
|
|
61
|
-
Inference
|
|
62
|
-
#########
|
|
63
|
-
:Product: mindee/passport v1.0
|
|
64
|
-
:Rotation applied: Yes
|
|
65
|
-
|
|
66
|
-
Prediction
|
|
67
|
-
==========
|
|
68
|
-
:Country Code: GBR
|
|
69
|
-
:ID Number: 707797979
|
|
70
|
-
:Given Name(s): HENERT
|
|
71
|
-
:Surname: PUDARSAN
|
|
72
|
-
:Date of Birth: 1995-05-20
|
|
73
|
-
:Place of Birth: CAMTETH
|
|
74
|
-
:Gender: M
|
|
75
|
-
:Date of Issue: 2012-04-22
|
|
76
|
-
:Expiry Date: 2017-04-22
|
|
77
|
-
:MRZ Line 1: P<GBRPUDARSAN<<HENERT<<<<<<<<<<<<<<<<<<<<<<<
|
|
78
|
-
:MRZ Line 2: 7077979792GBR9505209M1704224<<<<<<<<<<<<<<00
|
|
79
|
-
|
|
80
|
-
Page Predictions
|
|
81
|
-
================
|
|
82
|
-
|
|
83
|
-
Page 0
|
|
84
|
-
------
|
|
85
|
-
:Country Code: GBR
|
|
86
|
-
:ID Number: 707797979
|
|
87
|
-
:Given Name(s): HENERT
|
|
88
|
-
:Surname: PUDARSAN
|
|
89
|
-
:Date of Birth: 1995-05-20
|
|
90
|
-
:Place of Birth: CAMTETH
|
|
91
|
-
:Gender: M
|
|
92
|
-
:Date of Issue: 2012-04-22
|
|
93
|
-
:Expiry Date: 2017-04-22
|
|
94
|
-
:MRZ Line 1: P<GBRPUDARSAN<<HENERT<<<<<<<<<<<<<<<<<<<<<<<
|
|
95
|
-
:MRZ Line 2: 7077979792GBR9505209M1704224<<<<<<<<<<<<<<00
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
# Field Types
|
|
99
|
-
## Standard Fields
|
|
100
|
-
These fields are generic and used in several products.
|
|
101
|
-
|
|
102
|
-
### Basic Field
|
|
103
|
-
Each prediction object contains a set of fields that inherit from the generic `Field` class.
|
|
104
|
-
A typical `Field` object will have the following attributes:
|
|
105
|
-
|
|
106
|
-
* **value** (`String`, `Float`, `Integer`, `bool`): corresponds to the field value. Can be `nil` if no value was extracted.
|
|
107
|
-
* **confidence** (Float, nil): the confidence score of the field prediction.
|
|
108
|
-
* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
|
|
109
|
-
* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
|
|
110
|
-
* **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level.
|
|
111
|
-
* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it).
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
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.
|
|
115
|
-
|
|
116
|
-
### Date Field
|
|
117
|
-
Aside from the basic `Field` attributes, the date field `DateField` also implements the following:
|
|
118
|
-
|
|
119
|
-
* **date_object** (`Date`): an accessible representation of the value as a JavaScript object.
|
|
120
|
-
|
|
121
|
-
### String Field
|
|
122
|
-
The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`).
|
|
123
|
-
|
|
124
|
-
# Attributes
|
|
125
|
-
The following fields are extracted for Passport V1:
|
|
126
|
-
|
|
127
|
-
## Date of Birth
|
|
128
|
-
**birth_date** ([DateField](#date-field)): The date of birth of the passport holder.
|
|
129
|
-
|
|
130
|
-
```rb
|
|
131
|
-
puts result.document.inference.prediction.birth_date.value
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## Place of Birth
|
|
135
|
-
**birth_place** ([StringField](#string-field)): The place of birth of the passport holder.
|
|
136
|
-
|
|
137
|
-
```rb
|
|
138
|
-
puts result.document.inference.prediction.birth_place.value
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
## Country Code
|
|
142
|
-
**country** ([StringField](#string-field)): The country's 3 letter code (ISO 3166-1 alpha-3).
|
|
143
|
-
|
|
144
|
-
```rb
|
|
145
|
-
puts result.document.inference.prediction.country.value
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
## Expiry Date
|
|
149
|
-
**expiry_date** ([DateField](#date-field)): The expiry date of the passport.
|
|
150
|
-
|
|
151
|
-
```rb
|
|
152
|
-
puts result.document.inference.prediction.expiry_date.value
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## Gender
|
|
156
|
-
**gender** ([StringField](#string-field)): The gender of the passport holder.
|
|
157
|
-
|
|
158
|
-
```rb
|
|
159
|
-
puts result.document.inference.prediction.gender.value
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
## Given Name(s)
|
|
163
|
-
**given_names** (Array<[StringField](#string-field)>): The given name(s) of the passport holder.
|
|
164
|
-
|
|
165
|
-
```rb
|
|
166
|
-
result.document.inference.prediction.given_names do |given_names_elem|
|
|
167
|
-
puts given_names_elem.value
|
|
168
|
-
end
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## ID Number
|
|
172
|
-
**id_number** ([StringField](#string-field)): The passport's identification number.
|
|
173
|
-
|
|
174
|
-
```rb
|
|
175
|
-
puts result.document.inference.prediction.id_number.value
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## Date of Issue
|
|
179
|
-
**issuance_date** ([DateField](#date-field)): The date the passport was issued.
|
|
180
|
-
|
|
181
|
-
```rb
|
|
182
|
-
puts result.document.inference.prediction.issuance_date.value
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## MRZ Line 1
|
|
186
|
-
**mrz1** ([StringField](#string-field)): Machine Readable Zone, first line
|
|
187
|
-
|
|
188
|
-
```rb
|
|
189
|
-
puts result.document.inference.prediction.mrz1.value
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## MRZ Line 2
|
|
193
|
-
**mrz2** ([StringField](#string-field)): Machine Readable Zone, second line
|
|
194
|
-
|
|
195
|
-
```rb
|
|
196
|
-
puts result.document.inference.prediction.mrz2.value
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
## Surname
|
|
200
|
-
**surname** ([StringField](#string-field)): The surname of the passport holder.
|
|
201
|
-
|
|
202
|
-
```rb
|
|
203
|
-
puts result.document.inference.prediction.surname.value
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
# Questions?
|
|
207
|
-
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)
|