/** * @copyright Sister Software * @license AGPL-3.0 * @author Teffen Ellis, et al. */ import type { Displayable } from "../resources/debugging.ts"; import type { Alpha3bLanguageCode } from "../resources/languages/index.ts"; import type { LibPostalLanguageCode } from "../resources/libpostal.ts"; import { type Classification, type ClassificationMatch, ClassificationsMatchMap } from "../types/Classification.ts"; import { Graph } from "./Graph.ts"; export interface SpanCreationOptions { start?: number; classifications?: Iterable; children?: Iterable; } declare const kSpanID: unique symbol; export interface SerializedSpan { body: string; start: number; end: number; normalized: string; classifications: ClassificationMatch[]; children: SerializedSpan[]; phrases: SerializedSpan[]; } /** * A span of text, i.e. a token or a phrase. */ export declare class Span extends Graph { #private; /** * The start index of the span. */ start: number; /** * The end index of the span. */ end: number; /** * The unique identifier for this span. */ protected static IDCounter: number; /** * The unique identifier for this span. */ readonly [kSpanID]: number; get id(): number; /** * The normalized body of the span. */ normalized: string; /** * Classifications for this span. */ readonly classifications: ClassificationsMatchMap; /** * Boolean-like indications that hint at the nature of the span. * * Unlike classifications, these are not exposed in the final output. */ get flags(): ReadonlySet; is(classification: Classification): boolean; static from(input?: string, options?: SpanCreationOptions): Span; static from(input: Span, options?: Omit): Span; static from(input: Span | string, options?: SpanCreationOptions): Span; constructor(body?: string, start?: number); get body(): string; /** * Set the body of the Span */ set body(nextBody: string); /** * Predicate to determine if this Span intersects another Span */ intersects(that: Pick): boolean; /** * Predicate to determine if this Span covers another Span */ covers(that: Pick): boolean; /** * Returns the distance between two Spans * * @todo Use graph to find prev and next spans for a more accurate result * @todo Or base 'distance' on word distance (slop) rather than characters */ distance(that: Pick): number; /** * Returns the coverage of the span, i.e. the number of characters covered by the span and its children. */ get coverage(): number; /** * The combined languages of the span's children. */ get languages(): Displayable>; /** * Serialize the span to JSON. */ toJSON(): SerializedSpan; toString(): string; /** * Connect siblings in the graph. */ static connectSiblings(...spans: Span[]): Span[]; } export type SpanFlag = "ends_with_period" | "numeric" | "alpha" | "alphanumeric" | "numeral" | "punctuation"; /** * Patterns to test and apply classifications to spans. * * Note that order here is important, as the first pattern that matches will be used. */ export declare const PatternMatchers: readonly [pattern: RegExp, flag: SpanFlag][]; export {}; //# sourceMappingURL=Span.d.ts.map