mindee 3.5.0 → 3.7.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.
- package/CHANGELOG.md +63 -39
- package/package.json +3 -3
- package/src/api/{response.d.ts → documentResponse.d.ts} +2 -2
- package/src/api/endpoint.d.ts +32 -5
- package/src/api/endpoint.js +104 -34
- package/src/api/index.d.ts +3 -2
- package/src/api/index.js +5 -3
- package/src/api/predictResponse.d.ts +33 -0
- package/src/api/predictResponse.js +52 -0
- package/src/cli.js +210 -50
- package/src/client.d.ts +20 -4
- package/src/client.js +75 -23
- package/src/documents/custom/fields.js +1 -1
- package/src/documents/custom/lineitems.d.ts +41 -0
- package/src/documents/custom/lineitems.js +127 -0
- package/src/documents/document.d.ts +1 -1
- package/src/documents/documentConfig.d.ts +14 -6
- package/src/documents/documentConfig.js +59 -28
- package/src/documents/eu/licensePlate/licensePlateV1.js +4 -2
- package/src/documents/financialDocument/financialDocumentV0.d.ts +28 -0
- package/src/documents/financialDocument/financialDocumentV0.js +140 -0
- package/src/documents/financialDocument/financialDocumentV1.d.ts +44 -15
- package/src/documents/financialDocument/financialDocumentV1.js +154 -110
- package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.js +3 -2
- package/src/documents/fr/carteVitale/carteVitaleV1.js +2 -2
- package/src/documents/fr/idCard/idCardV1.js +10 -10
- package/src/documents/index.d.ts +5 -1
- package/src/documents/index.js +10 -2
- package/src/documents/invoice/invoiceV4.d.ts +3 -2
- package/src/documents/invoice/invoiceV4.js +85 -86
- package/src/documents/invoiceSplitter/invoiceSplitterV1.d.ts +3 -3
- package/src/documents/invoiceSplitter/invoiceSplitterV1.js +1 -0
- package/src/documents/mindeeVision/mindeeVisionV1.d.ts +8 -0
- package/src/documents/mindeeVision/mindeeVisionV1.js +29 -0
- package/src/documents/proofOfAddress/proofOfAddressV1.d.ts +24 -0
- package/src/documents/proofOfAddress/proofOfAddressV1.js +77 -0
- package/src/documents/receipt/receiptV3.d.ts +2 -2
- package/src/documents/receipt/receiptV3.js +1 -2
- package/src/documents/receipt/receiptV4.d.ts +3 -4
- package/src/documents/receipt/receiptV4.js +53 -65
- package/src/documents/{shipping_container → shippingContainer}/shippingContainerV1.js +2 -2
- package/src/fields/classification.d.ts +8 -0
- package/src/fields/classification.js +11 -0
- package/src/fields/field.d.ts +2 -2
- package/src/fields/field.js +1 -6
- package/src/fields/index.d.ts +1 -0
- package/src/fields/index.js +3 -1
- package/src/geometry.d.ts +18 -4
- package/src/geometry.js +40 -3
- package/src/index.d.ts +2 -2
- package/src/index.js +3 -1
- package/src/math/index.d.ts +1 -0
- package/src/math/index.js +5 -0
- package/src/math/precision.d.ts +1 -0
- package/src/math/precision.js +13 -0
- /package/src/api/{response.js → documentResponse.js} +0 -0
- /package/src/documents/{shipping_container → shippingContainer}/shippingContainerV1.d.ts +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MindeeVisionV1 = void 0;
|
|
4
|
+
const document_1 = require("../document");
|
|
5
|
+
const fields_1 = require("../../fields");
|
|
6
|
+
class MindeeVisionV1 extends document_1.Document {
|
|
7
|
+
constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
|
|
8
|
+
super({
|
|
9
|
+
inputSource: inputSource,
|
|
10
|
+
pageId: pageId,
|
|
11
|
+
orientation: orientation,
|
|
12
|
+
fullText: fullText,
|
|
13
|
+
extras: extras,
|
|
14
|
+
});
|
|
15
|
+
/** List of words found on the page. */
|
|
16
|
+
this.allWords = [];
|
|
17
|
+
if (prediction.all_words !== undefined) {
|
|
18
|
+
prediction.all_words.map((prediction) => {
|
|
19
|
+
this.allWords.push(prediction);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
toString() {
|
|
24
|
+
const fullText = new fields_1.FullText();
|
|
25
|
+
fullText.words = this.allWords;
|
|
26
|
+
return fullText.toString();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.MindeeVisionV1 = MindeeVisionV1;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
+
import { CompanyRegistration, DateField, Locale, TextField } from "../../fields";
|
|
3
|
+
export declare class ProofOfAddressV1 extends Document {
|
|
4
|
+
/** ISO date yyyy-mm-dd. Works both for European and US dates. */
|
|
5
|
+
issuanceDate: DateField;
|
|
6
|
+
/** All extrated ISO date yyyy-mm-dd. Works both for European and US dates. */
|
|
7
|
+
dates: DateField[];
|
|
8
|
+
/** Address of the document's issuer. */
|
|
9
|
+
issuerAddress: TextField;
|
|
10
|
+
/** Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific. */
|
|
11
|
+
issuerCompanyRegistration: CompanyRegistration[];
|
|
12
|
+
/** Name of the person or company issuing the document. */
|
|
13
|
+
issuerName: TextField;
|
|
14
|
+
/** ISO 639-1 code, works best with ca, de, en, es, fr, it, nl and pt. */
|
|
15
|
+
locale: Locale;
|
|
16
|
+
/** Address of supplier. */
|
|
17
|
+
recipientAddress: TextField;
|
|
18
|
+
/** Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific. */
|
|
19
|
+
recipientCompanyRegistration: CompanyRegistration[];
|
|
20
|
+
/** Name of the document's recipient. */
|
|
21
|
+
recipientName: TextField;
|
|
22
|
+
constructor({ prediction, orientation, extras, inputSource, pageId, }: DocumentConstructorProps);
|
|
23
|
+
toString(): string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProofOfAddressV1 = void 0;
|
|
4
|
+
const document_1 = require("../document");
|
|
5
|
+
const fields_1 = require("../../fields");
|
|
6
|
+
class ProofOfAddressV1 extends document_1.Document {
|
|
7
|
+
constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, pageId = undefined, }) {
|
|
8
|
+
super({
|
|
9
|
+
inputSource: inputSource,
|
|
10
|
+
pageId: pageId,
|
|
11
|
+
orientation: orientation,
|
|
12
|
+
extras: extras,
|
|
13
|
+
});
|
|
14
|
+
/** All extrated ISO date yyyy-mm-dd. Works both for European and US dates. */
|
|
15
|
+
this.dates = [];
|
|
16
|
+
/** Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific. */
|
|
17
|
+
this.issuerCompanyRegistration = [];
|
|
18
|
+
/** Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific. */
|
|
19
|
+
this.recipientCompanyRegistration = [];
|
|
20
|
+
this.locale = new fields_1.Locale({
|
|
21
|
+
prediction: prediction.locale,
|
|
22
|
+
});
|
|
23
|
+
this.issuanceDate = new fields_1.DateField({
|
|
24
|
+
prediction: prediction.date,
|
|
25
|
+
pageId: pageId,
|
|
26
|
+
});
|
|
27
|
+
prediction.dates.map((prediction) => this.dates.push(new fields_1.DateField({
|
|
28
|
+
prediction: prediction,
|
|
29
|
+
pageId: pageId,
|
|
30
|
+
})));
|
|
31
|
+
this.issuerAddress = new fields_1.TextField({
|
|
32
|
+
prediction: prediction.issuer_address,
|
|
33
|
+
pageId: pageId,
|
|
34
|
+
});
|
|
35
|
+
prediction.issuer_company_registration.map((prediction) => this.issuerCompanyRegistration.push(new fields_1.CompanyRegistration({
|
|
36
|
+
prediction: prediction,
|
|
37
|
+
pageId: pageId,
|
|
38
|
+
})));
|
|
39
|
+
this.issuerName = new fields_1.TextField({
|
|
40
|
+
prediction: prediction.issuer_name,
|
|
41
|
+
pageId: pageId,
|
|
42
|
+
});
|
|
43
|
+
prediction.recipient_company_registration.map((prediction) => this.recipientCompanyRegistration.push(new fields_1.CompanyRegistration({
|
|
44
|
+
prediction: prediction,
|
|
45
|
+
pageId: pageId,
|
|
46
|
+
})));
|
|
47
|
+
this.recipientAddress = new fields_1.TextField({
|
|
48
|
+
prediction: prediction.recipient_address,
|
|
49
|
+
pageId: pageId,
|
|
50
|
+
});
|
|
51
|
+
this.recipientName = new fields_1.TextField({
|
|
52
|
+
prediction: prediction.recipient_name,
|
|
53
|
+
pageId: pageId,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
toString() {
|
|
57
|
+
const outStr = `----- Proof of Address V1 -----
|
|
58
|
+
Filename: ${this.filename}
|
|
59
|
+
Locale: ${this.locale}
|
|
60
|
+
Issuer Name: ${this.issuerName}
|
|
61
|
+
Issuer Company Registrations: ${this.issuerCompanyRegistration
|
|
62
|
+
.map((icr) => icr.value)
|
|
63
|
+
.join(", ")}
|
|
64
|
+
Issuer Address: ${this.issuerAddress}
|
|
65
|
+
Recipient Name: ${this.recipientName}
|
|
66
|
+
Recipient Company Registrations: ${this.recipientCompanyRegistration
|
|
67
|
+
.map((rcr) => rcr.value)
|
|
68
|
+
.join(", ")}
|
|
69
|
+
Recipient Address: ${this.recipientAddress}
|
|
70
|
+
Dates: ${this.dates.map((rcr) => rcr.value).join("\n ")}
|
|
71
|
+
Date of Issue: ${this.issuanceDate}
|
|
72
|
+
----------------------
|
|
73
|
+
`;
|
|
74
|
+
return ProofOfAddressV1.cleanOutString(outStr);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.ProofOfAddressV1 = ProofOfAddressV1;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
-
import { TaxField, TextField, Amount, Locale, DateField } from "../../fields";
|
|
2
|
+
import { ClassificationField, TaxField, TextField, Amount, Locale, DateField } from "../../fields";
|
|
3
3
|
export declare class ReceiptV3 extends Document {
|
|
4
4
|
#private;
|
|
5
5
|
/** Total amount with the tax amount of the purchase. */
|
|
@@ -9,7 +9,7 @@ export declare class ReceiptV3 extends Document {
|
|
|
9
9
|
/** The purchase date. */
|
|
10
10
|
date: DateField;
|
|
11
11
|
/** The type of purchase. */
|
|
12
|
-
category:
|
|
12
|
+
category: ClassificationField;
|
|
13
13
|
/** Merchant's name as seen on the receipt. */
|
|
14
14
|
merchantName: TextField;
|
|
15
15
|
/** Time as seen on the receipt in HH:MM format. */
|
|
@@ -67,9 +67,8 @@ _ReceiptV3_instances = new WeakSet(), _ReceiptV3_initFromApiPrediction = functio
|
|
|
67
67
|
prediction: apiPrediction.date,
|
|
68
68
|
pageId: pageId,
|
|
69
69
|
});
|
|
70
|
-
this.category = new fields_1.
|
|
70
|
+
this.category = new fields_1.ClassificationField({
|
|
71
71
|
prediction: apiPrediction.category,
|
|
72
|
-
pageId: pageId,
|
|
73
72
|
});
|
|
74
73
|
this.merchantName = new fields_1.TextField({
|
|
75
74
|
prediction: apiPrediction.supplier,
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
-
import { Amount, DateField, TextField, Locale, TaxField } from "../../fields";
|
|
2
|
+
import { ClassificationField, Amount, DateField, TextField, Locale, TaxField } from "../../fields";
|
|
3
3
|
export declare class ReceiptV4 extends Document {
|
|
4
|
-
#private;
|
|
5
4
|
/** Where the purchase was made, the language, and the currency. */
|
|
6
5
|
locale: Locale;
|
|
7
6
|
/** The purchase date. */
|
|
8
7
|
date: DateField;
|
|
9
8
|
/** The receipt category among predefined classes. */
|
|
10
|
-
category:
|
|
9
|
+
category: ClassificationField;
|
|
11
10
|
/** The receipt sub-category among predefined classes. */
|
|
12
|
-
subCategory:
|
|
11
|
+
subCategory: ClassificationField;
|
|
13
12
|
/** Whether the document is an expense receipt or a credit card receipt. */
|
|
14
13
|
documentType: TextField;
|
|
15
14
|
/** The name of the supplier or merchant, as seen on the receipt. */
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _ReceiptV4_instances, _ReceiptV4_initFromApiPrediction;
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.ReceiptV4 = void 0;
|
|
10
4
|
const document_1 = require("../document");
|
|
@@ -18,10 +12,61 @@ class ReceiptV4 extends document_1.Document {
|
|
|
18
12
|
extras: extras,
|
|
19
13
|
fullText: fullText,
|
|
20
14
|
});
|
|
21
|
-
_ReceiptV4_instances.add(this);
|
|
22
15
|
/** List of taxes detected on the receipt. */
|
|
23
16
|
this.taxes = [];
|
|
24
|
-
|
|
17
|
+
this.locale = new fields_1.Locale({
|
|
18
|
+
prediction: prediction.locale,
|
|
19
|
+
});
|
|
20
|
+
this.totalTax = new fields_1.Amount({
|
|
21
|
+
prediction: prediction.total_tax,
|
|
22
|
+
valueKey: "value",
|
|
23
|
+
pageId: pageId,
|
|
24
|
+
});
|
|
25
|
+
this.totalAmount = new fields_1.Amount({
|
|
26
|
+
prediction: prediction.total_amount,
|
|
27
|
+
valueKey: "value",
|
|
28
|
+
pageId: pageId,
|
|
29
|
+
});
|
|
30
|
+
this.totalNet = new fields_1.Amount({
|
|
31
|
+
prediction: prediction.total_net,
|
|
32
|
+
valueKey: "value",
|
|
33
|
+
pageId: pageId,
|
|
34
|
+
});
|
|
35
|
+
this.tip = new fields_1.Amount({
|
|
36
|
+
prediction: prediction.tip,
|
|
37
|
+
valueKey: "value",
|
|
38
|
+
pageId: pageId,
|
|
39
|
+
});
|
|
40
|
+
this.date = new fields_1.DateField({
|
|
41
|
+
prediction: prediction.date,
|
|
42
|
+
pageId: pageId,
|
|
43
|
+
});
|
|
44
|
+
this.category = new fields_1.ClassificationField({
|
|
45
|
+
prediction: prediction.category,
|
|
46
|
+
});
|
|
47
|
+
this.subCategory = new fields_1.ClassificationField({
|
|
48
|
+
prediction: prediction.subcategory,
|
|
49
|
+
});
|
|
50
|
+
this.documentType = new fields_1.TextField({
|
|
51
|
+
prediction: prediction.document_type,
|
|
52
|
+
pageId: pageId,
|
|
53
|
+
});
|
|
54
|
+
this.supplier = new fields_1.TextField({
|
|
55
|
+
prediction: prediction.supplier,
|
|
56
|
+
pageId: pageId,
|
|
57
|
+
});
|
|
58
|
+
this.time = new fields_1.TextField({
|
|
59
|
+
prediction: prediction.time,
|
|
60
|
+
pageId: pageId,
|
|
61
|
+
});
|
|
62
|
+
prediction.taxes.map((taxPrediction) => this.taxes.push(new fields_1.TaxField({
|
|
63
|
+
prediction: taxPrediction,
|
|
64
|
+
pageId: pageId,
|
|
65
|
+
valueKey: "value",
|
|
66
|
+
rateKey: "rate",
|
|
67
|
+
codeKey: "code",
|
|
68
|
+
baseKey: "base",
|
|
69
|
+
})));
|
|
25
70
|
}
|
|
26
71
|
toString() {
|
|
27
72
|
const taxes = this.taxes.map((item) => item.toString()).join("\n ");
|
|
@@ -45,60 +90,3 @@ Locale: ${this.locale}
|
|
|
45
90
|
}
|
|
46
91
|
}
|
|
47
92
|
exports.ReceiptV4 = ReceiptV4;
|
|
48
|
-
_ReceiptV4_instances = new WeakSet(), _ReceiptV4_initFromApiPrediction = function _ReceiptV4_initFromApiPrediction(apiPrediction, pageId) {
|
|
49
|
-
this.locale = new fields_1.Locale({
|
|
50
|
-
prediction: apiPrediction.locale,
|
|
51
|
-
});
|
|
52
|
-
this.totalTax = new fields_1.Amount({
|
|
53
|
-
prediction: apiPrediction.total_tax,
|
|
54
|
-
valueKey: "value",
|
|
55
|
-
pageId: pageId,
|
|
56
|
-
});
|
|
57
|
-
this.totalAmount = new fields_1.Amount({
|
|
58
|
-
prediction: apiPrediction.total_amount,
|
|
59
|
-
valueKey: "value",
|
|
60
|
-
pageId: pageId,
|
|
61
|
-
});
|
|
62
|
-
this.totalNet = new fields_1.Amount({
|
|
63
|
-
prediction: apiPrediction.total_net,
|
|
64
|
-
valueKey: "value",
|
|
65
|
-
pageId: pageId,
|
|
66
|
-
});
|
|
67
|
-
this.tip = new fields_1.Amount({
|
|
68
|
-
prediction: apiPrediction.tip,
|
|
69
|
-
valueKey: "value",
|
|
70
|
-
pageId: pageId,
|
|
71
|
-
});
|
|
72
|
-
this.date = new fields_1.DateField({
|
|
73
|
-
prediction: apiPrediction.date,
|
|
74
|
-
pageId: pageId,
|
|
75
|
-
});
|
|
76
|
-
this.category = new fields_1.TextField({
|
|
77
|
-
prediction: apiPrediction.category,
|
|
78
|
-
pageId: pageId,
|
|
79
|
-
});
|
|
80
|
-
this.subCategory = new fields_1.TextField({
|
|
81
|
-
prediction: apiPrediction.subcategory,
|
|
82
|
-
pageId: pageId,
|
|
83
|
-
});
|
|
84
|
-
this.documentType = new fields_1.TextField({
|
|
85
|
-
prediction: apiPrediction.document_type,
|
|
86
|
-
pageId: pageId,
|
|
87
|
-
});
|
|
88
|
-
this.supplier = new fields_1.TextField({
|
|
89
|
-
prediction: apiPrediction.supplier,
|
|
90
|
-
pageId: pageId,
|
|
91
|
-
});
|
|
92
|
-
this.time = new fields_1.TextField({
|
|
93
|
-
prediction: apiPrediction.time,
|
|
94
|
-
pageId: pageId,
|
|
95
|
-
});
|
|
96
|
-
apiPrediction.taxes.map((taxPrediction) => this.taxes.push(new fields_1.TaxField({
|
|
97
|
-
prediction: taxPrediction,
|
|
98
|
-
pageId: pageId,
|
|
99
|
-
valueKey: "value",
|
|
100
|
-
rateKey: "rate",
|
|
101
|
-
codeKey: "code",
|
|
102
|
-
baseKey: "base",
|
|
103
|
-
})));
|
|
104
|
-
};
|
|
@@ -28,8 +28,8 @@ class ShippingContainerV1 extends document_1.Document {
|
|
|
28
28
|
const outStr = `----- Shipping Container V1 -----
|
|
29
29
|
Filename: ${this.filename}
|
|
30
30
|
Owner: ${this.owner}
|
|
31
|
-
Serial
|
|
32
|
-
Size and
|
|
31
|
+
Serial Number: ${this.serialNumber}
|
|
32
|
+
Size and Type: ${this.sizeType}
|
|
33
33
|
----------------------
|
|
34
34
|
`;
|
|
35
35
|
return ShippingContainerV1.cleanOutString(outStr);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseField, BaseFieldConstructor } from "./base";
|
|
2
|
+
export declare class ClassificationField extends BaseField {
|
|
3
|
+
/** The confidence score of the prediction. */
|
|
4
|
+
confidence: number;
|
|
5
|
+
/** The classification. */
|
|
6
|
+
value?: string;
|
|
7
|
+
constructor({ prediction, valueKey, reconstructed, }: BaseFieldConstructor);
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClassificationField = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
class ClassificationField extends base_1.BaseField {
|
|
6
|
+
constructor({ prediction, valueKey = "value", reconstructed = false, }) {
|
|
7
|
+
super({ prediction, valueKey, reconstructed });
|
|
8
|
+
this.confidence = prediction.confidence ? prediction.confidence : 0.0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ClassificationField = ClassificationField;
|
package/src/fields/field.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StringDict, BaseField } from "./base";
|
|
2
|
-
import { Polygon } from "../geometry";
|
|
2
|
+
import { Polygon, BoundingBox } from "../geometry";
|
|
3
3
|
export interface FieldConstructor {
|
|
4
4
|
prediction: StringDict;
|
|
5
5
|
valueKey?: string;
|
|
@@ -11,7 +11,7 @@ export declare class Field extends BaseField {
|
|
|
11
11
|
* Contains exactly 4 relative vertices coordinates (points) of a right
|
|
12
12
|
* rectangle containing the field in the document.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
boundingBox: BoundingBox;
|
|
15
15
|
/**
|
|
16
16
|
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
17
17
|
* the field in the document.
|
package/src/fields/field.js
CHANGED
|
@@ -13,11 +13,6 @@ class Field extends base_1.BaseField {
|
|
|
13
13
|
*/
|
|
14
14
|
constructor({ prediction, valueKey = "value", reconstructed = false, pageId, }) {
|
|
15
15
|
super({ prediction, valueKey, reconstructed });
|
|
16
|
-
/**
|
|
17
|
-
* Contains exactly 4 relative vertices coordinates (points) of a right
|
|
18
|
-
* rectangle containing the field in the document.
|
|
19
|
-
*/
|
|
20
|
-
this.bbox = [];
|
|
21
16
|
/**
|
|
22
17
|
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
23
18
|
* the field in the document.
|
|
@@ -27,8 +22,8 @@ class Field extends base_1.BaseField {
|
|
|
27
22
|
this.confidence = prediction.confidence ? prediction.confidence : 0.0;
|
|
28
23
|
if (prediction.polygon) {
|
|
29
24
|
this.polygon = prediction.polygon;
|
|
30
|
-
this.bbox = (0, geometry_1.getBboxAsPolygon)(prediction.polygon);
|
|
31
25
|
}
|
|
26
|
+
this.boundingBox = (0, geometry_1.getBoundingBox)(this.polygon);
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
29
|
@param {Field[]} array1 - first Array of Fields
|
package/src/fields/index.d.ts
CHANGED
package/src/fields/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TextField = exports.PositionField = exports.CompanyRegistration = exports.FullText = exports.BaseField = exports.DateField = exports.Amount = exports.Locale = exports.OrientationField = exports.PaymentDetails = exports.TaxField = void 0;
|
|
3
|
+
exports.TextField = exports.PositionField = exports.CompanyRegistration = exports.FullText = exports.BaseField = exports.DateField = exports.Amount = exports.Locale = exports.OrientationField = exports.PaymentDetails = exports.TaxField = exports.ClassificationField = void 0;
|
|
4
|
+
var classification_1 = require("./classification");
|
|
5
|
+
Object.defineProperty(exports, "ClassificationField", { enumerable: true, get: function () { return classification_1.ClassificationField; } });
|
|
4
6
|
var tax_1 = require("./tax");
|
|
5
7
|
Object.defineProperty(exports, "TaxField", { enumerable: true, get: function () { return tax_1.TaxField; } });
|
|
6
8
|
var paymentDetails_1 = require("./paymentDetails");
|
package/src/geometry.d.ts
CHANGED
|
@@ -4,18 +4,32 @@ export type MinMax = {
|
|
|
4
4
|
};
|
|
5
5
|
/** A point on the document defined by 2 coordinates: X, Y */
|
|
6
6
|
export type Point = [number, number];
|
|
7
|
-
/** A bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
|
|
8
|
-
export type
|
|
7
|
+
/** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
|
|
8
|
+
export type BBox = [number, number, number, number];
|
|
9
|
+
/** A bounding box defined by 4 points. */
|
|
10
|
+
export type BoundingBox = [Point, Point, Point, Point];
|
|
9
11
|
/** A polygon, composed of several Points. */
|
|
10
12
|
export type Polygon = Array<Point>;
|
|
11
13
|
/**
|
|
12
14
|
* Given a Polygon, calculate a polygon that encompasses all points.
|
|
13
15
|
*/
|
|
14
|
-
export declare function
|
|
16
|
+
export declare function getBoundingBox(polygon: Polygon): BoundingBox;
|
|
17
|
+
/**
|
|
18
|
+
* Given a BBox, generate the associated bounding box.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getBoundingBoxFromBBox(bbox: BBox): BoundingBox;
|
|
21
|
+
/**
|
|
22
|
+
* Given 2 bbox, merge them.
|
|
23
|
+
*/
|
|
24
|
+
export declare function mergeBbox(bbox1: BBox, bbox2: BBox): BBox;
|
|
15
25
|
/**
|
|
16
26
|
* Given a Polygon, calculate a bounding box that encompasses all points.
|
|
17
27
|
*/
|
|
18
|
-
export declare function getBbox(polygon: Polygon):
|
|
28
|
+
export declare function getBbox(polygon: Polygon): BBox;
|
|
29
|
+
/**
|
|
30
|
+
* Given polygons, calculate a bounding box that encompasses all points.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getBBoxForPolygons(polygons: Polygon[]): BBox;
|
|
19
33
|
/**
|
|
20
34
|
* Get the central point (centroid) given a list of points.
|
|
21
35
|
*/
|
package/src/geometry.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.relativeX = exports.isPointInPolygonX = exports.getMinMaxX = exports.isPointInX = exports.relativeY = exports.isPointInPolygonY = exports.getMinMaxY = exports.isPointInY = exports.getCentroid = exports.getBbox = exports.
|
|
3
|
+
exports.relativeX = exports.isPointInPolygonX = exports.getMinMaxX = exports.isPointInX = exports.relativeY = exports.isPointInPolygonY = exports.getMinMaxY = exports.isPointInY = exports.getCentroid = exports.getBBoxForPolygons = exports.getBbox = exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Given a Polygon, calculate a polygon that encompasses all points.
|
|
6
6
|
*/
|
|
7
|
-
function
|
|
7
|
+
function getBoundingBox(polygon) {
|
|
8
8
|
const bbox = getBbox(polygon);
|
|
9
9
|
return [
|
|
10
10
|
[bbox[0], bbox[1]],
|
|
@@ -13,7 +13,31 @@ function getBboxAsPolygon(polygon) {
|
|
|
13
13
|
[bbox[0], bbox[3]],
|
|
14
14
|
];
|
|
15
15
|
}
|
|
16
|
-
exports.
|
|
16
|
+
exports.getBoundingBox = getBoundingBox;
|
|
17
|
+
/**
|
|
18
|
+
* Given a BBox, generate the associated bounding box.
|
|
19
|
+
*/
|
|
20
|
+
function getBoundingBoxFromBBox(bbox) {
|
|
21
|
+
return [
|
|
22
|
+
[bbox[0], bbox[1]],
|
|
23
|
+
[bbox[2], bbox[1]],
|
|
24
|
+
[bbox[2], bbox[3]],
|
|
25
|
+
[bbox[0], bbox[3]],
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
exports.getBoundingBoxFromBBox = getBoundingBoxFromBBox;
|
|
29
|
+
/**
|
|
30
|
+
* Given 2 bbox, merge them.
|
|
31
|
+
*/
|
|
32
|
+
function mergeBbox(bbox1, bbox2) {
|
|
33
|
+
return [
|
|
34
|
+
Math.min(bbox1[0], bbox2[0]),
|
|
35
|
+
Math.min(bbox1[1], bbox2[1]),
|
|
36
|
+
Math.max(bbox1[2], bbox2[2]),
|
|
37
|
+
Math.max(bbox1[3], bbox2[3]),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
exports.mergeBbox = mergeBbox;
|
|
17
41
|
/**
|
|
18
42
|
* Given a Polygon, calculate a bounding box that encompasses all points.
|
|
19
43
|
*/
|
|
@@ -27,6 +51,19 @@ function getBbox(polygon) {
|
|
|
27
51
|
return [xMin, yMin, xMax, yMax];
|
|
28
52
|
}
|
|
29
53
|
exports.getBbox = getBbox;
|
|
54
|
+
/**
|
|
55
|
+
* Given polygons, calculate a bounding box that encompasses all points.
|
|
56
|
+
*/
|
|
57
|
+
function getBBoxForPolygons(polygons) {
|
|
58
|
+
const allY = polygons.flatMap((polygon) => polygon.map((point) => point[1]));
|
|
59
|
+
const allX = polygons.flatMap((polygon) => polygon.map((point) => point[0]));
|
|
60
|
+
const yMin = Math.min(...allY);
|
|
61
|
+
const yMax = Math.max(...allY);
|
|
62
|
+
const xMin = Math.min(...allX);
|
|
63
|
+
const xMax = Math.max(...allX);
|
|
64
|
+
return [xMin, yMin, xMax, yMax];
|
|
65
|
+
}
|
|
66
|
+
exports.getBBoxForPolygons = getBBoxForPolygons;
|
|
30
67
|
/**
|
|
31
68
|
* Get the central point (centroid) given a list of points.
|
|
32
69
|
*/
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CustomV1, Document, FinancialDocumentV1, InvoiceV3, InvoiceV4, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
|
|
1
|
+
export { CustomV1, Document, FinancialDocumentV0, FinancialDocumentV1, InvoiceV3, InvoiceV4, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
|
|
2
2
|
export { Client, ClientOptions, CustomConfigParams, PredictOptions, } from "./client";
|
|
3
|
-
export { ResponseSig, Response } from "./api";
|
|
3
|
+
export { ResponseSig, Response, AsyncPredictResponse } from "./api";
|
|
4
4
|
export { InputSource, PageOptionsOperation } from "./inputs";
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PageOptionsOperation = exports.InputSource = exports.Response = exports.Client = exports.eu = exports.us = exports.fr = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.Document = exports.CustomV1 = void 0;
|
|
3
|
+
exports.PageOptionsOperation = exports.InputSource = exports.AsyncPredictResponse = exports.Response = exports.Client = exports.eu = exports.us = exports.fr = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.FinancialDocumentV0 = exports.Document = exports.CustomV1 = void 0;
|
|
4
4
|
var documents_1 = require("./documents");
|
|
5
5
|
Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return documents_1.CustomV1; } });
|
|
6
6
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return documents_1.Document; } });
|
|
7
|
+
Object.defineProperty(exports, "FinancialDocumentV0", { enumerable: true, get: function () { return documents_1.FinancialDocumentV0; } });
|
|
7
8
|
Object.defineProperty(exports, "FinancialDocumentV1", { enumerable: true, get: function () { return documents_1.FinancialDocumentV1; } });
|
|
8
9
|
Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return documents_1.InvoiceV3; } });
|
|
9
10
|
Object.defineProperty(exports, "InvoiceV4", { enumerable: true, get: function () { return documents_1.InvoiceV4; } });
|
|
@@ -19,6 +20,7 @@ var client_1 = require("./client");
|
|
|
19
20
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
20
21
|
var api_1 = require("./api");
|
|
21
22
|
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return api_1.Response; } });
|
|
23
|
+
Object.defineProperty(exports, "AsyncPredictResponse", { enumerable: true, get: function () { return api_1.AsyncPredictResponse; } });
|
|
22
24
|
var inputs_1 = require("./inputs");
|
|
23
25
|
Object.defineProperty(exports, "InputSource", { enumerable: true, get: function () { return inputs_1.InputSource; } });
|
|
24
26
|
Object.defineProperty(exports, "PageOptionsOperation", { enumerable: true, get: function () { return inputs_1.PageOptionsOperation; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { equals as precisionEquals } from "./precision";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.precisionEquals = void 0;
|
|
4
|
+
var precision_1 = require("./precision");
|
|
5
|
+
Object.defineProperty(exports, "precisionEquals", { enumerable: true, get: function () { return precision_1.equals; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function equals(a: number, b: number, tolerance: number): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.equals = void 0;
|
|
4
|
+
function equals(a, b, tolerance) {
|
|
5
|
+
if (Math.abs(b - a) <= tolerance) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
if (Math.abs(a - b) <= tolerance) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
exports.equals = equals;
|
|
File without changes
|
|
File without changes
|