|
| 1 | +--- |
| 2 | +title: FR Bank Statement OCR Ruby |
| 3 | +category: 622b805aaec68102ea7fcbc2 |
| 4 | +slug: ruby-fr-bank-statement-ocr |
| 5 | +parentDoc: 6294d97ee723f1008d2ab28e |
| 6 | +--- |
| 7 | +The Ruby OCR SDK supports the [Bank Statement API](https://platform.mindee.com/mindee/bank_statement_fr). |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | + |
| 12 | +# Quick-Start |
| 13 | +```rb |
| 14 | +require 'mindee' |
| 15 | + |
| 16 | +# Init a new client |
| 17 | +mindee_client = Mindee::Client.new(api_key: 'my-api-key') |
| 18 | + |
| 19 | +# Load a file from disk |
| 20 | +input_source = mindee_client.source_from_path('/path/to/the/file.ext') |
| 21 | + |
| 22 | +# Parse the file |
| 23 | +result = mindee_client.enqueue_and_parse( |
| 24 | + input_source, |
| 25 | + Mindee::Product::FR::BankStatement::BankStatementV2 |
| 26 | +) |
| 27 | + |
| 28 | +# Print a full summary of the parsed data in RST format |
| 29 | +puts result.document |
| 30 | + |
| 31 | +# Print the document-level parsed data |
| 32 | +# puts result.document.inference.prediction |
| 33 | + |
| 34 | +``` |
| 35 | + |
| 36 | +**Output (RST):** |
| 37 | +```rst |
| 38 | +######## |
| 39 | +Document |
| 40 | +######## |
| 41 | +:Mindee ID: 3c1811c0-9876-45ae-91ad-c2e9cd75dd83 |
| 42 | +:Filename: default_sample.jpg |
| 43 | +
|
| 44 | +Inference |
| 45 | +######### |
| 46 | +:Product: mindee/bank_statement_fr v2.0 |
| 47 | +:Rotation applied: Yes |
| 48 | +
|
| 49 | +Prediction |
| 50 | +========== |
| 51 | +:Account Number: XXXXXXXXXXXXXX |
| 52 | +:Bank Name: Banque lafinancepourtous |
| 53 | +:Bank Address: 1 rue de la Banque, 100210 Cassette |
| 54 | +:Client Names: Karine Plume |
| 55 | +:Client Address: 1 rue des Cigales, 100210 Cassette |
| 56 | +:Statement Date: 2002-02-28 |
| 57 | +:Statement Start Date: 2002-02-01 |
| 58 | +:Statement End Date: 2002-02-28 |
| 59 | +:Opening Balance: 22.15 |
| 60 | +:Closing Balance: -278.96 |
| 61 | +:Transactions: |
| 62 | + +------------+------------+--------------------------------------+ |
| 63 | + | Amount | Date | Description | |
| 64 | + +============+============+======================================+ |
| 65 | + | 1240.00 | 2002-02-01 | Virement salaire | |
| 66 | + +------------+------------+--------------------------------------+ |
| 67 | + | -520.00 | 2002-02-02 | Virement loyer | |
| 68 | + +------------+------------+--------------------------------------+ |
| 69 | + | -312.00 | 2002-02-03 | Débit Carte nºxxxx | |
| 70 | + +------------+------------+--------------------------------------+ |
| 71 | + | 12.47 | 2002-02-04 | Virement CPAM | |
| 72 | + +------------+------------+--------------------------------------+ |
| 73 | + | 65.00 | 2002-02-05 | Virement APL | |
| 74 | + +------------+------------+--------------------------------------+ |
| 75 | + | -110.00 | 2002-02-07 | Débit Carte nxxxxxxxxxxxxxxxx | |
| 76 | + +------------+------------+--------------------------------------+ |
| 77 | + | -3.30 | 2002-02-08 | Cotisation mensuelle carte bancaire | |
| 78 | + +------------+------------+--------------------------------------+ |
| 79 | + | -120.00 | 2002-02-09 | Chèque n° xxxxxx98 | |
| 80 | + +------------+------------+--------------------------------------+ |
| 81 | + | -60.00 | 2002-02-09 | Retrait espèces DAB | |
| 82 | + +------------+------------+--------------------------------------+ |
| 83 | + | -55.00 | 2002-02-15 | Chèque n° xxxxxx99 | |
| 84 | + +------------+------------+--------------------------------------+ |
| 85 | + | -80.00 | 2002-02-16 | Prélèvement supercrédit | |
| 86 | + +------------+------------+--------------------------------------+ |
| 87 | + | -120.00 | 2002-02-17 | Chèque n° xxxxx 100 | |
| 88 | + +------------+------------+--------------------------------------+ |
| 89 | + | -163.25 | 2002-02-20 | Débit Carte nºxxxxxxxxxxxxx | |
| 90 | + +------------+------------+--------------------------------------+ |
| 91 | + | -25.50 | 2002-02-21 | Débit Carte n°xxxxxxxxxxxxxxxxxx | |
| 92 | + +------------+------------+--------------------------------------+ |
| 93 | + | -30.00 | 2002-02-24 | Prélèvement Opérateur téléphonique | |
| 94 | + +------------+------------+--------------------------------------+ |
| 95 | + | -6.53 | 2002-02-25 | Agios | |
| 96 | + +------------+------------+--------------------------------------+ |
| 97 | + | -13.00 | 2002-02-28 | Frais irrégularités et incidents ... | |
| 98 | + +------------+------------+--------------------------------------+ |
| 99 | +:Total Debits: 1618.58 |
| 100 | +:Total Credits: 1339.62 |
| 101 | +``` |
| 102 | + |
| 103 | +# Field Types |
| 104 | +## Standard Fields |
| 105 | +These fields are generic and used in several products. |
| 106 | + |
| 107 | +### Basic Field |
| 108 | +Each prediction object contains a set of fields that inherit from the generic `Field` class. |
| 109 | +A typical `Field` object will have the following attributes: |
| 110 | + |
| 111 | +* **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted. |
| 112 | +* **confidence** (Float, nil): the confidence score of the field prediction. |
| 113 | +* **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. |
| 114 | +* **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. |
| 115 | +* **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level. |
| 116 | +* **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). |
| 117 | + |
| 118 | + |
| 119 | +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. |
| 120 | + |
| 121 | + |
| 122 | +### Amount Field |
| 123 | +The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`). |
| 124 | + |
| 125 | +### Date Field |
| 126 | +Aside from the basic `Field` attributes, the date field `DateField` also implements the following: |
| 127 | + |
| 128 | +* **date_object** (`Date`): an accessible representation of the value as a JavaScript object. |
| 129 | + |
| 130 | +### String Field |
| 131 | +The text field `StringField` only has one constraint: it's **value** is a `String` (or `nil`). |
| 132 | + |
| 133 | +## Specific Fields |
| 134 | +Fields which are specific to this product; they are not used in any other product. |
| 135 | + |
| 136 | +### Transactions Field |
| 137 | +The list of values that represent the financial transactions recorded in a bank statement. |
| 138 | + |
| 139 | +A `BankStatementV2Transaction` implements the following attributes: |
| 140 | + |
| 141 | +* `amount` (Float): The monetary amount of the transaction. |
| 142 | +* `date` (String): The date on which the transaction occurred. |
| 143 | +* `description` (String): The additional information about the transaction. |
| 144 | + |
| 145 | +# Attributes |
| 146 | +The following fields are extracted for Bank Statement V2: |
| 147 | + |
| 148 | +## Account Number |
| 149 | +**account_number** ([StringField](#string-field)): The unique identifier for a customer's account in the bank's system. |
| 150 | + |
| 151 | +```rb |
| 152 | +puts result.document.inference.prediction.account_number.value |
| 153 | +``` |
| 154 | + |
| 155 | +## Bank Address |
| 156 | +**bank_address** ([StringField](#string-field)): The physical location of the bank where the statement was issued. |
| 157 | + |
| 158 | +```rb |
| 159 | +puts result.document.inference.prediction.bank_address.value |
| 160 | +``` |
| 161 | + |
| 162 | +## Bank Name |
| 163 | +**bank_name** ([StringField](#string-field)): The name of the bank that issued the statement. |
| 164 | + |
| 165 | +```rb |
| 166 | +puts result.document.inference.prediction.bank_name.value |
| 167 | +``` |
| 168 | + |
| 169 | +## Client Address |
| 170 | +**client_address** ([StringField](#string-field)): The address of the client associated with the bank statement. |
| 171 | + |
| 172 | +```rb |
| 173 | +puts result.document.inference.prediction.client_address.value |
| 174 | +``` |
| 175 | + |
| 176 | +## Client Names |
| 177 | +**client_names** (Array<[StringField](#string-field)>): The name of the clients who own the bank statement. |
| 178 | + |
| 179 | +```rb |
| 180 | +for client_names_elem in result.document.inference.prediction.client_names do |
| 181 | + puts client_names_elem.value |
| 182 | +end |
| 183 | +``` |
| 184 | + |
| 185 | +## Closing Balance |
| 186 | +**closing_balance** ([AmountField](#amount-field)): The final amount of money in the account at the end of the statement period. |
| 187 | + |
| 188 | +```rb |
| 189 | +puts result.document.inference.prediction.closing_balance.value |
| 190 | +``` |
| 191 | + |
| 192 | +## Opening Balance |
| 193 | +**opening_balance** ([AmountField](#amount-field)): The initial amount of money in an account at the start of the period. |
| 194 | + |
| 195 | +```rb |
| 196 | +puts result.document.inference.prediction.opening_balance.value |
| 197 | +``` |
| 198 | + |
| 199 | +## Statement Date |
| 200 | +**statement_date** ([DateField](#date-field)): The date on which the bank statement was generated. |
| 201 | + |
| 202 | +```rb |
| 203 | +puts result.document.inference.prediction.statement_date.value |
| 204 | +``` |
| 205 | + |
| 206 | +## Statement End Date |
| 207 | +**statement_end_date** ([DateField](#date-field)): The date when the statement period ends. |
| 208 | + |
| 209 | +```rb |
| 210 | +puts result.document.inference.prediction.statement_end_date.value |
| 211 | +``` |
| 212 | + |
| 213 | +## Statement Start Date |
| 214 | +**statement_start_date** ([DateField](#date-field)): The date when the bank statement period begins. |
| 215 | + |
| 216 | +```rb |
| 217 | +puts result.document.inference.prediction.statement_start_date.value |
| 218 | +``` |
| 219 | + |
| 220 | +## Total Credits |
| 221 | +**total_credits** ([AmountField](#amount-field)): The total amount of money deposited into the account. |
| 222 | + |
| 223 | +```rb |
| 224 | +puts result.document.inference.prediction.total_credits.value |
| 225 | +``` |
| 226 | + |
| 227 | +## Total Debits |
| 228 | +**total_debits** ([AmountField](#amount-field)): The total amount of money debited from the account. |
| 229 | + |
| 230 | +```rb |
| 231 | +puts result.document.inference.prediction.total_debits.value |
| 232 | +``` |
| 233 | + |
| 234 | +## Transactions |
| 235 | +**transactions** (Array<[BankStatementV2Transaction](#transactions-field)>): The list of values that represent the financial transactions recorded in a bank statement. |
| 236 | + |
| 237 | +```rb |
| 238 | +for transactions_elem in result.document.inference.prediction.transactions do |
| 239 | + puts transactions_elem.value |
| 240 | +end |
| 241 | +``` |
| 242 | + |
| 243 | +# Questions? |
| 244 | +[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) |
0 commit comments