/** * A corpus's train-split shapes and surfaces, counted once beside its manifest * and queried per gauntlet row. * * Whether a corpus supported a row used to take a scan of every train row, * about 8 minutes per 700 M-row corpus, through a reader written for the question. * This index answers the three questions that scan answered: the train rows of a country * that hold a given set of component tags, the rows that hold a surface under each tag, * and the rows that hold a word at the head or tail of an open-class span. * * Rows are attributed to the train split the way `countHoldoutSpans` attributes them, * with the manifest's deletions removed, so a count here is a count the trainer read. */ import { type ComponentTag } from "@mailwoman/codex/component"; import { type DisposableDuckDB, type DuckDBLimits } from "#parquet/duckdb"; import { type CorpusDeletion } from "#tools/overlay/deletions"; /** * The directory beside a manifest that holds its support index. */ export declare const SUPPORT_INDEX_DIRECTORY = "support-index"; /** * The record a finished index writes last, so its presence marks the index complete. */ export declare const SUPPORT_INDEX_RECORD = "SUPPORT_INDEX.json"; /** * The record's layout version, raised when a column or a fold changes meaning. */ export declare const SUPPORT_INDEX_VERSION = 1; /** * The tags whose span comes from a bounded vocabulary, indexed by whole folded surface. */ export declare const CLOSED_CLASS_TAGS: readonly ComponentTag[]; /** * The tags whose span is open vocabulary, indexed by the folded first and last word. * * A whole venue or street name would make the surface table as large as the corpus. */ export declare const OPEN_CLASS_TAGS: readonly ComponentTag[]; /** * Every component tag belongs to one class. * * A tag added to the vocabulary without a class would be left out of the index without a trace. */ export declare function unclassifiedTags(): ComponentTag[]; /** * The fold applied to every indexed surface and to every queried value. * * It runs in SQL so the index and the query share one implementation. * DuckDB folds canonical forms (NFC) rather than compatibility forms, so a fullwidth * letter stays distinct from its ASCII form here. */ export declare function foldSurfaceSQL(expression: string): string; /** * How a span's surface entered the index: whole, or by its first or last word. */ export type SurfacePosition = "whole" | "first" | "last"; /** * What a finished index records about itself. */ export interface SupportIndexRecord { version: number; manifest: string; corpus_version: string | null; taken_at: string; elapsed_ms: number; files_listed: number; files_read: number; /** * Files the manifest records as `val` or `test`, read by no train row. */ files_held_out: number; train_rows: number; fold: string; closed_class_tags: string[]; open_class_tags: string[]; shapes_file: string; surfaces_file: string; shape_entries: number; surface_entries: number; } export interface BuildSupportIndexOptions { /** * Where the index is written. * * @defaultValue `support-index` beside the manifest. */ outDir?: string; /** * Stop after N train files have been read, for a smoke run. * * Held-out files are skipped without counting, and the record states the number of files read. */ limitFiles?: number; limits?: DuckDBLimits; log?: (line: string) => void; } /** * The index directory for a manifest. */ export declare function supportIndexDirectoryFor(manifestPath: string): string; /** * The record of a finished index, or `null` when the directory holds none. */ export declare function readSupportIndexRecord(indexDir: string): Promise; /** * One file as a corpus manifest lists it. */ export type TrainManifestFile = Record & { path: string; source?: string; }; /** * Stages one manifest file's train rows as the temporary table `r`, projected by * `projection` and narrowed by the SQL predicate `rowFilter`, and returns their count, * or `null` for a file the manifest records as `val` or `test`. * * A file decided by a split attribute contributes the rows the attribute lists under * neither held-out split, and a file a manifest deletion targets loses the deleted ids. * The caller's connection must hold an `excluded_ids (id VARCHAR)` table. * This function empties and refills it. * * @throws When the file records neither a split nor a split attribute, since reading * it as train or skipping it would both misstate the count. */ export declare function stageTrainRows(db: DisposableDuckDB, manifestPath: string, file: TrainManifestFile, deletions: readonly CorpusDeletion[], projection: string, limits?: DuckDBLimits, rowFilter?: string): Promise; /** * Count a corpus's train-split shapes and surfaces and write them beside its manifest. * * Each manifest file is read once through DuckDB. * A file recorded as `val` or `test` is skipped. * * A file decided by a split attribute contributes the rows the attribute lists under * neither held-out split, and a file a manifest deletion targets loses the deleted ids. * * @throws When a manifest file records neither a split nor a split attribute, * since reading it as train or skipping it would both misstate the count. */ export declare function buildSupportIndex(manifestPath: string, options?: BuildSupportIndexOptions): Promise; /** * One row to read support for: its country and the components it expects. */ export interface SupportQueryRow { id: string; country: string | null; components: Readonly>; } /** * One word of an open-class value and the (tag, position) entries that hold it. * * A key is the tag for a whole-surface entry and `tag/position` for a head or tail entry. */ export interface WordSupport { position: "first" | "last"; word: string; under: Record; } /** * The train support for one expected component. * * - `closed`: `own_rows` is the rows holding the folded value under the expected tag, * and `under_tags` the rows holding it under every tag. * - `open`: the value is read by its first and last word in `words`, and `own_rows` is `null`. * - `unindexed`: the tag belongs to neither class, so the reading is empty rather than zero. */ export interface ComponentSupport { tag: string; value: string; kind: "closed" | "open" | "unindexed"; own_rows: number | null; under_tags: Record; words: WordSupport[]; } export interface SupportRowReading { id: string; country: string | null; /** * The row's expected tags, sorted and joined with `|`, which is how the index keys a shape. */ tag_set: string; /** * Train rows of the country whose tag set is exactly `tag_set`, or `null` * when the row states no country and couldn't be probed. */ shape_rows: number | null; shape_sources: Array<{ source: string; rows: number; }>; components: ComponentSupport[]; rendered: string; } /** * Renders one row's support on one line, for a transcript a human reads without a paraphrase. */ export declare function renderSupportRow(row: Omit): string; /** * Read the train support of each row from a finished index. * * Every probe is folded by the index's own SQL fold and joined in one pass per table, * so a board of a thousand rows is two scans rather than thousands. * * @throws When the directory holds no finished record. */ export declare function querySupport(indexDir: string, rows: readonly SupportQueryRow[], limits?: DuckDBLimits): Promise; //# sourceMappingURL=support-index.d.ts.map