Skip to content

Commit 18ba2f6

Browse files
✨ add support for fr bank statement (#81)
1 parent 38f1ad5 commit 18ba2f6

13 files changed

Lines changed: 508 additions & 3 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ customize the experience.
143143
* [Receipt OCR Ruby](https://developers.mindee.com/docs/receipt-ocr-ruby)
144144
* [EU License Plate OCR Ruby](https://developers.mindee.com/docs/eu-license-plate-ocr-ruby)
145145
* [FR Bank Account Details OCR Ruby](https://developers.mindee.com/docs/fr-bank-account-details-ocr-ruby)
146+
* [FR Bank Statement OCR Ruby](https://developers.mindee.com/docs/fr-bank-statement-ocr-ruby)
146147
* [FR Carte Vitale OCR Ruby](https://developers.mindee.com/docs/fr-carte-vitale-ocr-ruby)
147148
* [FR ID Card OCR Ruby](https://developers.mindee.com/docs/fr-id-card-ocr-ruby)
148149
* [US Bank Check OCR Ruby](https://developers.mindee.com/docs/us-bank-check-ocr-ruby)

bin/mindee.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
sync: true,
6868
async: false,
6969
},
70+
"fr-bank-statement" => {
71+
description: "FR Bank Statement",
72+
doc_class: Mindee::Product::FR::BankStatement::BankStatementV1,
73+
sync: false,
74+
async: true,
75+
},
7076
"fr-carte-vitale" => {
7177
description: "FR Carte Vitale",
7278
doc_class: Mindee::Product::FR::CarteVitale::CarteVitaleV1,

docs/bank_statement_fr_v1.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
title: FR Bank Statement (FR) OCR Ruby
3+
---
4+
The Ruby OCR SDK supports the [Bank Statement (FR) API](https://platform.mindee.com/mindee/bank_statement_fr).
5+
6+
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
7+
![Bank Statement (FR) sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_statement_fr/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.enqueue_and_parse(
21+
input_source,
22+
Mindee::Product::FR::BankStatement::BankStatementV1
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+
36+
# Field Types
37+
## Standard Fields
38+
These fields are generic and used in several products.
39+
40+
### Basic Field
41+
Each prediction object contains a set of fields that inherit from the generic `Field` class.
42+
A typical `Field` object will have the following attributes:
43+
44+
* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
45+
* **confidence** (Float, nil): the confidence score of the field prediction.
46+
* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
47+
* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
48+
* **page_id** (`Integer`, `nil`): the ID of the page, is `nil` when at document-level.
49+
* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
50+
51+
52+
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.
53+
54+
55+
### Amount Field
56+
The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`).
57+
58+
### Date Field
59+
Aside from the basic `Field` attributes, the date field `DateField` also implements the following:
60+
61+
* **date_object** (`Date`): an accessible representation of the value as a JavaScript object.
62+
63+
### String Field
64+
The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`).
65+
66+
## Specific Fields
67+
Fields which are specific to this product; they are not used in any other product.
68+
69+
### Transactions Field
70+
The list of values that represent the financial transactions recorded in a bank statement.
71+
72+
A `BankStatementV1Transaction` implements the following attributes:
73+
74+
* `amount` (Float): The monetary amount of the transaction.
75+
* `date` (String): The date on which the transaction occurred.
76+
* `description` (String): The additional information about the transaction.
77+
78+
# Attributes
79+
The following fields are extracted for Bank Statement (FR) V1:
80+
81+
## Account Number
82+
**account_number** ([StringField](#string-field)): The unique identifier for a customer's account in the bank's system.
83+
84+
```rb
85+
puts result.document.inference.prediction.account_number.value
86+
```
87+
88+
## Bank Address
89+
**bank_address** ([StringField](#string-field)): The physical location of the bank where the statement was issued.
90+
91+
```rb
92+
puts result.document.inference.prediction.bank_address.value
93+
```
94+
95+
## Bank Name
96+
**bank_name** ([StringField](#string-field)): The name of the bank that issued the statement.
97+
98+
```rb
99+
puts result.document.inference.prediction.bank_name.value
100+
```
101+
102+
## Client Address
103+
**client_address** ([StringField](#string-field)): The address of the client associated with the bank statement.
104+
105+
```rb
106+
puts result.document.inference.prediction.client_address.value
107+
```
108+
109+
## Client Name
110+
**client_name** ([StringField](#string-field)): The name of the client who owns the bank statement.
111+
112+
```rb
113+
puts result.document.inference.prediction.client_name.value
114+
```
115+
116+
## Closing Balance
117+
**closing_balance** ([AmountField](#amount-field)): The final amount of money in the account at the end of the statement period.
118+
119+
```rb
120+
puts result.document.inference.prediction.closing_balance.value
121+
```
122+
123+
## Opening Balance
124+
**opening_balance** ([AmountField](#amount-field)): The initial amount of money in an account at the start of the period.
125+
126+
```rb
127+
puts result.document.inference.prediction.opening_balance.value
128+
```
129+
130+
## Statement Date
131+
**statement_date** ([DateField](#date-field)): The date on which the bank statement was generated.
132+
133+
```rb
134+
puts result.document.inference.prediction.statement_date.value
135+
```
136+
137+
## Statement End Date
138+
**statement_end_date** ([DateField](#date-field)): The date when the statement period ends.
139+
140+
```rb
141+
puts result.document.inference.prediction.statement_end_date.value
142+
```
143+
144+
## Statement Start Date
145+
**statement_start_date** ([DateField](#date-field)): The date when the bank statement period begins.
146+
147+
```rb
148+
puts result.document.inference.prediction.statement_start_date.value
149+
```
150+
151+
## Total Credits
152+
**total_credits** ([AmountField](#amount-field)): The total amount of money deposited into the account.
153+
154+
```rb
155+
puts result.document.inference.prediction.total_credits.value
156+
```
157+
158+
## Total Debits
159+
**total_debits** ([AmountField](#amount-field)): The total amount of money debited from the account.
160+
161+
```rb
162+
puts result.document.inference.prediction.total_debits.value
163+
```
164+
165+
## Transactions
166+
**transactions** (Array<[BankStatementV1Transaction](#transactions-field)>): The list of values that represent the financial transactions recorded in a bank statement.
167+
168+
```rb
169+
for transactions_elem in result.document.inference.prediction.transactions do
170+
puts transactions_elem.value
171+
end
172+
```
173+
174+
# Questions?
175+
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.enqueue_and_parse(
11+
input_source,
12+
Mindee::Product::FR::BankStatement::BankStatementV1
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

lib/mindee/parsing/common/inference.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def to_s
3636
out_str << "\n#{@prediction.to_s.size.positive? ? "#{@prediction}\n" : ''}"
3737
out_str << "\nPage Predictions\n================\n\n" unless @pages.empty?
3838
out_str << @pages.map(&:to_s).join("\n\n")
39+
out_str.rstrip!
40+
out_str
3941
end
4042
end
4143
end

lib/mindee/product.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
require_relative 'product/eu/license_plate/license_plate_v1'
1414
require_relative 'product/fr/bank_account_details/bank_account_details_v1'
1515
require_relative 'product/fr/bank_account_details/bank_account_details_v2'
16+
require_relative 'product/fr/bank_statement/bank_statement_v1'
1617
require_relative 'product/fr/carte_vitale/carte_vitale_v1'
1718
require_relative 'product/fr/id_card/id_card_v1'
1819
require_relative 'product/fr/id_card/id_card_v2'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../parsing'
4+
require_relative 'bank_statement_v1_document'
5+
require_relative 'bank_statement_v1_page'
6+
7+
module Mindee
8+
module Product
9+
module FR
10+
# Bank Statement (FR) module.
11+
module BankStatement
12+
# Bank Statement (FR) V1 prediction inference.
13+
class BankStatementV1 < Mindee::Parsing::Common::Inference
14+
@endpoint_name = 'bank_statement_fr'
15+
@endpoint_version = '1'
16+
17+
# @param prediction [Hash]
18+
def initialize(prediction)
19+
super
20+
@prediction = BankStatementV1Document.new(prediction['prediction'], nil)
21+
@pages = []
22+
prediction['pages'].each do |page|
23+
if page.key?('prediction') && !page['prediction'].nil? && !page['prediction'].empty?
24+
@pages.push(BankStatementV1Page.new(page))
25+
end
26+
end
27+
end
28+
29+
class << self
30+
# Name of the endpoint for this product.
31+
# @return [String]
32+
attr_reader :endpoint_name
33+
# Version for this product.
34+
# @return [String]
35+
attr_reader :endpoint_version
36+
end
37+
end
38+
end
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)