mindee
Version:
Mindee Client Library for Node.js
41 lines (40 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomV1Page = void 0;
const common_1 = require("../../parsing/common");
const custom_1 = require("../../parsing/custom");
/**
* Page data for Custom builds.
*/
class CustomV1Page {
constructor(rawPrediction, pageId) {
/** Map of page-specific fields for a Custom build. Cannot include Classification fields. */
this.fields = new Map();
Object.entries(rawPrediction).forEach(([fieldName, fieldValue]) => {
this.fields.set(fieldName, new custom_1.ListField({
prediction: fieldValue,
pageId: pageId,
}));
});
}
/**
* 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.
*/
toString() {
let outStr = "";
this.fields.forEach((fieldData, name) => {
outStr += `:${name}: ${fieldData}\n`;
});
return (0, common_1.cleanOutString)(outStr).trimEnd();
}
}
exports.CustomV1Page = CustomV1Page;