/** * Core matching engine — orchestrates tokenization, normalization, * transliteration, fuzzy matching, and phrase detection. */ import type { DictionaryEntry, DetectionResult, ResolvedConfig, PhraseEntry } from '../types.js'; import { AhoCorasick } from './aho-corasick.js'; interface DictionaryIndex { /** word/normalized/alias → entry (fast O(1) lookup) */ wordMap: Map; /** All dictionary words grouped by first char + length for fuzzy pre-filter */ fuzzyIndex: Map; /** Phrase entries for multi-word detection */ phrases: PhraseEntry[]; /** * Phrase entries indexed by their normalized form. Multi-valued because * distinct entries can normalize to the same key (e.g. accent variants). * Lets `matchPhrases` do an O(1) lookup per window instead of scanning * every phrase entry for every window. */ phrasesByNormalized: Map; /** All canonical words (for fuzzy matching) */ allWords: string[]; /** Aho-Corasick automaton over allowPartialMatch words (all languages) — * O(n + z) multi-pattern scan regardless of dictionary size. */ partialAutomaton: AhoCorasick; /** Whether any partial-match patterns exist (skip scan if empty). */ hasPartialPatterns: boolean; } /** * Build an optimized index from dictionary entries for fast lookup. */ export declare function buildIndex(entries: DictionaryEntry[], phrases?: PhraseEntry[]): DictionaryIndex; /** * Main detection function. Takes text and returns all detected profanity. * * The input is first folded through `unicodeFold` so that confusable * codepoints (Cyrillic/Greek look-alikes) and NFKC-equivalent forms * (fullwidth, mathematical alphanumerics, ligatures) are normalized to ASCII * before tokenization. After detection, result positions are mapped back to * indices in the *original* input via the fold's index map, and `original` * is sliced from the original input — preserving the API contract. */ export declare function detect(originalInput: string, index: DictionaryIndex, config: ResolvedConfig): DetectionResult[]; export {};