/**
 * JSON Block Analyzer for Section-Aware Chunking
 *
 * Analyzes Datalab JSON block hierarchy to identify atomic (unsplittable)
 * regions such as tables, figures, and code blocks. These regions inform
 * the hybrid chunker where it must NOT split text.
 *
 * @module services/chunking/json-block-analyzer
 */
import { PageOffset } from '../../models/document.js';
/** A region in the markdown text that should not be split */
export interface AtomicRegion {
    startOffset: number;
    endOffset: number;
    blockType: string;
    pageNumber: number | null;
}
/**
 * Find atomic (unsplittable) regions in the markdown text by analyzing JSON blocks.
 *
 * Walks the Datalab JSON block tree, locates Table, TableGroup, Figure, FigureGroup,
 * and Code blocks, then finds their approximate positions in the markdown text using
 * fuzzy text matching. Returns sorted, non-overlapping regions.
 *
 * @param jsonBlocks - The JSON block hierarchy from Datalab OCR (may be null)
 * @param markdownText - The full markdown text to search within
 * @param pageOffsets - Page offset information for page number assignment
 * @returns Sorted array of AtomicRegion representing unsplittable text spans
 */
export declare function findAtomicRegions(jsonBlocks: Record<string, unknown> | null, markdownText: string, pageOffsets: PageOffset[]): AtomicRegion[];
/**
 * Check if a character offset falls within an atomic region.
 *
 * Uses binary search on the sorted regions array for efficient lookup.
 *
 * @param offset - The character offset to check
 * @param regions - Sorted array of AtomicRegion (from findAtomicRegions)
 * @returns The containing AtomicRegion, or null if offset is not in any region
 */
export declare function isOffsetInAtomicRegion(offset: number, regions: AtomicRegion[]): AtomicRegion | null;
/** Statistics about block types found in the JSON block hierarchy */
export interface BlockTypeStats {
    total_blocks: number;
    text_blocks: number;
    table_blocks: number;
    figure_blocks: number;
    code_blocks: number;
    list_blocks: number;
    header_blocks: number;
    footer_blocks: number;
    heading_blocks: number;
    page_count: number;
    tables_per_page: number;
    figures_per_page: number;
    text_density: number;
}
/**
 * Walk the JSON block tree and count block types to produce statistics.
 *
 * Recognizes: Text, Table, TableGroup, Figure, FigureGroup, Code,
 * ListItem, List, PageHeader, PageFooter, SectionHeader, Title, Page.
 *
 * @param jsonBlocks - The JSON block hierarchy from Datalab OCR (may be null)
 * @returns BlockTypeStats with counts and derived ratios
 */
export declare function computeBlockTypeStats(jsonBlocks: Record<string, unknown> | null): BlockTypeStats | null;
/**
 * Confidence scores for block types, used to compute chunk quality from
 * the block types present in a chunk. Higher values indicate more structured
 * and typically more reliable content.
 */
export declare const BLOCK_TYPE_CONFIDENCE: Record<string, number>;
/**
 * Compute a confidence score for a chunk based on the block types it contains.
 *
 * Returns the average confidence across all content types in the chunk.
 * Unknown block types default to 0.7. An empty content types array also
 * defaults to 0.7.
 *
 * @param contentTypes - Array of block type strings from the chunk
 * @returns Confidence score between 0 and 1
 */
export declare function computeBlockConfidence(contentTypes: string[]): number;
/** Information about headers and footers detected in the JSON block tree */
export interface HeaderFooterInfo {
    headerTexts: string[];
    footerTexts: string[];
    repeatedHeaders: string[];
    repeatedFooters: string[];
}
/**
 * Detect repeated headers and footers from the JSON block tree.
 *
 * Walks the block tree for each page, collecting PageHeader and PageFooter
 * block texts. A text is considered "repeated" if it appears on >50% of pages
 * with at least 2 occurrences.
 *
 * @param jsonBlocks - The JSON block hierarchy from Datalab OCR (may be null)
 * @returns HeaderFooterInfo with all and repeated header/footer texts
 */
export declare function detectRepeatedHeadersFooters(jsonBlocks: Record<string, unknown> | null): HeaderFooterInfo;
/**
 * Check if a chunk's text closely matches any of the repeated header/footer texts.
 * Uses normalized comparison (lowercased, whitespace-collapsed).
 *
 * @param chunkText - The chunk text to check
 * @param repeatedTexts - Array of repeated header/footer texts
 * @returns true if the chunk text matches a repeated header/footer
 */
export declare function isRepeatedHeaderFooter(chunkText: string, repeatedTexts: string[]): boolean;
/** Extracted structure information for a table block */
export interface TableStructure {
    startOffset: number;
    endOffset: number;
    columnHeaders: string[];
    rowCount: number;
    columnCount: number;
    pageNumber: number | null;
    /** Human-readable summary of table content */
    summary: string;
    /** Values from the first data row (for summary generation) */
    firstRowValues: string[];
    /** Caption text from preceding block (e.g., "Table 1: Budget Summary") */
    caption?: string;
    /** Index of a prior table this continues (cross-page table detection) */
    continuationOf?: number;
}
/**
 * Extract table structures from the JSON block tree.
 *
 * Walks json_blocks for Table/TableGroup blocks, extracts column headers
 * from the first row, and maps to markdown text offsets.
 *
 * @param jsonBlocks - The JSON block hierarchy from Datalab OCR (may be null)
 * @param markdownText - The full markdown text to search within
 * @param pageOffsets - Page offset information for page number assignment
 * @returns Array of TableStructure with column headers and position info
 */
export declare function extractTableStructures(jsonBlocks: Record<string, unknown> | null, markdownText: string, pageOffsets: PageOffset[]): TableStructure[];
/**
 * Extract column headers from the first pipe-delimited row of markdown table text.
 * Fallback when JSON block children don't contain TableRow elements.
 */
export declare function extractHeadersFromMarkdown(tableMarkdown: string): string[];
/**
 * Count table dimensions from markdown pipe-delimited text.
 * Counts data rows (excludes header and separator rows).
 */
export declare function countTableDimensionsFromMarkdown(tableMarkdown: string): {
    rowCount: number;
    columnCount: number;
};
/**
 * Extract values from the first data row (after header and separator) of markdown table.
 */
export declare function extractFirstDataRow(tableMarkdown: string): string[];
/**
 * Generate a human-readable summary of table content.
 * Format: "Table with N rows and columns: col1, col2. Sample: val1, val2"
 * Max 200 chars.
 */
export declare function generateTableSummary(columnHeaders: string[], rowCount: number, firstRowValues: string[], caption?: string): string;
//# sourceMappingURL=json-block-analyzer.d.ts.map