mindee 1.0.9 → 1.1.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 +9 -0
- package/LICENSE +202 -0
- package/lib/api/financialDocument.js +2 -2
- package/lib/api/object.js +2 -2
- package/lib/api/request.js +6 -4
- package/lib/api/response.js +8 -3
- package/lib/documents/document.js +5 -1
- package/lib/documents/fields/field.js +1 -1
- package/lib/documents/financialDocument.js +36 -28
- package/lib/documents/invoice.js +49 -31
- package/lib/documents/receipt.js +40 -25
- package/mindee/api/financialDocument.js +6 -4
- package/mindee/api/object.js +2 -2
- package/mindee/api/request.js +7 -4
- package/mindee/api/response.js +8 -5
- package/mindee/documents/fields/field.js +1 -1
- package/mindee/documents/financialDocument.js +40 -16
- package/mindee/documents/invoice.js +39 -23
- package/mindee/documents/receipt.js +31 -16
- package/mindee/inputs.js +1 -0
- package/package.json +2 -2
- package/LICENSE.md +0 -674
package/lib/documents/receipt.js
CHANGED
|
@@ -57,6 +57,7 @@ class Receipt extends Document {
|
|
|
57
57
|
* @param {Object} orientation - orientation value for creating Receipt object from scratch
|
|
58
58
|
* @param {Object} totalTax - total taxes value for creating Receipt object from scratch
|
|
59
59
|
* @param {Object} totalExcl - total taxes excluded value for creating Receipt object from scratch
|
|
60
|
+
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
60
61
|
*/
|
|
61
62
|
constructor(_ref) {
|
|
62
63
|
var {
|
|
@@ -72,7 +73,8 @@ class Receipt extends Document {
|
|
|
72
73
|
orientation: _orientation = undefined,
|
|
73
74
|
totalTax: _totalTax = undefined,
|
|
74
75
|
totalExcl: _totalExcl = undefined,
|
|
75
|
-
pageNumber: _pageNumber = 0
|
|
76
|
+
pageNumber: _pageNumber = 0,
|
|
77
|
+
level = "page"
|
|
76
78
|
} = _ref;
|
|
77
79
|
super(inputFile);
|
|
78
80
|
|
|
@@ -90,6 +92,18 @@ class Receipt extends Document {
|
|
|
90
92
|
|
|
91
93
|
_initFromScratch.add(this);
|
|
92
94
|
|
|
95
|
+
this.level = level;
|
|
96
|
+
|
|
97
|
+
this.constructPrediction = function (item) {
|
|
98
|
+
return {
|
|
99
|
+
prediction: {
|
|
100
|
+
value: item
|
|
101
|
+
},
|
|
102
|
+
valueKey: "value",
|
|
103
|
+
pageNumber: _pageNumber
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
93
107
|
if (_apiPrediction === undefined) {
|
|
94
108
|
_classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, {
|
|
95
109
|
locale: _locale,
|
|
@@ -147,23 +161,12 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
|
|
|
147
161
|
totalTax,
|
|
148
162
|
pageNumber
|
|
149
163
|
} = _ref2;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
valueKey: "value",
|
|
157
|
-
pageNumber
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
this.locale = new Locale(constructPrediction(locale));
|
|
162
|
-
this.totalIncl = new Amount(constructPrediction(totalIncl));
|
|
163
|
-
this.date = new Date(constructPrediction(date));
|
|
164
|
-
this.category = new Field(constructPrediction(category));
|
|
165
|
-
this.merchantName = new Field(constructPrediction(merchantName));
|
|
166
|
-
this.time = new Field(constructPrediction(time));
|
|
164
|
+
this.locale = new Locale(this.constructPrediction(locale));
|
|
165
|
+
this.totalIncl = new Amount(this.constructPrediction(totalIncl));
|
|
166
|
+
this.date = new Date(this.constructPrediction(date));
|
|
167
|
+
this.category = new Field(this.constructPrediction(category));
|
|
168
|
+
this.merchantName = new Field(this.constructPrediction(merchantName));
|
|
169
|
+
this.time = new Field(this.constructPrediction(time));
|
|
167
170
|
|
|
168
171
|
if (taxes !== undefined) {
|
|
169
172
|
this.taxes = [];
|
|
@@ -181,9 +184,9 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
|
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
186
|
|
|
184
|
-
this.orientation = new Orientation(constructPrediction(orientation));
|
|
185
|
-
this.totalTax = new Amount(constructPrediction(totalTax));
|
|
186
|
-
this.totalExcl = new Amount(constructPrediction(totalExcl));
|
|
187
|
+
this.orientation = new Orientation(this.constructPrediction(orientation));
|
|
188
|
+
this.totalTax = new Amount(this.constructPrediction(totalTax));
|
|
189
|
+
this.totalExcl = new Amount(this.constructPrediction(totalExcl));
|
|
187
190
|
};
|
|
188
191
|
|
|
189
192
|
var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pageNumber) {
|
|
@@ -223,10 +226,6 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
|
|
|
223
226
|
rateKey: "rate",
|
|
224
227
|
codeKey: "code"
|
|
225
228
|
}));
|
|
226
|
-
this.orientation = new Orientation({
|
|
227
|
-
prediction: apiPrediction.orientation,
|
|
228
|
-
pageNumber
|
|
229
|
-
});
|
|
230
229
|
this.totalTax = new Amount({
|
|
231
230
|
prediction: {
|
|
232
231
|
value: undefined,
|
|
@@ -243,6 +242,22 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
|
|
|
243
242
|
valueKey: "value",
|
|
244
243
|
pageNumber
|
|
245
244
|
});
|
|
245
|
+
|
|
246
|
+
if (this.level === "page") {
|
|
247
|
+
this.orientation = new Orientation({
|
|
248
|
+
prediction: apiPrediction.orientation,
|
|
249
|
+
pageNumber
|
|
250
|
+
});
|
|
251
|
+
} else {
|
|
252
|
+
this.orientation = new Orientation(this.constructPrediction({
|
|
253
|
+
prediction: {
|
|
254
|
+
value: undefined,
|
|
255
|
+
probability: 0.0,
|
|
256
|
+
degrees: undefined
|
|
257
|
+
}
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
|
|
246
261
|
if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
|
|
247
262
|
};
|
|
248
263
|
|
|
@@ -30,12 +30,14 @@ class APIFinancialDocument extends APIObject {
|
|
|
30
30
|
filename: filename,
|
|
31
31
|
allowCutPdf: cutPdf,
|
|
32
32
|
});
|
|
33
|
-
this.apiToken =
|
|
34
|
-
inputFile.fileExtension === "pdf" ? this.invoiceToken : this.receiptToken;
|
|
35
33
|
await inputFile.init();
|
|
34
|
+
this.apiToken =
|
|
35
|
+
inputFile.fileExtension === "application/pdf"
|
|
36
|
+
? this.invoiceToken
|
|
37
|
+
: this.receiptToken;
|
|
36
38
|
const url =
|
|
37
|
-
inputFile.fileExtension === "pdf"
|
|
38
|
-
? "/invoices/
|
|
39
|
+
inputFile.fileExtension === "application/pdf"
|
|
40
|
+
? "/invoices/v2/predict"
|
|
39
41
|
: "/expense_receipts/v3/predict";
|
|
40
42
|
super.parse();
|
|
41
43
|
return await super._request(url, inputFile, version, includeWords);
|
package/mindee/api/object.js
CHANGED
|
@@ -10,7 +10,7 @@ const request = require("./request");
|
|
|
10
10
|
class APIObject {
|
|
11
11
|
constructor(apiToken = undefined, apiName = "") {
|
|
12
12
|
this.apiToken = apiToken;
|
|
13
|
-
this.baseUrl = "https://api.mindee.net/products";
|
|
13
|
+
this.baseUrl = "https://api.mindee.net/v1/products/mindee/";
|
|
14
14
|
this.apiName = apiName;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -54,7 +54,7 @@ class APIObject {
|
|
|
54
54
|
@returns {Response}
|
|
55
55
|
*/
|
|
56
56
|
wrapResponse(inputFile, response, documentType) {
|
|
57
|
-
if (response.statusCode
|
|
57
|
+
if (response.statusCode > 201) {
|
|
58
58
|
const errorMessage = JSON.stringify(response.data, null, 4);
|
|
59
59
|
errorHandler.throw(
|
|
60
60
|
new Error(
|
package/mindee/api/request.js
CHANGED
|
@@ -2,20 +2,23 @@ const https = require("https");
|
|
|
2
2
|
const { version: sdkVersion } = require("../../package.json");
|
|
3
3
|
const { URL } = require("url");
|
|
4
4
|
const FormData = require("form-data");
|
|
5
|
+
const os = require("os");
|
|
5
6
|
|
|
6
7
|
const request = (url, method, headers, input, includeWords = false) => {
|
|
7
8
|
return new Promise(function (resolve, reject) {
|
|
8
9
|
const form = new FormData();
|
|
9
10
|
let body;
|
|
10
|
-
headers["User-Agent"] = `mindee-node/${sdkVersion} node/${process.version}`;
|
|
11
11
|
|
|
12
|
+
headers["User-Agent"] = `mindee-api-nodejs@v${sdkVersion} nodejs-${
|
|
13
|
+
process.version
|
|
14
|
+
} ${os.type().toLowerCase()}`;
|
|
12
15
|
if (["path", "stream"].includes(input.inputType)) {
|
|
13
16
|
const fileParams = { filename: input.filename };
|
|
14
|
-
form.append("
|
|
17
|
+
form.append("document", input.fileObject, fileParams);
|
|
15
18
|
if (includeWords) form.append("include_mvision", "true");
|
|
16
19
|
headers = { ...headers, ...form.getHeaders() };
|
|
17
20
|
} else if (input.inputType === "base64") {
|
|
18
|
-
let body_obj = {
|
|
21
|
+
let body_obj = { document: input.fileObject };
|
|
19
22
|
if (includeWords) body_obj["include_mvision"] = "true";
|
|
20
23
|
body = JSON.stringify(body_obj);
|
|
21
24
|
headers["Content-Type"] = "application/json";
|
|
@@ -44,7 +47,7 @@ const request = (url, method, headers, input, includeWords = false) => {
|
|
|
44
47
|
data: JSON.parse(responseBody),
|
|
45
48
|
});
|
|
46
49
|
} catch (error) {
|
|
47
|
-
console.log(responseBody);
|
|
50
|
+
console.log(responseBody, error);
|
|
48
51
|
}
|
|
49
52
|
});
|
|
50
53
|
});
|
package/mindee/api/response.js
CHANGED
|
@@ -38,14 +38,14 @@ class Response {
|
|
|
38
38
|
invoice: (params) => new Invoice(params),
|
|
39
39
|
financialDocument: (params) => new FinancialDocument(params),
|
|
40
40
|
};
|
|
41
|
-
const predictions = this.httpResponse.data.
|
|
41
|
+
const predictions = this.httpResponse.data.document.inference.pages.entries();
|
|
42
42
|
this[`${this.documentType}s`] = [];
|
|
43
43
|
|
|
44
44
|
// Create a list of Document (Receipt, Invoice...) for each page of the input document
|
|
45
45
|
for (const [pageNumber, prediction] of predictions) {
|
|
46
46
|
this[`${this.documentType}s`].push(
|
|
47
47
|
constructors[this.documentType]({
|
|
48
|
-
apiPrediction: prediction,
|
|
48
|
+
apiPrediction: prediction.prediction,
|
|
49
49
|
inputFile: this.input,
|
|
50
50
|
pageNumber: pageNumber,
|
|
51
51
|
})
|
|
@@ -53,9 +53,12 @@ class Response {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// Merge the list of Document into a unique Document
|
|
56
|
-
this[this.documentType] =
|
|
57
|
-
this
|
|
58
|
-
|
|
56
|
+
this[this.documentType] = constructors[this.documentType]({
|
|
57
|
+
apiPrediction: this.httpResponse.data.document.inference.prediction,
|
|
58
|
+
inputFile: this.input,
|
|
59
|
+
pageNumber: -1,
|
|
60
|
+
level: "document",
|
|
61
|
+
});
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -18,7 +18,7 @@ class Field {
|
|
|
18
18
|
this.value = undefined;
|
|
19
19
|
this.probability = 0.0;
|
|
20
20
|
this.bbox = [];
|
|
21
|
-
if (valueKey in prediction && prediction[valueKey] !==
|
|
21
|
+
if (valueKey in prediction && prediction[valueKey] !== null) {
|
|
22
22
|
this.value = prediction[valueKey];
|
|
23
23
|
if (prediction.probability) this.probability = prediction.probability;
|
|
24
24
|
if (prediction.segmentation)
|
|
@@ -27,6 +27,7 @@ class FinancialDocument extends Document {
|
|
|
27
27
|
* @param {Object} totalTax - total tax value for creating FinancialDocument object from scratch
|
|
28
28
|
* @param {Object} time - time value for creating FinancialDocument object from scratch
|
|
29
29
|
* @param {Object} pageNumber - pageNumber for multi pages pdf input
|
|
30
|
+
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
30
31
|
*/
|
|
31
32
|
constructor({
|
|
32
33
|
apiPrediction = undefined,
|
|
@@ -46,8 +47,10 @@ class FinancialDocument extends Document {
|
|
|
46
47
|
totalTax = undefined,
|
|
47
48
|
time = undefined,
|
|
48
49
|
pageNumber = 0,
|
|
50
|
+
level = "page",
|
|
49
51
|
}) {
|
|
50
52
|
super(inputFile);
|
|
53
|
+
this.level = level;
|
|
51
54
|
if (apiPrediction === undefined) {
|
|
52
55
|
this.#initFromScratch({
|
|
53
56
|
locale,
|
|
@@ -57,7 +60,7 @@ class FinancialDocument extends Document {
|
|
|
57
60
|
invoiceNumber,
|
|
58
61
|
dueDate,
|
|
59
62
|
taxes,
|
|
60
|
-
|
|
63
|
+
supplier,
|
|
61
64
|
paymentDetails,
|
|
62
65
|
companyNumber,
|
|
63
66
|
vatNumber,
|
|
@@ -86,7 +89,7 @@ class FinancialDocument extends Document {
|
|
|
86
89
|
vatNumber,
|
|
87
90
|
orientation,
|
|
88
91
|
pageNumber,
|
|
89
|
-
|
|
92
|
+
supplier,
|
|
90
93
|
time,
|
|
91
94
|
}) {
|
|
92
95
|
const constructPrediction = function (item) {
|
|
@@ -98,7 +101,7 @@ class FinancialDocument extends Document {
|
|
|
98
101
|
this.totalTax = new Amount(constructPrediction(totalTax));
|
|
99
102
|
this.date = new Date(constructPrediction(date));
|
|
100
103
|
this.dueDate = new Date(constructPrediction(dueDate));
|
|
101
|
-
this.
|
|
104
|
+
this.supplier = new Field(constructPrediction(supplier));
|
|
102
105
|
this.time = new Field(constructPrediction(time));
|
|
103
106
|
this.orientation = new Orientation(constructPrediction(orientation));
|
|
104
107
|
this.invoiceNumber = new Field(constructPrediction(invoiceNumber));
|
|
@@ -122,26 +125,47 @@ class FinancialDocument extends Document {
|
|
|
122
125
|
|
|
123
126
|
#initFromApiPrediction(apiPrediction, inputFile, pageNumber) {
|
|
124
127
|
if (Object.keys(apiPrediction).includes("invoice_number")) {
|
|
125
|
-
const invoice = new Invoice({
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
const invoice = new Invoice({
|
|
129
|
+
apiPrediction,
|
|
130
|
+
inputFile,
|
|
131
|
+
pageNumber,
|
|
132
|
+
level: this.level,
|
|
129
133
|
});
|
|
130
|
-
this.
|
|
134
|
+
this.locale = invoice.locale;
|
|
135
|
+
this.totalIncl = invoice.totalIncl;
|
|
136
|
+
this.totalExcl = invoice.totalExcl;
|
|
137
|
+
this.date = invoice.invoiceDate;
|
|
138
|
+
this.invoiceNumber = invoice.invoiceNumber;
|
|
139
|
+
this.dueDate = invoice.dueDate;
|
|
140
|
+
this.taxes = invoice.taxes;
|
|
141
|
+
this.supplier = invoice.supplier;
|
|
142
|
+
this.paymentDetails = invoice.paymentDetails;
|
|
143
|
+
this.companyNumber = invoice.companyNumber;
|
|
144
|
+
this.orientation = invoice.orientation;
|
|
145
|
+
this.totalTax = invoice.totalTax;
|
|
146
|
+
this.time = new Field({
|
|
131
147
|
prediction: { value: undefined, probability: 0.0 },
|
|
132
148
|
});
|
|
133
149
|
} else {
|
|
134
|
-
const receipt = new Receipt({
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
150
|
+
const receipt = new Receipt({
|
|
151
|
+
apiPrediction,
|
|
152
|
+
inputFile,
|
|
153
|
+
pageNumber,
|
|
154
|
+
level: this.level,
|
|
138
155
|
});
|
|
156
|
+
this.orientation = receipt.orientation;
|
|
157
|
+
this.date = receipt.date;
|
|
158
|
+
this.dueDate = receipt.date;
|
|
159
|
+
this.taxes = receipt.taxes;
|
|
160
|
+
this.locale = receipt.locale;
|
|
161
|
+
this.totalIncl = receipt.totalIncl;
|
|
162
|
+
this.totalExcl = receipt.totalExcl;
|
|
163
|
+
this.supplier = receipt.merchantName;
|
|
164
|
+
this.time = receipt.time;
|
|
165
|
+
this.totalTax = receipt.totalTax;
|
|
139
166
|
this.invoiceNumber = new Field({
|
|
140
167
|
prediction: { value: undefined, probability: 0.0 },
|
|
141
168
|
});
|
|
142
|
-
this.dueDate = new Field({
|
|
143
|
-
prediction: { value: undefined, probability: 0.0 },
|
|
144
|
-
});
|
|
145
169
|
this.paymentDetails = new Field({
|
|
146
170
|
prediction: { value: undefined, probability: 0.0 },
|
|
147
171
|
});
|
|
@@ -157,7 +181,7 @@ class FinancialDocument extends Document {
|
|
|
157
181
|
Filename: ${this.filename}
|
|
158
182
|
Total amount: ${this.totalIncl.value}
|
|
159
183
|
Date: ${this.date.value}
|
|
160
|
-
|
|
184
|
+
Supplier: ${this.supplier.value}
|
|
161
185
|
Total taxes: ${this.totalTax.value}
|
|
162
186
|
`;
|
|
163
187
|
}
|
|
@@ -11,7 +11,6 @@ class Invoice extends Document {
|
|
|
11
11
|
/**
|
|
12
12
|
* @param {Object} apiPrediction - Json parsed prediction from HTTP response
|
|
13
13
|
* @param {Input} input - Input object
|
|
14
|
-
* @param {Integer} pageNumber - Page number for multi pages pdf input
|
|
15
14
|
* @param {Object} locale - locale value for creating Invoice object from scratch
|
|
16
15
|
* @param {Object} totalIncl - total tax included value for creating Invoice object from scratch
|
|
17
16
|
* @param {Object} totalExcl - total tax excluded value for creating Invoice object from scratch
|
|
@@ -24,7 +23,8 @@ class Invoice extends Document {
|
|
|
24
23
|
* @param {Object} vatNumber - vat number value for creating Invoice object from scratch
|
|
25
24
|
* @param {Object} orientation - orientation value for creating Invoice object from scratch
|
|
26
25
|
* @param {Object} totalTax - total tax value for creating Invoice object from scratch
|
|
27
|
-
* @param {
|
|
26
|
+
* @param {Number} pageNumber - pageNumber for multi pages pdf input
|
|
27
|
+
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
28
28
|
*/
|
|
29
29
|
constructor({
|
|
30
30
|
apiPrediction = undefined,
|
|
@@ -43,8 +43,13 @@ class Invoice extends Document {
|
|
|
43
43
|
orientation = undefined,
|
|
44
44
|
totalTax = undefined,
|
|
45
45
|
pageNumber = 0,
|
|
46
|
+
level = "page",
|
|
46
47
|
}) {
|
|
47
48
|
super(inputFile);
|
|
49
|
+
this.level = level;
|
|
50
|
+
this.constructPrediction = function (item) {
|
|
51
|
+
return { prediction: { value: item }, valueKey: "value", pageNumber };
|
|
52
|
+
};
|
|
48
53
|
if (apiPrediction === undefined) {
|
|
49
54
|
this.#initFromScratch({
|
|
50
55
|
locale,
|
|
@@ -85,22 +90,18 @@ class Invoice extends Document {
|
|
|
85
90
|
orientation,
|
|
86
91
|
pageNumber,
|
|
87
92
|
}) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
93
|
-
this.
|
|
94
|
-
this.
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this.invoiceNumber = new Field(constructPrediction(invoiceNumber));
|
|
101
|
-
this.paymentDetails = new Field(constructPrediction(paymentDetails));
|
|
102
|
-
this.companyNumber = new Field(constructPrediction(companyNumber));
|
|
103
|
-
this.vatNumber = new Field(constructPrediction(vatNumber));
|
|
93
|
+
this.locale = new Locale(this.constructPrediction(locale));
|
|
94
|
+
this.totalIncl = new Amount(this.constructPrediction(totalIncl));
|
|
95
|
+
this.totalExcl = new Amount(this.constructPrediction(totalExcl));
|
|
96
|
+
this.totalTax = new Amount(this.constructPrediction(totalTax));
|
|
97
|
+
this.date = new Date(this.constructPrediction(invoiceDate));
|
|
98
|
+
this.invoiceDate = new Date(this.constructPrediction(invoiceDate));
|
|
99
|
+
this.dueDate = new Date(this.constructPrediction(dueDate));
|
|
100
|
+
this.supplier = new Field(this.constructPrediction(supplier));
|
|
101
|
+
this.invoiceNumber = new Field(this.constructPrediction(invoiceNumber));
|
|
102
|
+
this.paymentDetails = new Field(this.constructPrediction(paymentDetails));
|
|
103
|
+
this.companyNumber = new Field(this.constructPrediction(companyNumber));
|
|
104
|
+
this.vatNumber = new Field(this.constructPrediction(vatNumber));
|
|
104
105
|
if (taxes !== undefined) {
|
|
105
106
|
this.taxes = [];
|
|
106
107
|
for (const t of taxes) {
|
|
@@ -114,6 +115,9 @@ class Invoice extends Document {
|
|
|
114
115
|
);
|
|
115
116
|
}
|
|
116
117
|
}
|
|
118
|
+
if (this.level === "page") {
|
|
119
|
+
this.orientation = new Orientation(this.constructPrediction(orientation));
|
|
120
|
+
}
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
#initFromApiPrediction(apiPrediction, pageNumber) {
|
|
@@ -153,10 +157,6 @@ class Invoice extends Document {
|
|
|
153
157
|
codeKey: "code",
|
|
154
158
|
});
|
|
155
159
|
});
|
|
156
|
-
this.orientation = new Orientation({
|
|
157
|
-
prediction: apiPrediction.orientation,
|
|
158
|
-
pageNumber,
|
|
159
|
-
});
|
|
160
160
|
this.companyNumber = apiPrediction.company_registration.map(function (
|
|
161
161
|
companyNumber
|
|
162
162
|
) {
|
|
@@ -184,7 +184,23 @@ class Invoice extends Document {
|
|
|
184
184
|
) {
|
|
185
185
|
return new PaymentDetails({ prediction: paymentDetail, pageNumber });
|
|
186
186
|
});
|
|
187
|
-
|
|
187
|
+
if (this.level === "page") {
|
|
188
|
+
this.orientation = new Orientation({
|
|
189
|
+
prediction: apiPrediction.orientation,
|
|
190
|
+
pageNumber,
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
this.orientation = new Orientation(
|
|
194
|
+
this.constructPrediction({
|
|
195
|
+
prediction: {
|
|
196
|
+
value: undefined,
|
|
197
|
+
probability: 0.0,
|
|
198
|
+
degrees: undefined,
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
// document.inference.ocr
|
|
188
204
|
if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
|
|
189
205
|
}
|
|
190
206
|
|
|
@@ -22,6 +22,7 @@ class Receipt extends Document {
|
|
|
22
22
|
* @param {Object} orientation - orientation value for creating Receipt object from scratch
|
|
23
23
|
* @param {Object} totalTax - total taxes value for creating Receipt object from scratch
|
|
24
24
|
* @param {Object} totalExcl - total taxes excluded value for creating Receipt object from scratch
|
|
25
|
+
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
25
26
|
*/
|
|
26
27
|
constructor({
|
|
27
28
|
apiPrediction = undefined,
|
|
@@ -37,8 +38,13 @@ class Receipt extends Document {
|
|
|
37
38
|
totalTax = undefined,
|
|
38
39
|
totalExcl = undefined,
|
|
39
40
|
pageNumber = 0,
|
|
41
|
+
level = "page",
|
|
40
42
|
}) {
|
|
41
43
|
super(inputFile);
|
|
44
|
+
this.level = level;
|
|
45
|
+
this.constructPrediction = function (item) {
|
|
46
|
+
return { prediction: { value: item }, valueKey: "value", pageNumber };
|
|
47
|
+
};
|
|
42
48
|
if (apiPrediction === undefined) {
|
|
43
49
|
this.#initFromScratch({
|
|
44
50
|
locale,
|
|
@@ -73,15 +79,12 @@ class Receipt extends Document {
|
|
|
73
79
|
totalTax,
|
|
74
80
|
pageNumber,
|
|
75
81
|
}) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
this.category = new Field(constructPrediction(category));
|
|
83
|
-
this.merchantName = new Field(constructPrediction(merchantName));
|
|
84
|
-
this.time = new Field(constructPrediction(time));
|
|
82
|
+
this.locale = new Locale(this.constructPrediction(locale));
|
|
83
|
+
this.totalIncl = new Amount(this.constructPrediction(totalIncl));
|
|
84
|
+
this.date = new Date(this.constructPrediction(date));
|
|
85
|
+
this.category = new Field(this.constructPrediction(category));
|
|
86
|
+
this.merchantName = new Field(this.constructPrediction(merchantName));
|
|
87
|
+
this.time = new Field(this.constructPrediction(time));
|
|
85
88
|
if (taxes !== undefined) {
|
|
86
89
|
this.taxes = [];
|
|
87
90
|
for (const t of taxes) {
|
|
@@ -95,9 +98,9 @@ class Receipt extends Document {
|
|
|
95
98
|
);
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
|
-
this.orientation = new Orientation(constructPrediction(orientation));
|
|
99
|
-
this.totalTax = new Amount(constructPrediction(totalTax));
|
|
100
|
-
this.totalExcl = new Amount(constructPrediction(totalExcl));
|
|
101
|
+
this.orientation = new Orientation(this.constructPrediction(orientation));
|
|
102
|
+
this.totalTax = new Amount(this.constructPrediction(totalTax));
|
|
103
|
+
this.totalExcl = new Amount(this.constructPrediction(totalExcl));
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
/**
|
|
@@ -142,10 +145,6 @@ class Receipt extends Document {
|
|
|
142
145
|
codeKey: "code",
|
|
143
146
|
})
|
|
144
147
|
);
|
|
145
|
-
this.orientation = new Orientation({
|
|
146
|
-
prediction: apiPrediction.orientation,
|
|
147
|
-
pageNumber,
|
|
148
|
-
});
|
|
149
148
|
this.totalTax = new Amount({
|
|
150
149
|
prediction: { value: undefined, probability: 0 },
|
|
151
150
|
valueKey: "value",
|
|
@@ -156,6 +155,22 @@ class Receipt extends Document {
|
|
|
156
155
|
valueKey: "value",
|
|
157
156
|
pageNumber,
|
|
158
157
|
});
|
|
158
|
+
if (this.level === "page") {
|
|
159
|
+
this.orientation = new Orientation({
|
|
160
|
+
prediction: apiPrediction.orientation,
|
|
161
|
+
pageNumber,
|
|
162
|
+
});
|
|
163
|
+
} else {
|
|
164
|
+
this.orientation = new Orientation(
|
|
165
|
+
this.constructPrediction({
|
|
166
|
+
prediction: {
|
|
167
|
+
value: undefined,
|
|
168
|
+
probability: 0.0,
|
|
169
|
+
degrees: undefined,
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
}
|
|
159
174
|
if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
|
|
160
175
|
}
|
|
161
176
|
|
package/mindee/inputs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Mindee API SDK for Node.js",
|
|
5
5
|
"main": "mindee/index.js",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"base64-stream": "^1.0.0",
|
|
39
39
|
"concat-stream": "^2.0.0",
|
|
40
40
|
"file-type": "^16.5.3",
|
|
41
|
-
"form-data": "^3.0.
|
|
41
|
+
"form-data": "^3.0.1",
|
|
42
42
|
"pdf-lib": "^1.13.0"
|
|
43
43
|
},
|
|
44
44
|
"keywords": [
|