UNPKG

@briancullen/aws-textract-parser

Version:

Library for converting AWS Textract responses into a more usable structure.

31 lines (30 loc) 1.68 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var LineBlockNode_1 = __importDefault(require("../model/LineBlockNode")); var LineParser = /** @class */ (function () { function LineParser(wordParser, geometryParser, blockIdParser, blockMap) { this.wordParser = wordParser; this.geometryParser = geometryParser; this.blockIdParser = blockIdParser; this.blockMap = blockMap; } LineParser.prototype.process = function (line) { var _this = this; var _a, _b, _c, _d, _e; var children = (_c = (_b = (_a = line.Relationships) === null || _a === void 0 ? void 0 : _a.find(function (relationship) { return relationship.Type === 'CHILD'; })) === null || _b === void 0 ? void 0 : _b.Ids, (_c !== null && _c !== void 0 ? _c : [])); var words = children.map(function (id) { return _this.blockMap.get(id); }) .filter(function (block) { return block !== undefined; }) .filter(function (block) { return block.BlockType === 'WORD'; }) .map(function (block) { return _this.wordParser.process(block); }); var id = this.blockIdParser(line); var geometry = this.geometryParser(line); var confidence = (_d = line.Confidence, (_d !== null && _d !== void 0 ? _d : 0)); var text = (_e = line.Text, (_e !== null && _e !== void 0 ? _e : '')); return new LineBlockNode_1.default(id, geometry, text, confidence, words); }; return LineParser; }()); exports.default = LineParser;