/** * Base Processor for AAC File Formats * * This module provides base functionality for processing AAC (Augmentative and Alternative * Communication) files across various formats (gridset, OBF, Snap, TouchChat, etc.). * * ## LLM-Based Translation with Symbol Preservation * * All processor formats support LLM-based translation that preserves symbol-to-word * associations across languages. This is critical for AAC systems where visual symbols * are attached to specific words. * * ### Usage Example: * * ```typescript * import { extractAllButtonsForTranslation, createTranslationPrompt } from '../optional/translation/translationProcessor'; * * // 1. Extract buttons from your format * const buttons = extractAllButtonsForTranslation(myFormatButtons, (button) => ({ * pageId: button.pageId, * pageName: button.pageName * })); * * // 2. Create prompt for LLM * const prompt = createTranslationPrompt(buttons, 'Spanish'); * * // 3. Send to LLM (Gemini, GPT, etc.) and get response * const llmResponse = await callLLMAPI(prompt); * * // 4. Apply translations to your format * processor.processLLMTranslations(filePath, llmResponse, outputPath); * ``` * * ### Format-Specific Implementation: * * Each processor should implement: * - `extractSymbolsForLLM()` - Uses extractAllButtonsForTranslation() utility * - `processLLMTranslations()` - Applies translations using format-specific logic * * See `src/utilities/translation/translationProcessor.ts` for shared utilities. */ import { AACTree, AACButton } from './treeStructure'; import { StringCasing } from './stringCasing'; import { ValidationResult } from '../validation/validationTypes'; import { BinaryOutput, FileAdapter, ProcessorInput } from '../utils/io'; import { ZipAdapter } from '../utils/zip'; import type { ProcessorCapabilities } from '../types/aac'; export interface ProcessorConfig { excludeNavigationButtons?: boolean; excludeSystemButtons?: boolean; gridsetPassword?: string; customButtonFilter?: (button: AACButton) => boolean; preserveAllButtons?: boolean; grid3SymbolDir?: string; grid3Path?: string; grid3Locale?: string; fileAdapter: FileAdapter; zipAdapter: (input?: ProcessorInput, fileAdapter?: FileAdapter) => Promise; } export type ProcessorOptions = Partial; export interface ExtractedString { string: string; vocabPlacementMeta: VocabPlacementMetadata; } export interface VocabPlacementMetadata { vocabLocations: VocabLocation[]; } export interface VocabLocation { table: string; id: string | number; column: string; casing: StringCasing; } export interface ProcessingError { message: string; step: 'EXTRACT' | 'PROCESS' | 'SAVE'; } export interface ExtractStringsResult { errors: ProcessingError[]; extractedStrings: ExtractedString[]; } export interface TranslatedString { sourcestringid: number; overridestring: string; translatedstring: string; } export interface SourceString { id: number; sourcestring: string; vocabplacementmetadata: VocabPlacementMetadata; } declare abstract class BaseProcessor { protected options: ProcessorConfig; abstract readonly capabilities: ProcessorCapabilities; constructor(options?: ProcessorOptions); abstract extractTexts(filePathOrBuffer: ProcessorInput): Promise; abstract loadIntoTree(filePathOrBuffer: ProcessorInput): Promise; abstract processTexts(filePathOrBuffer: ProcessorInput, translations: Map, outputPath: string): Promise; abstract saveFromTree(tree: AACTree, outputPath: string): Promise; validate?(filePath: string): Promise; /** * Extract strings with metadata for external platform integration * @param filePath - Path to the AAC file * @returns Promise with extracted strings and any errors */ extractStringsWithMetadata?(filePath: string): Promise; /** * Generate translated download with external translation data * @param filePath - Path to the original AAC file * @param translatedStrings - Array of translated string data * @param sourceStrings - Array of source string data with metadata * @returns Promise with path to the generated translated file */ generateTranslatedDownload?(filePath: string, translatedStrings: TranslatedString[], sourceStrings: SourceString[]): Promise; protected shouldFilterButton(button: AACButton): boolean; protected filterPageButtons(buttons: AACButton[]): AACButton[]; /** * Generic implementation for extracting strings with metadata * Can be used by any processor that doesn't need format-specific logic * @param filePath - Path to the AAC file * @returns Promise with extracted strings and metadata */ protected extractStringsWithMetadataGeneric(filePath: string): Promise; /** * Generic implementation for generating translated downloads * Can be used by any processor that doesn't need format-specific logic * @param filePath - Path to the original AAC file * @param translatedStrings - Array of translated string data * @param sourceStrings - Array of source string data * @returns Promise with path to the generated translated file */ protected generateTranslatedDownloadGeneric(filePath: string, translatedStrings: TranslatedString[], sourceStrings: SourceString[]): Promise; /** * Helper method to add extracted strings to the map, handling duplicates * @param extractedMap - Map to store extracted strings * @param key - Lowercase key for deduplication * @param originalString - Original string with proper casing * @param vocabLocation - Metadata about where the string was found */ protected addToExtractedMap(extractedMap: Map, key: string, originalString: string, vocabLocation: VocabLocation): void; /** * Generate output path for translated file based on input file extension * @param filePath - Original file path * @returns Path for the translated output file */ protected generateTranslatedOutputPath(filePath: string): string; } export { BaseProcessor };