Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mindee

Package Overview
Dependencies
Maintainers
7
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mindee - npm Package Compare versions

Comparing version 4.2.0 to 4.3.0

5

CHANGELOG.md
# CHANGELOG
## v4.3.0 - 2023-09-19
### Changes
* :sparkles: add line items reconstruction for API builder
## v4.2.0 - 2023-09-15

@@ -4,0 +9,0 @@ ### Changes

2

package.json
{
"name": "mindee",
"version": "4.2.0",
"version": "4.3.0",
"description": "Mindee Client Library for Node.js",

@@ -5,0 +5,0 @@ "main": "src/index.js",

import { Point } from "./point";
/** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
export type BBox = [number, number, number, number];
export declare class BBox {
xMin: number;
yMin: number;
xMax: number;
yMax: number;
constructor(xMin: number, yMin: number, xMax: number, yMax: number);
}
/** A bounding box defined by 4 points. */
export type BoundingBox = [Point, Point, Point, Point];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BBox = void 0;
/** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
class BBox {
constructor(xMin, yMin, xMax, yMax) {
this.xMin = xMin;
this.yMin = yMin;
this.xMax = xMax;
this.yMax = yMax;
}
}
exports.BBox = BBox;

@@ -16,8 +16,8 @@ import { BoundingBox, BBox } from "./boundingBox";

/**
* Given a Polygon, calculate a bounding box that encompasses all points.
* Given a Polygon, calculate a BBox that encompasses all points.
*/
export declare function getBbox(polygon: Polygon): BBox;
/**
* Given polygons, calculate a bounding box that encompasses all points.
* Given polygons, calculate a BBox that encompasses all points.
*/
export declare function getBBoxForPolygons(polygons: Polygon[]): BBox;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBBoxForPolygons = exports.getBbox = exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = void 0;
const boundingBox_1 = require("./boundingBox");
/**

@@ -9,8 +10,3 @@ * Given a Polygon, calculate a polygon that encompasses all points.

const bbox = getBbox(polygon);
return [
[bbox[0], bbox[1]],
[bbox[2], bbox[1]],
[bbox[2], bbox[3]],
[bbox[0], bbox[3]],
];
return getBoundingBoxFromBBox(bbox);
}

@@ -23,6 +19,6 @@ exports.getBoundingBox = getBoundingBox;

return [
[bbox[0], bbox[1]],
[bbox[2], bbox[1]],
[bbox[2], bbox[3]],
[bbox[0], bbox[3]],
[bbox.xMin, bbox.yMin],
[bbox.xMax, bbox.yMin],
[bbox.xMax, bbox.yMax],
[bbox.xMin, bbox.yMax],
];

@@ -35,12 +31,7 @@ }

function mergeBbox(bbox1, bbox2) {
return [
Math.min(bbox1[0], bbox2[0]),
Math.min(bbox1[1], bbox2[1]),
Math.max(bbox1[2], bbox2[2]),
Math.max(bbox1[3], bbox2[3]),
];
return new boundingBox_1.BBox(Math.min(bbox1.xMin, bbox2.xMin), Math.min(bbox1.yMin, bbox2.yMin), Math.max(bbox1.xMax, bbox2.xMax), Math.max(bbox1.yMax, bbox2.yMax));
}
exports.mergeBbox = mergeBbox;
/**
* Given a Polygon, calculate a bounding box that encompasses all points.
* Given a Polygon, calculate a BBox that encompasses all points.
*/

@@ -50,11 +41,7 @@ function getBbox(polygon) {

const allX = polygon.map((point) => point[0]);
const yMin = Math.min(...allY);
const yMax = Math.max(...allY);
const xMin = Math.min(...allX);
const xMax = Math.max(...allX);
return [xMin, yMin, xMax, yMax];
return new boundingBox_1.BBox(Math.min(...allX), Math.min(...allY), Math.max(...allX), Math.max(...allY));
}
exports.getBbox = getBbox;
/**
* Given polygons, calculate a bounding box that encompasses all points.
* Given polygons, calculate a BBox that encompasses all points.
*/

@@ -64,8 +51,4 @@ function getBBoxForPolygons(polygons) {

const allX = polygons.flatMap((polygon) => polygon.map((point) => point[0]));
const yMin = Math.min(...allY);
const yMax = Math.max(...allY);
const xMin = Math.min(...allX);
const xMax = Math.max(...allX);
return [xMin, yMin, xMax, yMax];
return new boundingBox_1.BBox(Math.min(...allX), Math.min(...allY), Math.max(...allX), Math.max(...allY));
}
exports.getBBoxForPolygons = getBBoxForPolygons;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = exports.getBBoxForPolygons = exports.getBbox = exports.getMinMaxY = exports.getMinMaxX = exports.relativeY = exports.relativeX = exports.isPointInPolygonY = exports.isPointInPolygonX = exports.getCentroid = exports.compareOnY = exports.compareOnX = exports.Polygon = void 0;
exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = exports.getBBoxForPolygons = exports.getBbox = exports.BBox = exports.getMinMaxY = exports.getMinMaxX = exports.relativeY = exports.relativeX = exports.isPointInPolygonY = exports.isPointInPolygonX = exports.getCentroid = exports.compareOnY = exports.compareOnX = exports.Polygon = void 0;
var polygon_1 = require("./polygon");

@@ -16,2 +16,4 @@ Object.defineProperty(exports, "Polygon", { enumerable: true, get: function () { return polygon_1.Polygon; } });

Object.defineProperty(exports, "getMinMaxY", { enumerable: true, get: function () { return polygonUtils_1.getMinMaxY; } });
var boundingBox_1 = require("./boundingBox");
Object.defineProperty(exports, "BBox", { enumerable: true, get: function () { return boundingBox_1.BBox; } });
var boundingBoxUtils_1 = require("./boundingBoxUtils");

@@ -18,0 +20,0 @@ Object.defineProperty(exports, "getBbox", { enumerable: true, get: function () { return boundingBoxUtils_1.getBbox; } });

@@ -1,3 +0,3 @@

export { Line, LineItems, getLineItems } from "./lineItems";
export { CustomLine, getLineItems } from "./lineItems";
export { ClassificationField } from "./classificationField";
export { ListField, ListFieldValue } from "./listField";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListFieldValue = exports.ListField = exports.ClassificationField = exports.getLineItems = exports.LineItems = exports.Line = void 0;
exports.ListFieldValue = exports.ListField = exports.ClassificationField = exports.getLineItems = exports.CustomLine = void 0;
var lineItems_1 = require("./lineItems");
Object.defineProperty(exports, "Line", { enumerable: true, get: function () { return lineItems_1.Line; } });
Object.defineProperty(exports, "LineItems", { enumerable: true, get: function () { return lineItems_1.LineItems; } });
Object.defineProperty(exports, "CustomLine", { enumerable: true, get: function () { return lineItems_1.CustomLine; } });
Object.defineProperty(exports, "getLineItems", { enumerable: true, get: function () { return lineItems_1.getLineItems; } });

@@ -8,0 +7,0 @@ var classificationField_1 = require("./classificationField");

import { BBox, Polygon } from "../../geometry";
import { ListField, ListFieldValue } from "./listField";
export declare class Line {
export declare class CustomLine {
/**

@@ -17,9 +17,4 @@ * Number of the current line.

bbox: BBox;
constructor(rowNumber: number);
/**
* The height tolerance used to build the line.
* It helps when the height of a line can vary unexpectedly.
*/
heightTolerance: number;
constructor(rowNumber: number, heightTolerance: number);
/**
* Extends the current bbox of the line with the bbox.

@@ -32,12 +27,4 @@ */

extendWith(polygon: Polygon): void;
/**
* Check if the bbox fits the current line.
*/
contains(bbox: BBox): boolean;
updateField(name: string, fieldValue: ListFieldValue): void;
}
export declare class LineItems {
rows: Line[];
constructor(lines: Line[]);
}
export declare function getLineItems(anchorNames: string[], heightLineTolerance: number, fieldNamesTargeted: string[], fields: Map<string, ListField>): LineItems;
export declare function getLineItems(anchorNames: string[], fieldNames: string[], fields: Map<string, ListField>, heightLineTolerance: number): CustomLine[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLineItems = exports.LineItems = exports.Line = void 0;
exports.getLineItems = exports.CustomLine = void 0;
const handler_1 = require("../../errors/handler");

@@ -8,8 +8,7 @@ const errors_1 = require("../../errors");

const listField_1 = require("./listField");
class Line {
constructor(rowNumber, heightTolerance) {
class CustomLine {
constructor(rowNumber) {
this.rowNumber = rowNumber;
this.bbox = [1, 1, 0, 0];
this.bbox = new geometry_1.BBox(1, 1, 0, 0);
this.fields = new Map();
this.heightTolerance = heightTolerance;
}

@@ -28,11 +27,2 @@ /**

}
/**
* Check if the bbox fits the current line.
*/
contains(bbox) {
if (Math.abs(bbox[1] - this.bbox[1]) <= this.heightTolerance) {
return true;
}
return Math.abs(this.bbox[1] - bbox[1]) <= this.heightTolerance;
}
updateField(name, fieldValue) {

@@ -63,20 +53,13 @@ if (!this.fields.has(name)) {

}
exports.Line = Line;
class LineItems {
constructor(lines) {
this.rows = [];
this.rows = lines;
}
}
exports.LineItems = LineItems;
function getLineItems(anchorNames, heightLineTolerance, fieldNamesTargeted, fields) {
const fieldsToTransformIntoLines = new Map([...fields].filter(([k]) => fieldNamesTargeted.includes(k)));
exports.CustomLine = CustomLine;
function getLineItems(anchorNames, fieldNames, fields, heightLineTolerance) {
const fieldsToTransformIntoLines = new Map([...fields].filter(([k]) => fieldNames.includes(k)));
const anchorName = findBestAnchor(anchorNames, fieldsToTransformIntoLines);
const lineItemsPrepared = prepare(anchorName, fieldsToTransformIntoLines, heightLineTolerance);
lineItemsPrepared.rows.forEach((currentLine) => {
const linesPrepared = prepare(anchorName, fieldsToTransformIntoLines, heightLineTolerance);
linesPrepared.forEach((currentLine) => {
fieldsToTransformIntoLines.forEach((field, fieldName) => {
field.values.forEach((listFieldValue) => {
const minYCurrentValue = (0, geometry_1.getMinMaxY)(listFieldValue.polygon).min;
if (minYCurrentValue < currentLine.bbox[3] &&
minYCurrentValue >= currentLine.bbox[1]) {
if (minYCurrentValue < currentLine.bbox.yMax &&
minYCurrentValue >= currentLine.bbox.yMin) {
currentLine.updateField(fieldName, listFieldValue);

@@ -87,3 +70,3 @@ }

});
return lineItemsPrepared;
return linesPrepared;
}

@@ -106,4 +89,13 @@ exports.getLineItems = getLineItems;

}
/**
* Check if the bbox fits inside the line.
*/
function isBboxInLine(line, bbox, heightTolerance) {
if (Math.abs(bbox.yMin - line.bbox.yMin) <= heightTolerance) {
return true;
}
return Math.abs(line.bbox.yMin - bbox.yMin) <= heightTolerance;
}
function prepare(anchorName, fields, heightLineTolerance) {
const lineItemsPrepared = [];
const linesPrepared = [];
const anchorField = fields.get(anchorName);

@@ -114,3 +106,3 @@ if (anchorField === undefined || anchorField.values.length === 0) {

let currentLineNumber = 1;
let currentLine = new Line(currentLineNumber, heightLineTolerance);
let currentLine = new CustomLine(currentLineNumber);
if (anchorField !== undefined) {

@@ -122,15 +114,15 @@ let currentValue = anchorField.values[0];

const currentFieldBbox = (0, geometry_1.getBbox)(currentValue.polygon);
if (!currentLine.contains(currentFieldBbox)) {
lineItemsPrepared.push(currentLine);
if (!isBboxInLine(currentLine, currentFieldBbox, heightLineTolerance)) {
linesPrepared.push(currentLine);
currentLineNumber++;
currentLine = new Line(currentLineNumber, heightLineTolerance);
currentLine = new CustomLine(currentLineNumber);
}
currentLine.extendWithBbox(currentFieldBbox);
}
if (lineItemsPrepared.filter((line) => line.rowNumber === currentLineNumber)
if (linesPrepared.filter((line) => line.rowNumber === currentLineNumber)
.length === 0) {
lineItemsPrepared.push(currentLine);
linesPrepared.push(currentLine);
}
}
return new LineItems(lineItemsPrepared);
return linesPrepared;
}
import { StringDict, Prediction } from "../../parsing/common";
import { ClassificationField, ListField } from "../../parsing/custom";
import { ClassificationField, ListField, CustomLine } from "../../parsing/custom";
/**

@@ -22,2 +22,9 @@ * Document data for Custom builds.

/**
* Order column fields into line items.
* @param anchorNames list of possible anchor fields.
* @param fieldNames list of all column fields.
* @param heightTolerance height tolerance to apply to lines.
*/
columnsToLineItems(anchorNames: string[], fieldNames: string[], heightTolerance?: number): CustomLine[];
/**
* Default string representation.

@@ -24,0 +31,0 @@ */

@@ -44,2 +44,11 @@ "use strict";

/**
* Order column fields into line items.
* @param anchorNames list of possible anchor fields.
* @param fieldNames list of all column fields.
* @param heightTolerance height tolerance to apply to lines.
*/
columnsToLineItems(anchorNames, fieldNames, heightTolerance = 0.01) {
return (0, custom_1.getLineItems)(anchorNames, fieldNames, this.fields, heightTolerance);
}
/**
* Default string representation.

@@ -46,0 +55,0 @@ */

import { StringDict, Prediction } from "../../parsing/common";
import { ListField } from "../../parsing/custom";
import { ListField, CustomLine } from "../../parsing/custom";
/**

@@ -11,2 +11,9 @@ * Page data for Custom builds.

/**
* Order column fields into line items.
* @param anchorNames list of possible anchor fields.
* @param fieldNames list of all column fields.
* @param heightTolerance height tolerance to apply to lines.
*/
columnsToLineItems(anchorNames: string[], fieldNames: string[], heightTolerance?: number): CustomLine[];
/**
* Default string representation.

@@ -13,0 +20,0 @@ */

@@ -21,2 +21,11 @@ "use strict";

/**
* Order column fields into line items.
* @param anchorNames list of possible anchor fields.
* @param fieldNames list of all column fields.
* @param heightTolerance height tolerance to apply to lines.
*/
columnsToLineItems(anchorNames, fieldNames, heightTolerance = 0.01) {
return (0, custom_1.getLineItems)(anchorNames, fieldNames, this.fields, heightTolerance);
}
/**
* Default string representation.

@@ -23,0 +32,0 @@ */

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc