Skip to content

Commit

Permalink
💥 allow page objects to be created even if they don't have an associa…
Browse files Browse the repository at this point in the history
…ted prediction
  • Loading branch information
sebastianMindee committed Jan 29, 2025
1 parent dd1645b commit e11d64b
Show file tree
Hide file tree
Showing 93 changed files with 359 additions and 267 deletions.
33 changes: 32 additions & 1 deletion docs/driver_license_v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parentDoc: 6294d97ee723f1008d2ab28e
---
The Ruby OCR SDK supports the [Driver License API](https://platform.mindee.com/mindee/driver_license).

The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg) can be used for testing purposes.
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
![Driver License sample](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg?raw=true)

# Quick-Start
Expand All @@ -32,6 +32,37 @@ puts result.document
# puts result.document.inference.prediction

```

**Output (RST):**
```rst
########
Document
########
:Mindee ID: fbdeae38-ada3-43ac-aa58-e01a3d47e474
:Filename: default_sample.jpg
Inference
#########
:Product: mindee/driver_license v1.0
:Rotation applied: Yes
Prediction
==========
:Country Code: USA
:State: AZ
:ID: D12345678
:Category: D
:Last Name: Sample
:First Name: Jelani
:Date of Birth: 1957-02-01
:Place of Birth:
:Expiry Date: 2018-02-01
:Issued Date: 2013-01-10
:Issuing Authority:
:MRZ:
:DD Number: DD1234567890123456
```

# Field Types
## Standard Fields
These fields are generic and used in several products.
Expand Down
10 changes: 5 additions & 5 deletions docs/financial_document_v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ puts result.document
########
Document
########
:Mindee ID: b26161ce-35d0-4984-b1ff-886645e160e6
:Mindee ID: f469a24d-3875-4a83-ad43-e0d5aa9da604
:Filename: default_sample.jpg
Inference
Expand All @@ -80,8 +80,8 @@ Prediction
:Document Number: INT-001
:Reference Numbers: 2412/2019
:Purchase Date: 2019-11-02
:Due Date: 2019-02-26
:Payment Date: 2019-02-26
:Due Date: 2019-11-17
:Payment Date: 2019-11-17
:Total Net: 195.00
:Total Amount: 204.75
:Taxes:
Expand Down Expand Up @@ -132,8 +132,8 @@ Page 0
:Document Number: INT-001
:Reference Numbers: 2412/2019
:Purchase Date: 2019-11-02
:Due Date: 2019-02-26
:Payment Date: 2019-02-26
:Due Date: 2019-11-17
:Payment Date: 2019-11-17
:Total Net: 195.00
:Total Amount: 204.75
:Taxes:
Expand Down
10 changes: 5 additions & 5 deletions docs/invoices_v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ puts result.document
########
Document
########
:Mindee ID: a67b70ea-4b1e-4eac-ae75-dda47a7064ae
:Mindee ID: 86b1833f-138b-4a01-8387-860204b0e631
:Filename: default_sample.jpg
Inference
Expand All @@ -78,8 +78,8 @@ Prediction
:Purchase Order Number: AD29094
:Reference Numbers: AD29094
:Purchase Date: 2018-09-25
:Due Date: 2011-12-01
:Payment Date: 2011-12-01
:Due Date:
:Payment Date:
:Total Net: 2145.00
:Total Amount: 2608.20
:Total Tax: 193.20
Expand Down Expand Up @@ -124,8 +124,8 @@ Page 0
:Purchase Order Number: AD29094
:Reference Numbers: AD29094
:Purchase Date: 2018-09-25
:Due Date: 2011-12-01
:Payment Date: 2011-12-01
:Due Date:
:Payment Date:
:Total Net: 2145.00
:Total Amount: 2608.20
:Total Tax: 193.20
Expand Down
6 changes: 4 additions & 2 deletions lib/mindee/parsing/common/inference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def to_s
out_str << "\n:Rotation applied: #{is_rotation_applied}"
out_str << "\n\nPrediction\n=========="
out_str << "\n#{@prediction.to_s.size.positive? ? "#{@prediction}\n" : ''}"
out_str << "\nPage Predictions\n================\n\n" unless @pages.empty?
out_str << @pages.map(&:to_s).join("\n\n")
if @pages.any? { |page| page.prediction != {} }
out_str << "\nPage Predictions\n================\n\n"
out_str << @pages.map(&:to_s).join("\n\n")
end
out_str.rstrip!
out_str
end
Expand Down
4 changes: 1 addition & 3 deletions lib/mindee/product/barcode_reader/barcode_reader_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def initialize(prediction)
@prediction = BarcodeReaderV1Document.new(prediction['prediction'], nil)
@pages = []
prediction['pages'].each do |page|
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
@pages.push(BarcodeReaderV1Page.new(page))
end
@pages.push(BarcodeReaderV1Page.new(page))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BarcodeReaderV1Document < Mindee::Parsing::Common::Prediction
# @param prediction [Hash]
# @param page_id [Integer, nil]
def initialize(prediction, page_id)
super()
super
@codes_1d = []
prediction['codes_1d'].each do |item|
@codes_1d.push(StringField.new(item, page_id))
Expand Down
12 changes: 8 additions & 4 deletions lib/mindee/product/barcode_reader/barcode_reader_v1_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ class BarcodeReaderV1Page < Mindee::Parsing::Common::Page
# @param prediction [Hash]
def initialize(prediction)
super
@prediction = BarcodeReaderV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
@prediction = if prediction['prediction'].empty?
{}
else
BarcodeReaderV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
end
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/mindee/product/bill_of_lading/bill_of_lading_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def initialize(prediction)
@prediction = BillOfLadingV1Document.new(prediction['prediction'], nil)
@pages = []
prediction['pages'].each do |page|
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
@pages.push(BillOfLadingV1Page.new(page))
end
@pages.push(BillOfLadingV1Page.new(page))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BillOfLadingV1Document < Mindee::Parsing::Common::Prediction
# @param prediction [Hash]
# @param page_id [Integer, nil]
def initialize(prediction, page_id)
super()
super
@bill_of_lading_number = StringField.new(prediction['bill_of_lading_number'], page_id)
@carrier = BillOfLadingV1Carrier.new(prediction['carrier'], page_id)
@carrier_items = []
Expand Down
12 changes: 8 additions & 4 deletions lib/mindee/product/bill_of_lading/bill_of_lading_v1_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ class BillOfLadingV1Page < Mindee::Parsing::Common::Page
# @param prediction [Hash]
def initialize(prediction)
super
@prediction = BillOfLadingV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
@prediction = if prediction['prediction'].empty?
{}
else
BillOfLadingV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
end
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/mindee/product/business_card/business_card_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def initialize(prediction)
@prediction = BusinessCardV1Document.new(prediction['prediction'], nil)
@pages = []
prediction['pages'].each do |page|
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
@pages.push(BusinessCardV1Page.new(page))
end
@pages.push(BusinessCardV1Page.new(page))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BusinessCardV1Document < Mindee::Parsing::Common::Prediction
# @param prediction [Hash]
# @param page_id [Integer, nil]
def initialize(prediction, page_id)
super()
super
@address = StringField.new(prediction['address'], page_id)
@company = StringField.new(prediction['company'], page_id)
@email = StringField.new(prediction['email'], page_id)
Expand Down
12 changes: 8 additions & 4 deletions lib/mindee/product/business_card/business_card_v1_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ class BusinessCardV1Page < Mindee::Parsing::Common::Page
# @param prediction [Hash]
def initialize(prediction)
super
@prediction = BusinessCardV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
@prediction = if prediction['prediction'].empty?
{}
else
BusinessCardV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
end
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/mindee/product/cropper/cropper_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def initialize(prediction)
@prediction = CropperV1Document.new
@pages = []
prediction['pages'].each do |page|
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
@pages.push(CropperV1Page.new(page))
end
@pages.push(CropperV1Page.new(page))
end
end

Expand Down
14 changes: 9 additions & 5 deletions lib/mindee/product/cropper/cropper_v1_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ class CropperV1Page < Mindee::Parsing::Common::Page
# @param prediction [Hash]
def initialize(prediction)
super
@prediction = CropperV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
@prediction = if prediction['prediction'].empty?
{}
else
CropperV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
end
end
end

Expand All @@ -33,7 +37,7 @@ def initialize(prediction, page_id)
prediction['cropping'].each do |item|
@cropping.push(PositionField.new(item, page_id))
end
super()
super
end

# @return [String]
Expand Down
4 changes: 1 addition & 3 deletions lib/mindee/product/delivery_note/delivery_note_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def initialize(prediction)
@prediction = DeliveryNoteV1Document.new(prediction['prediction'], nil)
@pages = []
prediction['pages'].each do |page|
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
@pages.push(DeliveryNoteV1Page.new(page))
end
@pages.push(DeliveryNoteV1Page.new(page))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DeliveryNoteV1Document < Mindee::Parsing::Common::Prediction
# @param prediction [Hash]
# @param page_id [Integer, nil]
def initialize(prediction, page_id)
super()
super
@customer_address = StringField.new(prediction['customer_address'], page_id)
@customer_name = StringField.new(prediction['customer_name'], page_id)
@delivery_date = DateField.new(prediction['delivery_date'], page_id)
Expand Down
12 changes: 8 additions & 4 deletions lib/mindee/product/delivery_note/delivery_note_v1_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ class DeliveryNoteV1Page < Mindee::Parsing::Common::Page
# @param prediction [Hash]
def initialize(prediction)
super
@prediction = DeliveryNoteV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
@prediction = if prediction['prediction'].empty?
{}
else
DeliveryNoteV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
end
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/mindee/product/driver_license/driver_license_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def initialize(prediction)
@prediction = DriverLicenseV1Document.new(prediction['prediction'], nil)
@pages = []
prediction['pages'].each do |page|
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
@pages.push(DriverLicenseV1Page.new(page))
end
@pages.push(DriverLicenseV1Page.new(page))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DriverLicenseV1Document < Mindee::Parsing::Common::Prediction
# @param prediction [Hash]
# @param page_id [Integer, nil]
def initialize(prediction, page_id)
super()
super
@category = StringField.new(prediction['category'], page_id)
@country_code = StringField.new(prediction['country_code'], page_id)
@date_of_birth = DateField.new(prediction['date_of_birth'], page_id)
Expand Down
12 changes: 8 additions & 4 deletions lib/mindee/product/driver_license/driver_license_v1_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ class DriverLicenseV1Page < Mindee::Parsing::Common::Page
# @param prediction [Hash]
def initialize(prediction)
super
@prediction = DriverLicenseV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
@prediction = if prediction['prediction'].empty?
{}
else
DriverLicenseV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
end
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/mindee/product/eu/license_plate/license_plate_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def initialize(prediction)
@prediction = LicensePlateV1Document.new(prediction['prediction'], nil)
@pages = []
prediction['pages'].each do |page|
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
@pages.push(LicensePlateV1Page.new(page))
end
@pages.push(LicensePlateV1Page.new(page))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LicensePlateV1Document < Mindee::Parsing::Common::Prediction
# @param prediction [Hash]
# @param page_id [Integer, nil]
def initialize(prediction, page_id)
super()
super
@license_plates = []
prediction['license_plates'].each do |item|
@license_plates.push(StringField.new(item, page_id))
Expand Down
12 changes: 8 additions & 4 deletions lib/mindee/product/eu/license_plate/license_plate_v1_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ class LicensePlateV1Page < Mindee::Parsing::Common::Page
# @param prediction [Hash]
def initialize(prediction)
super
@prediction = LicensePlateV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
@prediction = if prediction['prediction'].empty?
{}
else
LicensePlateV1PagePrediction.new(
prediction['prediction'],
prediction['id']
)
end
end
end

Expand Down
Loading

0 comments on commit e11d64b

Please sign in to comment.