/** * Symbol Alignment for Translation * * Utilities to preserve symbol positions during text translation. * When translating AAC gridset messages that contain symbols attached * to specific words, we need to maintain the symbol-to-word associations * across languages. * * Example: * English: "I want apple juice" with apple symbol on "apple" * Spanish: "Yo quiero jugo de manzana" with apple symbol on "manzana" */ /** * Represents a symbol anchored to a specific word in the text */ export interface SymbolAnchor { symbolRef: string; wordIndex: number; originalWord: string; startPos: number; endPos: number; } /** * Parsed message with symbol anchors */ export interface ParsedMessage { text: string; words: string[]; symbols: SymbolAnchor[]; } /** * Translation result with preserved symbols */ export interface TranslatedMessage { text: string; alignment: { originalWord: string; translatedWord: string; originalIndex: number; translatedIndex: number; }[]; } /** * Parse a message to extract text and symbol anchors. * * This handles various formats: * 1. Plain text with no symbols * 2. Rich text with embedded symbol markers (future enhancement) * 3. Text where symbols are tracked separately (via richText.symbols) * * For now, this assumes symbols are tracked separately in the richText structure. * The text itself is plain, and we need to tokenize it to find word positions. * * @param message - The message text (may contain words or be plain) * @param richTextSymbols - Optional symbols from richText.symbols array * @returns Parsed message with word positions and symbol anchors */ export declare function parseMessageWithSymbols(message: string, richTextSymbols?: Array<{ text: string; image?: string; }>): ParsedMessage; /** * Align words from original text to translated text. * * This is a simple alignment strategy that works for many cases: * 1. Exact word matching (for cognates, names, numbers) * 2. Position-based alignment (assumes similar word order) * * For more accurate alignment, you could integrate with: * - Translation APIs that return alignment (e.g., Google Translate's word alignment) * - Statistical machine translation alignment tools * - Bilingual dictionaries * * @param originalWords - Words from the original text * @param translatedWords - Words from the translated text * @returns Alignment mapping between original and translated word indices */ export declare function alignWords(originalWords: string[], translatedWords: string[]): TranslatedMessage['alignment']; /** * Reattach symbols to translated text based on word alignment. * * @param translatedText - The translated plain text * @param originalParsed - The original parsed message with symbols * @param alignment - Word alignment between original and translation * @returns Translated text with symbols embedded (as rich text structure) */ export declare function reattachSymbols(translatedText: string, originalParsed: ParsedMessage, alignment: TranslatedMessage['alignment']): { text: string; richTextSymbols: Array<{ text: string; image?: string; }>; }; /** * Complete pipeline: translate a message while preserving symbol positions. * * @param originalMessage - The original message text * @param translatedText - The translated text (from translation API) * @param richTextSymbols - Original symbols from richText.symbols * @returns Object with translated text and aligned symbols */ export declare function translateWithSymbols(originalMessage: string, translatedText: string, richTextSymbols?: Array<{ text: string; image?: string; }>): { text: string; richTextSymbols: Array<{ text: string; image?: string; }>; }; /** * Extract symbols from a button for use during translation. * * This helper extracts symbols from either: * - button.semanticAction.richText.symbols * - button.image (if it's a symbol library reference) * * @param button - The AAC button * @returns Array of symbol attachments */ export declare function extractSymbolsFromButton(button: any): Array<{ text: string; image?: string; }> | undefined;