@claritylabs/cl-sdk 3.0.14 → 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.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) || /^IMPORTANT NOTICE\s*[-—]\s*/i.test(cleaned) || /^THIS IS A CLAIMS-MADE AND REPORTED POLICY\.? PLEASE READ IT CAREFULLY\.?$/i.test(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
- return metadataString(node.metadata, "elementType") === "title" || metadataString(node.metadata, "sourceUnit") === "title";
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: "section",
2698
+ kind: "text",
2688
2699
  title,
2689
2700
  description: nodeTextDescription({
2690
- kind: "section",
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 < 2) return params.sourceTree;
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 < 2) return params.sourceTree;
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
  }