/** * Paper and page text: PDF extraction, sections, quote matching and short * passages. * * Quote matching follows the W3C TextQuoteSelector idea: the matched text plus * a little text before and after it, so a reader can find the place again. It * tries an exact match first, then a match after normalising case, spacing, * quotes, ligatures and hyphens between letters, then the closest passage * with a similarity score. */ export type Section = { heading: string; level: number; text: string; page?: number; }; /** Pages up to this size come back whole; longer ones come back by section. */ export declare const WHOLE_TEXT_CHARS = 40000; /** Split markdown into sections at its headings. Text before the first heading is "(start)". */ export declare function splitSections(markdown: string): Section[]; /** Markdown to plain text: link text without its URL, no emphasis marks or escapes. */ export declare function stripMarkdown(text: string): string; /** Cut a section longer than max at paragraph breaks into parts, so no one reply is unbounded. */ export declare function splitLongSection(section: Section, max: number): Section[]; /** A line that reads as a section heading in PDF text: "2 SPADL: A LANGUAGE ...", "3.1 Data", "ABSTRACT". */ export declare function headingLevel(line: string): number; /** * Sections of a PDF from its page texts. Headings are found by the rules in * headingLevel; a heading in capitals that wraps onto a second line in * capitals is joined. With fewer than three headings, the sections are pages. */ export declare function pdfSections(pages: string[]): Section[]; export type PdfText = { pages: string[]; title?: string; author?: string; doi?: string; }; /** Text of every page of a PDF, with the title, author and first DOI it states. */ export declare function readPdf(data: Uint8Array): Promise; export declare function isPdf(data: Uint8Array): boolean; export declare function outline(sections: Section[]): string; export declare function sectionText(section: Section): string; /** Whole text when short, else the outline and the first sections that fit. */ export declare function renderFull(sections: Section[], requested?: number): { lines: string[]; isError?: boolean; }; /** Normalised text plus, for each of its characters, the index in the original. */ export type Normalised = { text: string; map: number[]; }; /** * Lower case, one space for any run of white space, plain quotes, ligatures * expanded, soft hyphens and hyphens between letters removed, markdown * emphasis and link brackets dropped. */ export declare function normalise(input: string): Normalised; export type QuoteMatch = { kind: "exact" | "normalised" | "close" | "none"; /** 1 for exact and normalised matches; the similarity of the closest passage otherwise. */ score: number; /** Offsets in the original text. */ start: number; end: number; }; /** The score a closest passage needs to count as a close match. */ export declare const CLOSE_MATCH_SCORE = 0.85; /** Find a quote in a text. Offsets refer to the text as given. */ export declare function findQuote(source: string, quote: string): QuoteMatch; /** Text before and after a span, cut at word boundaries. */ export declare function context(source: string, start: number, end: number, chars: number): { prefix: string; suffix: string; }; /** Up to `limit` passages of at most `cap` characters around the places a query's terms occur together. */ export declare function passages(source: string, query: string, cap: number, limit?: number): string[];