Skip to content

Commit 84a5026

Browse files
♻️ update display & structure for invoice splitter v1 (#334)
1 parent c64c7d6 commit 84a5026

29 files changed

+169
-111
lines changed

docs/code_samples/invoice_splitter_v1_async.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
88
// Load a file from disk
99
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");
1010

11-
// Parse the file asynchronously.
12-
const asyncApiResponse = mindeeClient.enqueueAndParse(
11+
// Parse the file
12+
const apiResponse = mindeeClient.enqueueAndParse(
1313
mindee.product.InvoiceSplitterV1,
1414
inputSource
1515
);
1616

1717
// Handle the response Promise
18-
asyncApiResponse.then((resp) => {
18+
apiResponse.then((resp) => {
1919
// print a string summary
2020
console.log(resp.document.toString());
21-
});
21+
});

docs/invoice_splitter_v1.md

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ parentDoc: 609809574212d40077a040f1
66
---
77
The Node.js OCR SDK supports the [Invoice Splitter API](https://platform.mindee.com/mindee/invoice_splitter).
88

9-
Using [this sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/default_sample.pdf), we are going to illustrate how to detect the pages of multiple invoices within the same document.
9+
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/default_sample.pdf), we are going to illustrate how to extract the data that we want using the OCR SDK.
10+
![Invoice Splitter sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/default_sample.pdf?raw=true)
1011

1112
# Quick-Start
12-
> **⚠️ Important:** This API only works **asynchronously**, which means that documents have to be sent and retrieved in a specific way:
13-
1413
```js
1514
const mindee = require("mindee");
1615
// for TS or modules:
@@ -22,11 +21,14 @@ const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
2221
// Load a file from disk
2322
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");
2423

25-
// Parse the file asynchronously.
26-
const asyncApiResponse = mindeeClient.enqueueAndParse(mindee.product.InvoiceSplitterV1, inputSource);
24+
// Parse the file
25+
const apiResponse = mindeeClient.enqueueAndParse(
26+
mindee.product.InvoiceSplitterV1,
27+
inputSource
28+
);
2729

2830
// Handle the response Promise
29-
asyncApiResponse.then((resp) => {
31+
apiResponse.then((resp) => {
3032
// print a string summary
3133
console.log(resp.document.toString());
3234
});
@@ -37,51 +39,71 @@ asyncApiResponse.then((resp) => {
3739
########
3840
Document
3941
########
40-
:Mindee ID: 8c25cc63-212b-4537-9c9b-3fbd3bd0ee20
41-
:Filename: default_sample.jpg
42+
:Mindee ID: 15ad7a19-7b75-43d0-b0c6-9a641a12b49b
43+
:Filename: default_sample.pdf
4244
4345
Inference
4446
#########
45-
:Product: mindee/carte_vitale v1.0
46-
:Rotation applied: Yes
47+
:Product: mindee/invoice_splitter v1.1
48+
:Rotation applied: No
4749
4850
Prediction
4951
==========
50-
:Given Name(s): NATHALIE
51-
:Surname: DURAND
52-
:Social Security Number: 269054958815780
53-
:Issuance Date: 2007-01-01
52+
:Invoice Page Groups:
53+
:Page indexes: 0
54+
:Page indexes: 1
5455
5556
Page Predictions
5657
================
5758
5859
Page 0
5960
------
60-
:Given Name(s): NATHALIE
61-
:Surname: DURAND
62-
:Social Security Number: 269054958815780
63-
:Issuance Date: 2007-01-01
61+
:Invoice Page Groups:
62+
63+
Page 1
64+
------
65+
:Invoice Page Groups:
6466
```
6567

6668
# Field Types
69+
## Standard Fields
70+
These fields are generic and used in several products.
71+
72+
### Basic Field
73+
Each prediction object contains a set of fields that inherit from the generic `Field` class.
74+
A typical `Field` object will have the following attributes:
75+
76+
* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted.
77+
* **confidence** (`number`): the confidence score of the field prediction.
78+
* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
79+
* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
80+
* **pageId** (`number`): the ID of the page, always `undefined` when at document-level.
81+
* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
82+
83+
> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`).
84+
85+
86+
Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string.
87+
6788
## Specific Fields
68-
### Invoice Splitter V1 Page Group
69-
List of page group indexes.
89+
Fields which are specific to this product; they are not used in any other product.
90+
91+
### Invoice Page Groups Field
92+
List of page groups. Each group represents a single invoice within a multi-invoice document.
7093

71-
An `InvoiceSplitterV1PageGroup` implements the following attributes:
94+
A `InvoiceSplitterV1InvoicePageGroup` implements the following attributes:
7295

73-
* **pageIndexes** (`number`[]): List of indexes of the pages of a single invoice.
74-
* **confidence** (`number`): The confidence of the prediction.
96+
* `pageIndexes` (Array<number>): List of page indexes that belong to the same invoice (group).
7597

7698
# Attributes
7799
The following fields are extracted for Invoice Splitter V1:
78100

79101
## Invoice Page Groups
80-
**invoicePageGroups** ([InvoiceSplitterV1PageGroup](#invoice-splitter-v1-page-group)[]): List of page indexes that belong to the same invoice in the PDF.
102+
**invoicePageGroups** ([InvoiceSplitterV1InvoicePageGroup](#invoice-page-groups-field)[]): List of page groups. Each group represents a single invoice within a multi-invoice document.
81103

82104
```js
83-
for (const invoicePageGroupsElem of result.document.inference.prediction.invoicePageGroups){
84-
console.log(invoicePageGroupsElem.pageIndexes.join(", "));
105+
for (const invoicePageGroupsElem of result.document.inference.prediction.invoicePageGroups) {
106+
console.log(invoicePageGroupsElem.value);
85107
}
86108
```
87109

src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function extractInvoices(
6262
if (indexes instanceof InvoiceSplitterV1) {
6363
indexes.prediction.invoicePageGroups.map((invoicePageGroup) => {
6464
if (!strict || invoicePageGroup.confidence === 1) {
65-
customIndexes.push(invoicePageGroup.pageIndexes);
65+
customIndexes.push(invoicePageGroup.pageIndexes ?? []);
6666
}
6767
});
6868
} else {

src/product/billOfLading/billOfLadingV1Carrier.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { StringDict } from "../../parsing/common";
32
import { Polygon } from "../../geometry";
43

src/product/billOfLading/billOfLadingV1Consignee.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { StringDict } from "../../parsing/common";
32
import { Polygon } from "../../geometry";
43

src/product/billOfLading/billOfLadingV1NotifyParty.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { StringDict } from "../../parsing/common";
32
import { Polygon } from "../../geometry";
43

src/product/billOfLading/billOfLadingV1Shipper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { StringDict } from "../../parsing/common";
32
import { Polygon } from "../../geometry";
43

src/product/fr/bankAccountDetails/bankAccountDetailsV2Bban.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { StringDict } from "../../../parsing/common";
32
import { Polygon } from "../../../geometry";
43

src/product/fr/energyBill/energyBillV1EnergyConsumer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { StringDict } from "../../../parsing/common";
32
import { Polygon } from "../../../geometry";
43

src/product/fr/energyBill/energyBillV1EnergySupplier.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { StringDict } from "../../../parsing/common";
32
import { Polygon } from "../../../geometry";
43

0 commit comments

Comments
 (0)