mindee 4.3.0 → 4.3.2

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.3.2 - 2023-10-04
4
+ ### Changes
5
+ * :arrow_up: dependency upgrade
6
+ * :recycle: minor refactoring
7
+
8
+
9
+ ## v4.3.1 - 2023-09-20
10
+ ### Fixes
11
+ * :bug: take line height tolerance into account when evaluating fields
12
+
13
+
3
14
  ## v4.3.0 - 2023-09-19
4
15
  ### Changes
5
16
  * :sparkles: add line items reconstruction for API builder
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
@@ -45,7 +45,7 @@
45
45
  "@types/node": "^18.15.11",
46
46
  "@typescript-eslint/eslint-plugin": "^5.57.1",
47
47
  "@typescript-eslint/parser": "^5.57.1",
48
- "chai": "^4.3.7",
48
+ "chai": "^4.3.10",
49
49
  "eslint": "^8.47.0",
50
50
  "lint-staged": "^13.2.3",
51
51
  "mocha": "^10.1.0",
@@ -22,7 +22,7 @@ class CropperExtra extends extras_1.ExtraField {
22
22
  toString() {
23
23
  const cropping = this.cropping
24
24
  .map((crop) => crop.toString())
25
- .join("\n ");
25
+ .join("\n ");
26
26
  return (0, summaryHelper_1.cleanOutString)(cropping);
27
27
  }
28
28
  }
@@ -1,3 +1,3 @@
1
- export { CustomLine, getLineItems } from "./lineItems";
1
+ export { CustomLine, CustomLines, getLineItems } from "./lineItems";
2
2
  export { ClassificationField } from "./classificationField";
3
3
  export { ListField, ListFieldValue } from "./listField";
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ListFieldValue = exports.ListField = exports.ClassificationField = exports.getLineItems = exports.CustomLine = void 0;
3
+ exports.ListFieldValue = exports.ListField = exports.ClassificationField = exports.getLineItems = exports.CustomLines = exports.CustomLine = void 0;
4
4
  var lineItems_1 = require("./lineItems");
5
5
  Object.defineProperty(exports, "CustomLine", { enumerable: true, get: function () { return lineItems_1.CustomLine; } });
6
+ Object.defineProperty(exports, "CustomLines", { enumerable: true, get: function () { return lineItems_1.CustomLines; } });
6
7
  Object.defineProperty(exports, "getLineItems", { enumerable: true, get: function () { return lineItems_1.getLineItems; } });
7
8
  var classificationField_1 = require("./classificationField");
8
9
  Object.defineProperty(exports, "ClassificationField", { enumerable: true, get: function () { return classificationField_1.ClassificationField; } });
@@ -11,7 +11,7 @@ export declare class CustomLine {
11
11
  */
12
12
  fields: Map<string, ListFieldValue>;
13
13
  /**
14
- * The BBox of the current line.
14
+ * The BBox of the entire line, all fields included.
15
15
  */
16
16
  bbox: BBox;
17
17
  constructor(rowNumber: number);
@@ -25,4 +25,9 @@ export declare class CustomLine {
25
25
  extendWith(polygon: Polygon): void;
26
26
  updateField(name: string, fieldValue: ListFieldValue): void;
27
27
  }
28
- export declare function getLineItems(anchorNames: string[], fieldNames: string[], fields: Map<string, ListField>, heightLineTolerance: number): CustomLine[];
28
+ export declare class CustomLines extends Array<CustomLine> {
29
+ }
30
+ /**
31
+ * Get line items from fields.
32
+ */
33
+ export declare function getLineItems(anchorNames: string[], fieldNames: string[], fields: Map<string, ListField>, heightLineTolerance: number): CustomLines;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLineItems = exports.CustomLine = void 0;
3
+ exports.getLineItems = exports.CustomLines = exports.CustomLine = void 0;
4
4
  const handler_1 = require("../../errors/handler");
5
5
  const errors_1 = require("../../errors");
6
6
  const geometry_1 = require("../../geometry");
@@ -49,6 +49,12 @@ class CustomLine {
49
49
  }
50
50
  }
51
51
  exports.CustomLine = CustomLine;
52
+ class CustomLines extends Array {
53
+ }
54
+ exports.CustomLines = CustomLines;
55
+ /**
56
+ * Get line items from fields.
57
+ */
52
58
  function getLineItems(anchorNames, fieldNames, fields, heightLineTolerance) {
53
59
  const fieldsToTransformIntoLines = new Map([...fields].filter(([k]) => fieldNames.includes(k)));
54
60
  const anchorName = findBestAnchor(anchorNames, fieldsToTransformIntoLines);
@@ -56,9 +62,9 @@ function getLineItems(anchorNames, fieldNames, fields, heightLineTolerance) {
56
62
  linesPrepared.forEach((currentLine) => {
57
63
  fieldsToTransformIntoLines.forEach((field, fieldName) => {
58
64
  field.values.forEach((listFieldValue) => {
59
- const minYCurrentValue = (0, geometry_1.getMinMaxY)(listFieldValue.polygon).min;
60
- if (minYCurrentValue < currentLine.bbox.yMax &&
61
- minYCurrentValue >= currentLine.bbox.yMin) {
65
+ const minMaxY = (0, geometry_1.getMinMaxY)(listFieldValue.polygon);
66
+ if (Math.abs(minMaxY.max - currentLine.bbox.yMax) <= heightLineTolerance &&
67
+ Math.abs(minMaxY.min - currentLine.bbox.yMin) <= heightLineTolerance) {
62
68
  currentLine.updateField(fieldName, listFieldValue);
63
69
  }
64
70
  });
@@ -67,6 +73,9 @@ function getLineItems(anchorNames, fieldNames, fields, heightLineTolerance) {
67
73
  return linesPrepared;
68
74
  }
69
75
  exports.getLineItems = getLineItems;
76
+ /**
77
+ * Loop through the possible anchor fields and find the one with the most values.
78
+ */
70
79
  function findBestAnchor(possibleAnchorNames, fields) {
71
80
  let anchorName = "";
72
81
  let anchorRows = 0;
@@ -3,7 +3,7 @@ import { Polygon } from "../../geometry";
3
3
  import { StringDict } from "../common";
4
4
  export declare class ListFieldValue {
5
5
  /** Extracted content of the prediction */
6
- content: string | number;
6
+ content: string;
7
7
  /**
8
8
  * The confidence score of the prediction.
9
9
  * Note: Score is calculated on **word selection**, not its textual content (OCR).
@@ -1,5 +1,5 @@
1
1
  import { StringDict, Prediction } from "../../parsing/common";
2
- import { ClassificationField, ListField, CustomLine } from "../../parsing/custom";
2
+ import { ClassificationField, ListField, CustomLines } from "../../parsing/custom";
3
3
  /**
4
4
  * Document data for Custom builds.
5
5
  */
@@ -24,7 +24,7 @@ export declare class CustomV1Document implements Prediction {
24
24
  * @param fieldNames list of all column fields.
25
25
  * @param heightTolerance height tolerance to apply to lines.
26
26
  */
27
- columnsToLineItems(anchorNames: string[], fieldNames: string[], heightTolerance?: number): CustomLine[];
27
+ columnsToLineItems(anchorNames: string[], fieldNames: string[], heightTolerance?: number): CustomLines;
28
28
  /**
29
29
  * Default string representation.
30
30
  */
@@ -1,5 +1,5 @@
1
1
  import { StringDict, Prediction } from "../../parsing/common";
2
- import { ListField, CustomLine } from "../../parsing/custom";
2
+ import { ListField, CustomLines } from "../../parsing/custom";
3
3
  /**
4
4
  * Page data for Custom builds.
5
5
  */
@@ -13,7 +13,7 @@ export declare class CustomV1Page implements Prediction {
13
13
  * @param fieldNames list of all column fields.
14
14
  * @param heightTolerance height tolerance to apply to lines.
15
15
  */
16
- columnsToLineItems(anchorNames: string[], fieldNames: string[], heightTolerance?: number): CustomLine[];
16
+ columnsToLineItems(anchorNames: string[], fieldNames: string[], heightTolerance?: number): CustomLines;
17
17
  /**
18
18
  * Default string representation.
19
19
  */
@@ -1,9 +1,9 @@
1
- import { Inference, StringDict } from "../../parsing/common";
1
+ import { Prediction, StringDict } from "../../parsing/common";
2
2
  import { InvoiceSplitterV1PageGroup } from "./invoiceSplitterV1PageGroup";
3
3
  /**
4
4
  * Document data for Invoice Splitter, API version 1.
5
5
  */
6
- export declare class InvoiceSplitterV1Document extends Inference {
6
+ export declare class InvoiceSplitterV1Document implements Prediction {
7
7
  /** List of page indexes that belong to the same invoice in the PDF. */
8
8
  invoicePageGroups: InvoiceSplitterV1PageGroup[];
9
9
  constructor(rawPrediction: StringDict);
@@ -6,9 +6,8 @@ const invoiceSplitterV1PageGroup_1 = require("./invoiceSplitterV1PageGroup");
6
6
  /**
7
7
  * Document data for Invoice Splitter, API version 1.
8
8
  */
9
- class InvoiceSplitterV1Document extends common_1.Inference {
9
+ class InvoiceSplitterV1Document {
10
10
  constructor(rawPrediction) {
11
- super(rawPrediction);
12
11
  /** List of page indexes that belong to the same invoice in the PDF. */
13
12
  this.invoicePageGroups = [];
14
13
  rawPrediction["invoice_page_groups"] &&
@@ -1,6 +1,6 @@
1
1
  import { StringDict } from "../../parsing/common";
2
2
  /**
3
- * Pages indexes in a group.
3
+ * Pages indexes in a group for Invoice Splitter V1.
4
4
  */
5
5
  export declare class InvoiceSplitterV1PageGroup {
6
6
  /** List of page indexes. */
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvoiceSplitterV1PageGroup = void 0;
4
4
  /**
5
- * Pages indexes in a group.
5
+ * Pages indexes in a group for Invoice Splitter V1.
6
6
  */
7
7
  class InvoiceSplitterV1PageGroup {
8
8
  constructor(prediction) {