@claritylabs/cl-sdk 3.0.13 → 3.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +79 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2345,7 +2345,7 @@ function isDiscardableBoilerplate(text, unit) {
|
|
|
2345
2345
|
}
|
|
2346
2346
|
function isBoilerplateLine(line) {
|
|
2347
2347
|
const cleaned = normalizeWhitespace(line.replace(/\bColumn\s+\d+:\s*/gi, ""));
|
|
2348
|
-
return isDiscardableBoilerplate(cleaned) || /^
|
|
2348
|
+
return isDiscardableBoilerplate(cleaned) || /^THIS IS A CLAIMS-MADE AND REPORTED POLICY\.? PLEASE READ IT CAREFULLY\.?$/i.test(cleaned);
|
|
2349
2349
|
}
|
|
2350
2350
|
function removedBoilerplateLines(text) {
|
|
2351
2351
|
return text.split(/\s{2,}|\r?\n/).map(normalizeWhitespace).filter((line) => line && isBoilerplateLine(line));
|
|
@@ -2644,7 +2644,18 @@ function metadataString(metadata, key) {
|
|
|
2644
2644
|
}
|
|
2645
2645
|
function isTitleContentNode(node) {
|
|
2646
2646
|
if (node.kind !== "text") return false;
|
|
2647
|
-
|
|
2647
|
+
const isMarkedTitle = metadataString(node.metadata, "elementType") === "title" || metadataString(node.metadata, "sourceUnit") === "title";
|
|
2648
|
+
if (!isMarkedTitle) return false;
|
|
2649
|
+
const text = normalizeWhitespace2(node.textExcerpt ?? node.title);
|
|
2650
|
+
if (!text || text.length > 140) return false;
|
|
2651
|
+
const words = text.split(/\s+/);
|
|
2652
|
+
if (words.length > 14) return false;
|
|
2653
|
+
const startsWithStructuredHeading = /^(section|item|part|coverage part|endorsement|schedule|article)\b|^[A-Z]\.\s|\b[IVX]+\.\s/i.test(text);
|
|
2654
|
+
const uppercaseLetters = [...text].filter((char) => /[A-Z]/.test(char)).length;
|
|
2655
|
+
const lowercaseLetters = [...text].filter((char) => /[a-z]/.test(char)).length;
|
|
2656
|
+
const mostlyUppercase = uppercaseLetters > 0 && uppercaseLetters >= lowercaseLetters * 1.6;
|
|
2657
|
+
const sentenceLike = /\b(is|are|was|were|will|shall|may|must|means|includes|provided|subject|available|attached|remain|constitutes)\b/i.test(text) && /[a-z]/.test(text);
|
|
2658
|
+
return startsWithStructuredHeading || mostlyUppercase && !sentenceLike;
|
|
2648
2659
|
}
|
|
2649
2660
|
function nodePageEnd(node) {
|
|
2650
2661
|
return node.pageEnd ?? node.pageStart;
|
|
@@ -2684,10 +2695,10 @@ function groupPageContentByTitles(nodes) {
|
|
|
2684
2695
|
const bbox = evidenceNodes.flatMap((node) => node.bbox ?? []).slice(0, 12);
|
|
2685
2696
|
byId.set(activeTitle.id, {
|
|
2686
2697
|
...activeTitle,
|
|
2687
|
-
kind: "
|
|
2698
|
+
kind: "text",
|
|
2688
2699
|
title,
|
|
2689
2700
|
description: nodeTextDescription({
|
|
2690
|
-
kind: "
|
|
2701
|
+
kind: "text",
|
|
2691
2702
|
title,
|
|
2692
2703
|
text: evidenceNodes.map((node) => node.textExcerpt).filter(Boolean).join("\n\n"),
|
|
2693
2704
|
page: activeTitle.pageStart
|
|
@@ -9252,6 +9263,7 @@ function looksLikeDeclarationsContinuation(node) {
|
|
|
9252
9263
|
function looksLikePolicyFormStart(node) {
|
|
9253
9264
|
const text = sourceNodeText(node);
|
|
9254
9265
|
const excerpt = cleanText(node.textExcerpt, "");
|
|
9266
|
+
if (isAdministrativeNoticeNode(node) || looksLikeDeclarationsStart(node)) return false;
|
|
9255
9267
|
return /\bpolicy form\b/i.test(node.title) || /^policy\s+form\b/i.test(excerpt) || /\btechnology errors?\s*&?\s*omissions\b/i.test(text) && /\bplease read this entire policy carefully\b/i.test(text) || /\bform\s+[A-Z]{2,}-[A-Z0-9-]+\s+\d{2}\s+\d{2}\b/i.test(text);
|
|
9256
9268
|
}
|
|
9257
9269
|
function looksLikePolicyFormContinuation(node) {
|
|
@@ -9260,9 +9272,9 @@ function looksLikePolicyFormContinuation(node) {
|
|
|
9260
9272
|
return /\b(insuring agreement|definitions?|exclusions?|conditions?|claim means|insured means|wrongful act means|limits of liability|notice of claim|cancellation by|action against the company)\b/i.test(text);
|
|
9261
9273
|
}
|
|
9262
9274
|
function groupAdjacentChildren(params) {
|
|
9263
|
-
if (params.childIds.length <
|
|
9275
|
+
if (params.childIds.length < 1) return params.sourceTree;
|
|
9264
9276
|
const children = params.childIds.map((id2) => params.children.find((child) => child.id === id2)).filter((child) => Boolean(child));
|
|
9265
|
-
if (children.length <
|
|
9277
|
+
if (children.length < 1) return params.sourceTree;
|
|
9266
9278
|
const parentId = children[0].parentId;
|
|
9267
9279
|
if (!children.every((child) => child.parentId === parentId)) return params.sourceTree;
|
|
9268
9280
|
const documentId = children[0].documentId;
|
|
@@ -9371,6 +9383,11 @@ function applySemanticPageGrouping(sourceTree) {
|
|
|
9371
9383
|
for (let index = policyStartIndex; index < children.length; index += 1) {
|
|
9372
9384
|
const child = children[index];
|
|
9373
9385
|
if (index > policyStartIndex && looksLikeEndorsementStart(child)) break;
|
|
9386
|
+
if (isAdministrativeNoticeNode(child) || looksLikeDeclarationsStart(child)) break;
|
|
9387
|
+
if (index > policyStartIndex && child.kind === "page") {
|
|
9388
|
+
policyIds.push(child.id);
|
|
9389
|
+
continue;
|
|
9390
|
+
}
|
|
9374
9391
|
if (!looksLikePolicyFormContinuation(child)) break;
|
|
9375
9392
|
policyIds.push(child.id);
|
|
9376
9393
|
}
|
|
@@ -9398,6 +9415,9 @@ function rejectsOrganizerGroup(group, children) {
|
|
|
9398
9415
|
function isEndorsementGroup(node) {
|
|
9399
9416
|
return node.kind === "page_group" && /^endorsements?\b/i.test(node.title);
|
|
9400
9417
|
}
|
|
9418
|
+
function isNoticesGroup(node) {
|
|
9419
|
+
return node.kind === "page_group" && /^notices?\s+and\s+jacket$/i.test(node.title);
|
|
9420
|
+
}
|
|
9401
9421
|
function endorsementGroupNodeId(documentId, parentId) {
|
|
9402
9422
|
return [
|
|
9403
9423
|
documentId.replace(/[^a-zA-Z0-9_.:-]/g, "_"),
|
|
@@ -9413,6 +9433,56 @@ function isPolicyFormNode(node) {
|
|
|
9413
9433
|
function isDeclarationsNode(node) {
|
|
9414
9434
|
return node.kind === "page_group" && node.title === "Declarations";
|
|
9415
9435
|
}
|
|
9436
|
+
function isAdministrativeNoticeNode(node) {
|
|
9437
|
+
const text = sourceNodeText(node);
|
|
9438
|
+
return /\b(specimen policy|policy jacket|important notice|privacy notice|ofac advisory|terrorism risk insurance act|tria|trade or economic sanctions|economic sanctions limitation|signature|countersignature|how to report a claim)\b/i.test(text);
|
|
9439
|
+
}
|
|
9440
|
+
function mergeAdministrativeNoticesIntoFrontMatter(sourceTree) {
|
|
9441
|
+
const rootId = sourceTreeRootId(sourceTree);
|
|
9442
|
+
if (!rootId) return sourceTree;
|
|
9443
|
+
const children = (nodesByParent(sourceTree).get(rootId) ?? []).filter((node) => node.kind !== "document");
|
|
9444
|
+
const noticesGroup = children.find(isNoticesGroup);
|
|
9445
|
+
if (!noticesGroup) return sourceTree;
|
|
9446
|
+
const noticesGroupChildren = new Set(
|
|
9447
|
+
(nodesByParent(sourceTree).get(noticesGroup.id) ?? []).map((node) => node.id)
|
|
9448
|
+
);
|
|
9449
|
+
const noticeIds = new Set(
|
|
9450
|
+
children.filter(
|
|
9451
|
+
(node) => node.id !== noticesGroup.id && !noticesGroupChildren.has(node.id) && node.kind === "page" && isAdministrativeNoticeNode(node)
|
|
9452
|
+
).map((node) => node.id)
|
|
9453
|
+
);
|
|
9454
|
+
if (noticeIds.size === 0) return sourceTree;
|
|
9455
|
+
return sourceTree.map(
|
|
9456
|
+
(node) => noticeIds.has(node.id) ? {
|
|
9457
|
+
...node,
|
|
9458
|
+
parentId: noticesGroup.id,
|
|
9459
|
+
metadata: {
|
|
9460
|
+
...node.metadata,
|
|
9461
|
+
organizerRepair: "merge_administrative_notice"
|
|
9462
|
+
}
|
|
9463
|
+
} : node
|
|
9464
|
+
);
|
|
9465
|
+
}
|
|
9466
|
+
function rootSemanticRank(node) {
|
|
9467
|
+
if (isNoticesGroup(node)) return 0;
|
|
9468
|
+
if (node.title === "Declarations") return 1;
|
|
9469
|
+
if (node.title === "Policy Form") return 2;
|
|
9470
|
+
if (isEndorsementGroup(node)) return 3;
|
|
9471
|
+
if (isAdministrativeNoticeNode(node)) return 0.5;
|
|
9472
|
+
return 2.5;
|
|
9473
|
+
}
|
|
9474
|
+
function normalizeRootSemanticOrder(sourceTree) {
|
|
9475
|
+
const rootId = sourceTreeRootId(sourceTree);
|
|
9476
|
+
if (!rootId) return sourceTree;
|
|
9477
|
+
const rootChildren2 = (nodesByParent(sourceTree).get(rootId) ?? []).filter((node) => node.kind !== "document").sort(
|
|
9478
|
+
(left, right) => rootSemanticRank(left) - rootSemanticRank(right) || (left.pageStart ?? Number.MAX_SAFE_INTEGER) - (right.pageStart ?? Number.MAX_SAFE_INTEGER) || left.order - right.order || left.id.localeCompare(right.id)
|
|
9479
|
+
);
|
|
9480
|
+
const orderById = new Map(rootChildren2.map((node, index) => [node.id, index + 1]));
|
|
9481
|
+
return sourceTree.map((node) => {
|
|
9482
|
+
const order = orderById.get(node.id);
|
|
9483
|
+
return order === void 0 ? node : { ...node, order };
|
|
9484
|
+
});
|
|
9485
|
+
}
|
|
9416
9486
|
function normalizePolicyFormStructure(sourceTree) {
|
|
9417
9487
|
let nextTree = sourceTree;
|
|
9418
9488
|
const byParent = nodesByParent(nextTree);
|
|
@@ -9521,9 +9591,10 @@ function normalizeSemanticHierarchy(sourceTree) {
|
|
|
9521
9591
|
)
|
|
9522
9592
|
);
|
|
9523
9593
|
const nested = normalizeDocumentSourceTreePaths(nestEndorsementContinuationPages(normalized));
|
|
9524
|
-
const
|
|
9594
|
+
const mergedNotices = normalizeDocumentSourceTreePaths(mergeAdministrativeNoticesIntoFrontMatter(nested));
|
|
9595
|
+
const withEvidence = normalizeContainerEvidenceFromChildren(mergedNotices);
|
|
9525
9596
|
return normalizeDocumentSourceTreePaths(
|
|
9526
|
-
normalizeContainerEvidenceFromChildren(withEvidence)
|
|
9597
|
+
normalizeRootSemanticOrder(normalizeContainerEvidenceFromChildren(withEvidence))
|
|
9527
9598
|
);
|
|
9528
9599
|
}
|
|
9529
9600
|
function applyEndorsementGrouping(sourceTree) {
|