/** * @copyright Sister Software * @license AGPL-3.0 * @author Teffen Ellis, et al. * * BIO-stream → AddressTree. * * Two passes: * * 1. Span emission — walk the token stream, group `B-X` followed by `I-X*` into one span. Lenient on * hanging `I-X` (treat as new span). A `B-X` that is whitespace-adjacent to an already-open * `X` span is also folded in (spurious-boundary repair for multi-word values the model * fragments, e.g. "Saint Paul" → B-locality B-locality); a comma/separator between them * keeps them distinct. Span `value` is sliced from `raw` by [start, end), NOT concatenated * from `piece` — this avoids SentencePiece's synthetic leading-space markers in the output. * 2. Parent attachment — for each span, find the nearest labeled span whose tag is the * highest-priority entry in this span's `PARENT_OF` list. Distance is the tiebreaker only. * Spans with no found parent become roots. * * The "nearest" rule (vs "most-recent-prior") is intentional: it makes the decoder independent of * source ordering — e.g. "75004 Paris" attaches postcode to locality even though postcode came * first. Source order is still preserved in the `start`/`end` fields, which the XML serializer * exposes as attributes. */ import type { Calibrator } from "./calibration.ts"; import type { AddressSystem, AddressTree, DecoderToken } from "./types.ts"; /** * Optional caller-supplied attribution stamped on every emitted node. The BIO stream comes from a single model, so * there's no per-span variation — one source for the whole tree. * * Phase 4.3 may overlay a resolver-derived attribution per node on top of this baseline. */ export interface BuildTreeOpts { source?: string; sourceID?: string; /** * Addressing system to decode under — selects the containment hierarchy via `containmentFor`. Stamped onto the * returned `AddressTree.system`. Omit for the default Western hierarchy. Today all systems share one map, so this * only records intent + threads the discriminator; it becomes behavioral when a system-specific map lands (Phase 6 * JP). See `containment.ts`. */ system?: AddressSystem; /** * Optional confidence calibrator (task #59). When provided, each span's mean-of-token-softmax confidence is mapped * through it before being stamped on the node, so `conf=` reports a calibrated probability of correctness rather than * the raw softmax. OPT-IN — omit for the byte-stable default. Build one via `createCalibrator` (`./calibration.ts`). */ calibrate?: Calibrator; } /** * Build an `AddressTree` from a raw input string and the token stream produced by the model. * * @param raw The original input as fed to the tokenizer. * @param tokens Model output: one entry per piece with predicted BIO label + confidence. * @param opts Optional attribution stamped on every emitted node. Callers in the neural pipeline pass `{ source: * "neural", sourceID: }` to mark provenance for the XML serializer's `src` attribute. */ export declare function buildAddressTree(raw: string, tokens: DecoderToken[], opts?: BuildTreeOpts): AddressTree; //# sourceMappingURL=build-tree.d.ts.map