react-pdf-ner-annotator
Version:
A React component to annotate named entities directly onto a PDF.
34 lines • 1.78 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
exports.__esModule = true;
var react_1 = require("react");
var textMapHelpers_1 = require("../helpers/textMapHelpers");
var useTextMap = function (annotations) {
var _a = (0, react_1.useState)([]), textMap = _a[0], setTextMap = _a[1];
(0, react_1.useEffect)(function () {
var pagesWithAnnotations = Array.from(new Set(annotations.map(function (annotation) { return annotation.page; })).values());
var textMapCleaned = textMap.filter(function (textMapItem) { return pagesWithAnnotations.includes(textMapItem.page); });
if (textMapCleaned.length < textMap.length) {
setTextMap(textMapCleaned);
}
}, [annotations, textMap]);
var addPageToTextMap = (0, react_1.useCallback)(function (page, pdfTextLayer, type, confidence, tokenizer) {
if (!textMap.find(function (textMapItem) { return textMapItem.page === page; })) {
var newTextMap = __spreadArray(__spreadArray([], textMap, true), [
{ page: page, textMapItems: (0, textMapHelpers_1.buildTextMapFromTextLayer)(pdfTextLayer, type, tokenizer), type: type, confidence: confidence },
], false);
setTextMap(newTextMap);
}
}, [textMap]);
return { textMap: textMap, addPageToTextMap: addPageToTextMap };
};
exports["default"] = useTextMap;
//# sourceMappingURL=useTextMap.js.map