/** * @file Chooses the WOF rows a {@link RowSample} keeps, from one pass over every renderable row. */ import type { ComponentTag } from "@mailwoman/codex/component"; import type { RowSample } from "#types"; /** * The `count` lowest numbers seen, held in a max-heap so each new number costs * one comparison once the heap is full. * * A number added with a `text` value that a held number already contains is skipped, * so the held numbers stand for `count` distinct texts. * The build drops a row whose text repeats an emitted row, and a floor counted over * repeated texts would lose those rows after sampling. */ export declare class LowestValues { #private; constructor(count: number); /** * Adds `value`, and returns whether it is now held. */ add(value: number, text?: number): boolean; /** * The highest number a kept value may have: the largest held when the heap is full, * otherwise every value passes. */ get threshold(): number; } /** * The tags of a rendered row in the order the aligner places them, such as `locality region country`, * or `null` when the aligner cannot place a component and would quarantine the row. * * {@linkcode locateComponentSpans}, the aligner's own span search, determines the order. * It orders a region that appears inside its locality's name (`ہیرسبرک، شمالی کیرولائنا` * before `شمالی کیرولائنا`) by its own span, matching the training row's span order. */ export declare function renderedTagOrder(raw: string, components: Partial>): string | null; /** * One renderable row, as the sampler sees it. */ export interface SampledRow { sourceID: string; country: string; slotKey: string; raw: string; components: Partial>; } /** * Picks the rows a {@link RowSample} keeps, and counts every cell it saw, in one pass. * * Call {@linkcode RowSampler.observe} on every renderable row with the value to * emit for it, then read {@linkcode RowSampler.kept}. * A row is kept when its hash is at or below the threshold of its structure cell * (country, tag order, name-slot kind), of its language cell (country, name-slot language) or of its country. * * The sampler holds a row while one of its cells' heaps holds its hash. * A heap of k values filled in random hash order admits about k ln(n / k) of its n rows * over the pass, so the held rows stay a small multiple of the kept ones. */ export declare class RowSampler { #private; /** * Renderable rows per full cell, `country|tag order|kind|language`. */ readonly cellCounts: Map; constructor(sample: RowSample); /** * Counts `row` in its cells and holds `payload` while one of its cells may keep it. * * A `required` row is kept whatever its hash, unless its cell is held out. * It still enters its cells' heaps as any other row does, so requiring it * moves no other row's keep decision. */ observe(row: SampledRow, payload: T, required?: boolean): void; /** * Counts a row its caller emits itself, whatever its hash, and returns whether the caller may emit it. * * The row enters its cells' heaps as a required row does, so emitting it * moves no other row's keep decision. * The sampler holds no payload for it, so emitting a row of every place adds * no row to the sampler's memory. * * A row the aligner would quarantine, or a row in a held-out cell, returns false: * the first is dropped and the second is held out as {@linkcode RowSampler.observe} holds it. */ observeEmitted(row: SampledRow, payload: T): boolean; /** * The payloads of the held-out rows, at most `heldOutPerCell` per `holdOutCells` entry, * none with the case-folded text of a kept row, in the order they were observed. */ heldOut(): Generator; /** * The payloads of unkept rows from `compareCells`, at most `heldOutPerCell` per entry, * none with the case-folded text of a kept row, in the order they were observed. */ comparison(): Generator; /** * The payloads of the kept rows, in the order they were observed. */ kept(): Generator; /** * Writes {@linkcode RowSampler.cellCounts} to the sample's `countsFile` and * {@linkcode RowSampler.heldOut} to its `heldOutFile`, and {@linkcode RowSampler.comparison} * to its `comparisonFile`, each when the sample identifies one. */ writeOutputs(): Promise; } //# sourceMappingURL=sample.d.ts.map