@claritylabs/cl-sdk 3.0.6 → 3.0.7
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 +147 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9425,13 +9425,157 @@ function simplifyOrganizerTitle(value, fallback, kind) {
|
|
|
9425
9425
|
return title;
|
|
9426
9426
|
}
|
|
9427
9427
|
function endorsementReference(value) {
|
|
9428
|
-
|
|
9428
|
+
const text = cleanText(value, "");
|
|
9429
|
+
const explicit = text.match(/\bendorsement\s+(?:no\.?|number|#)?\s*([A-Z0-9][A-Z0-9.-]*)\b/i)?.[1]?.toUpperCase();
|
|
9430
|
+
if (explicit) return explicit;
|
|
9431
|
+
return text.match(/\b(?:[A-Z]{2,}-)?END\s+0*([0-9]{1,4})\b/i)?.[1]?.toUpperCase();
|
|
9429
9432
|
}
|
|
9430
9433
|
function endorsementTitle(value) {
|
|
9431
9434
|
const text = cleanText(value, "");
|
|
9432
|
-
const
|
|
9435
|
+
const explicit = text.match(/\bendorsement\s+(?:no\.?|number|#)\s*([A-Z0-9][A-Z0-9.-]*)\b/i)?.[1]?.toUpperCase();
|
|
9436
|
+
const number = explicit ?? text.match(/\b(?:[A-Z]{2,}-)?END\s+0*([0-9]{1,4})\b/i)?.[1]?.toUpperCase();
|
|
9433
9437
|
return number ? `Endorsement No. ${number}` : void 0;
|
|
9434
9438
|
}
|
|
9439
|
+
function sourceNodeText(node) {
|
|
9440
|
+
return cleanText([node.title, node.description, node.textExcerpt].filter(Boolean).join(" "), "");
|
|
9441
|
+
}
|
|
9442
|
+
function semanticGroupNodeId(documentId, kind, title, childNodeIds) {
|
|
9443
|
+
return [
|
|
9444
|
+
documentId.replace(/[^a-zA-Z0-9_.:-]/g, "_"),
|
|
9445
|
+
"source_node",
|
|
9446
|
+
kind,
|
|
9447
|
+
title.replace(/[^a-zA-Z0-9_.:-]/g, "_").toLowerCase().slice(0, 48),
|
|
9448
|
+
childNodeIds.join("_").replace(/[^a-zA-Z0-9_.:-]/g, "_").slice(0, 80)
|
|
9449
|
+
].join(":");
|
|
9450
|
+
}
|
|
9451
|
+
function looksLikeDeclarationsStart(node) {
|
|
9452
|
+
return /\bdeclarations?\s+(page|schedule)\b/i.test(sourceNodeText(node));
|
|
9453
|
+
}
|
|
9454
|
+
function looksLikeDeclarationsContinuation(node) {
|
|
9455
|
+
const text = sourceNodeText(node);
|
|
9456
|
+
return looksLikeDeclarationsStart(node) || /\b(item\s+\d+\.|coverage part|each claim limit|aggregate limit|retroactive date|self-insured retention|premium|payment plan|producer|broker|forms? and endorsements?|extended reporting period|discovery period)\b/i.test(text);
|
|
9457
|
+
}
|
|
9458
|
+
function looksLikePolicyFormStart(node) {
|
|
9459
|
+
const text = sourceNodeText(node);
|
|
9460
|
+
return /\bpolicy form\b/i.test(node.title) || /\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);
|
|
9461
|
+
}
|
|
9462
|
+
function looksLikePolicyFormContinuation(node) {
|
|
9463
|
+
const text = sourceNodeText(node);
|
|
9464
|
+
if (looksLikePolicyFormStart(node)) return true;
|
|
9465
|
+
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);
|
|
9466
|
+
}
|
|
9467
|
+
function groupAdjacentChildren(params) {
|
|
9468
|
+
if (params.childIds.length < 2) return params.sourceTree;
|
|
9469
|
+
const children = params.childIds.map((id2) => params.children.find((child) => child.id === id2)).filter((child) => Boolean(child));
|
|
9470
|
+
if (children.length < 2) return params.sourceTree;
|
|
9471
|
+
const parentId = children[0].parentId;
|
|
9472
|
+
if (!children.every((child) => child.parentId === parentId)) return params.sourceTree;
|
|
9473
|
+
const documentId = children[0].documentId;
|
|
9474
|
+
const id = semanticGroupNodeId(documentId, params.kind, params.title, children.map((child) => child.id));
|
|
9475
|
+
if (params.sourceTree.some((node) => node.id === id)) return params.sourceTree;
|
|
9476
|
+
const pageStarts = children.map((child) => child.pageStart).filter((page) => typeof page === "number");
|
|
9477
|
+
const pageEnds = children.map((child) => child.pageEnd ?? child.pageStart).filter((page) => typeof page === "number");
|
|
9478
|
+
const sourceSpanIds = [...new Set(children.flatMap((child) => child.sourceSpanIds))];
|
|
9479
|
+
const order = Math.min(...children.map((child) => child.order));
|
|
9480
|
+
const groupNode = {
|
|
9481
|
+
id,
|
|
9482
|
+
documentId,
|
|
9483
|
+
parentId,
|
|
9484
|
+
kind: params.kind,
|
|
9485
|
+
title: params.title,
|
|
9486
|
+
description: params.description,
|
|
9487
|
+
textExcerpt: children.map((child) => child.textExcerpt ?? child.description).filter(Boolean).join("\n\n").slice(0, 1600),
|
|
9488
|
+
sourceSpanIds,
|
|
9489
|
+
pageStart: pageStarts.length ? Math.min(...pageStarts) : void 0,
|
|
9490
|
+
pageEnd: pageEnds.length ? Math.max(...pageEnds) : void 0,
|
|
9491
|
+
bbox: children.flatMap((child) => child.bbox ?? []).slice(0, 12),
|
|
9492
|
+
order,
|
|
9493
|
+
path: "",
|
|
9494
|
+
metadata: { sourceTreeVersion: "v3", organizer: params.organizer }
|
|
9495
|
+
};
|
|
9496
|
+
const wanted = new Set(children.map((child) => child.id));
|
|
9497
|
+
return [
|
|
9498
|
+
...params.sourceTree.map(
|
|
9499
|
+
(node) => wanted.has(node.id) ? { ...node, parentId: id, order: node.order + 1e-3 } : node
|
|
9500
|
+
),
|
|
9501
|
+
groupNode
|
|
9502
|
+
];
|
|
9503
|
+
}
|
|
9504
|
+
function applySemanticPageGrouping(sourceTree) {
|
|
9505
|
+
const relabeled = sourceTree.map((node) => {
|
|
9506
|
+
if (node.kind === "document" || node.kind === "page_group") return node;
|
|
9507
|
+
const text = sourceNodeText(node);
|
|
9508
|
+
const endorsement = endorsementTitle(text);
|
|
9509
|
+
if (endorsement && node.kind === "page") {
|
|
9510
|
+
return {
|
|
9511
|
+
...node,
|
|
9512
|
+
kind: "endorsement",
|
|
9513
|
+
title: endorsement,
|
|
9514
|
+
description: cleanText([endorsement, "endorsement", node.pageStart ? `page ${node.pageStart}` : void 0, node.textExcerpt].filter(Boolean).join(" | "), endorsement),
|
|
9515
|
+
metadata: { ...node.metadata, organizerRepair: "semantic_page_grouping" }
|
|
9516
|
+
};
|
|
9517
|
+
}
|
|
9518
|
+
if (node.kind === "page" && looksLikeDeclarationsStart(node)) {
|
|
9519
|
+
return {
|
|
9520
|
+
...node,
|
|
9521
|
+
title: "Declarations",
|
|
9522
|
+
description: cleanText([node.description, "Declarations"].join(" "), "Declarations"),
|
|
9523
|
+
metadata: { ...node.metadata, organizerRepair: "semantic_page_grouping" }
|
|
9524
|
+
};
|
|
9525
|
+
}
|
|
9526
|
+
if (node.kind === "page" && looksLikePolicyFormStart(node)) {
|
|
9527
|
+
return {
|
|
9528
|
+
...node,
|
|
9529
|
+
title: "Policy Form",
|
|
9530
|
+
description: cleanText([node.description, "Policy Form"].join(" "), "Policy Form"),
|
|
9531
|
+
metadata: { ...node.metadata, organizerRepair: "semantic_page_grouping" }
|
|
9532
|
+
};
|
|
9533
|
+
}
|
|
9534
|
+
return node;
|
|
9535
|
+
});
|
|
9536
|
+
const rootId = sourceTreeRootId(relabeled);
|
|
9537
|
+
const children = (nodesByParent(relabeled).get(rootId) ?? []).filter((node) => node.kind !== "document").sort((left, right) => left.order - right.order);
|
|
9538
|
+
let nextTree = relabeled;
|
|
9539
|
+
const declarationsStartIndex = children.findIndex(looksLikeDeclarationsStart);
|
|
9540
|
+
if (declarationsStartIndex >= 0) {
|
|
9541
|
+
const declarationIds = [];
|
|
9542
|
+
for (let index = declarationsStartIndex; index < children.length; index += 1) {
|
|
9543
|
+
const child = children[index];
|
|
9544
|
+
if (index > declarationsStartIndex && (looksLikePolicyFormStart(child) || endorsementTitle(sourceNodeText(child)))) break;
|
|
9545
|
+
if (!looksLikeDeclarationsContinuation(child)) break;
|
|
9546
|
+
declarationIds.push(child.id);
|
|
9547
|
+
}
|
|
9548
|
+
nextTree = groupAdjacentChildren({
|
|
9549
|
+
sourceTree: nextTree,
|
|
9550
|
+
children,
|
|
9551
|
+
childIds: declarationIds,
|
|
9552
|
+
kind: "page_group",
|
|
9553
|
+
title: "Declarations",
|
|
9554
|
+
description: "Declarations pages and schedules grouped by source order",
|
|
9555
|
+
organizer: "semantic_declarations_grouping"
|
|
9556
|
+
});
|
|
9557
|
+
}
|
|
9558
|
+
const policyStartIndex = children.findIndex(looksLikePolicyFormStart);
|
|
9559
|
+
if (policyStartIndex >= 0) {
|
|
9560
|
+
const policyIds = [];
|
|
9561
|
+
for (let index = policyStartIndex; index < children.length; index += 1) {
|
|
9562
|
+
const child = children[index];
|
|
9563
|
+
if (index > policyStartIndex && endorsementTitle(sourceNodeText(child))) break;
|
|
9564
|
+
if (!looksLikePolicyFormContinuation(child)) break;
|
|
9565
|
+
policyIds.push(child.id);
|
|
9566
|
+
}
|
|
9567
|
+
nextTree = groupAdjacentChildren({
|
|
9568
|
+
sourceTree: nextTree,
|
|
9569
|
+
children,
|
|
9570
|
+
childIds: policyIds,
|
|
9571
|
+
kind: "form",
|
|
9572
|
+
title: "Policy Form",
|
|
9573
|
+
description: "Policy form pages grouped by source order",
|
|
9574
|
+
organizer: "semantic_policy_form_grouping"
|
|
9575
|
+
});
|
|
9576
|
+
}
|
|
9577
|
+
return applyEndorsementGrouping(normalizeDocumentSourceTreePaths(nextTree));
|
|
9578
|
+
}
|
|
9435
9579
|
function rejectsOrganizerGroup(group, children) {
|
|
9436
9580
|
if (/^endorsements?\b/i.test(group.title) && group.kind !== "page_group") return true;
|
|
9437
9581
|
if (group.kind !== "endorsement") return false;
|
|
@@ -9918,6 +10062,7 @@ async function runSourceTreeExtraction(params) {
|
|
|
9918
10062
|
} catch (error) {
|
|
9919
10063
|
warnings.push(`Source-tree organizer failed; deterministic tree used (${error instanceof Error ? error.message : String(error)})`);
|
|
9920
10064
|
}
|
|
10065
|
+
sourceTree = applySemanticPageGrouping(sourceTree);
|
|
9921
10066
|
const deterministicProfile = buildDeterministicOperationalProfile({
|
|
9922
10067
|
sourceTree,
|
|
9923
10068
|
sourceSpans
|
|
@@ -9958,7 +10103,6 @@ async function runSourceTreeExtraction(params) {
|
|
|
9958
10103
|
} catch (error) {
|
|
9959
10104
|
warnings.push(`Operational profile model pass failed; deterministic profile used (${error instanceof Error ? error.message : String(error)})`);
|
|
9960
10105
|
}
|
|
9961
|
-
sourceTree = applyEndorsementGrouping(sourceTree);
|
|
9962
10106
|
const document = materializeDocument({
|
|
9963
10107
|
id: params.id,
|
|
9964
10108
|
sourceTree,
|