UNPKG

mindee

Version:

Mindee Client Library for Node.js

61 lines (60 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ListField = exports.ListFieldValue = void 0; const geometry_1 = require("../../geometry"); class ListFieldValue { constructor(prediction, pageId) { /** * Contains the relative vertices coordinates (points) of a polygon containing * the word in the document. */ this.polygon = new geometry_1.Polygon(); this.content = prediction["content"]; this.confidence = prediction["confidence"]; if (prediction["polygon"]) { this.polygon = prediction["polygon"]; this.bbox = (0, geometry_1.getBoundingBox)(prediction["polygon"]); } if (pageId !== undefined) { this.pageId = pageId; } } /** * Default string representation. */ toString() { return `${this.content}`; } } exports.ListFieldValue = ListFieldValue; class ListField { /** * @param {BaseFieldConstructor} constructor Constructor parameters. */ constructor({ prediction = {}, reconstructed = false, pageId, }) { this.values = []; this.confidence = prediction["confidence"]; this.reconstructed = reconstructed; if (prediction["values"] !== undefined) { prediction["values"].forEach((field) => { if (pageId === undefined) { pageId = field["page_id"]; } this.values.push(new ListFieldValue(field, pageId)); }); } } contentsList() { return this.values.map((item) => item.content); } contentsString(separator = " ") { return this.values.map((item) => `${item.content}`).join(separator); } /** * Default string representation. */ toString() { return this.contentsString(); } } exports.ListField = ListField;