mindee 4.3.0 → 4.3.1

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,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.3.1 - 2023-09-20
4
+ ### Fixes
5
+ * :bug: take line height tolerance into account when evaluating fields
6
+
7
+
3
8
  ## v4.3.0 - 2023-09-19
4
9
  ### Changes
5
10
  * :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.1",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
@@ -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;
@@ -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
  */