/** * Language-Aware Extraction (INT-011) * * Provides language detection and multi-language field mapping for content extraction. * Enables extraction of content from pages in any language with automatic field name translation. * * Key Features: * - Auto-detect page language from HTML attributes, meta tags, and content analysis * - Map common field names across languages (e.g., "requisitos" -> "requirements") * - Extensible to any language through the field mapping registry * - Confidence scoring for language detection */ import type { ContentMapping } from '../types/api-patterns.js'; /** * Result of language detection */ export interface LanguageDetectionResult { /** Detected ISO 639-1 language code (e.g., "en", "es", "de") */ language: string; /** Confidence in the detection (0-1) */ confidence: number; /** How the language was detected */ source: LanguageDetectionSource; /** Full locale if available (e.g., "en-US", "es-ES") */ locale?: string; } export type LanguageDetectionSource = 'html-lang' | 'meta-content-language' | 'og-locale' | 'content-analysis' | 'url-pattern' | 'unknown'; /** * Extended ContentMapping with multi-language support */ export interface LanguageAwareContentMapping extends ContentMapping { /** * Language-specific field overrides * Maps ISO 639-1 codes to partial ContentMapping overrides */ languageFieldMap?: Record>; } /** * Field category for semantic grouping */ export type FieldCategory = 'title' | 'description' | 'body' | 'requirements' | 'documents' | 'fees' | 'timeline' | 'application' | 'status' | 'contact' | 'address' | 'date' | 'deadline' | 'price' | 'name' | 'author' | 'summary'; /** * Detect the language of an HTML page * * Detection order (by reliability): * 1. html lang attribute (most reliable) * 2. Content-Language meta tag * 3. Open Graph locale * 4. URL patterns (subdomain or path) * 5. Content analysis (least reliable) * * @param html - The HTML content to analyze * @param url - Optional URL for pattern-based detection * @returns Language detection result with confidence */ export declare function detectPageLanguage(html: string, url?: string): LanguageDetectionResult; /** * Extract ISO 639-1 language code from a locale string */ export declare function extractLanguageCode(locale: string): string; /** * Multi-language field name registry * Maps English field names to their equivalents in other languages * * Supported languages (40+): * - Western European: en, es, pt, de, fr, it, nl * - Nordic: sv, no, da, fi, is * - Eastern European: pl, cs, sk, hu, ro, bg, hr, sl, sr, uk, ru, be * - Baltic: lt, lv, et * - Asian: zh, ja, ko, vi, th, id, ms, tl * - Middle Eastern: ar, he, tr, fa * - South Asian: hi, bn, ta * - Greek: el */ export declare const FIELD_TRANSLATIONS: Record>; /** * Get field name variants for a given category and language * * @param category - The semantic field category * @param language - The target language code (ISO 639-1) * @returns Array of field name variants in that language */ export declare function getFieldVariants(category: FieldCategory, language: string): string[]; /** * Get all field name variants for a category across all supported languages */ export declare function getAllFieldVariants(category: FieldCategory): string[]; /** * Translate a field name from one language to another * * @param fieldName - The field name to translate * @param fromLanguage - Source language (or 'auto' to detect) * @param toLanguage - Target language * @returns Translated field name or original if no translation found */ export declare function translateFieldName(fieldName: string, fromLanguage: string | 'auto', toLanguage: string): string; /** * Detect the semantic category of a field name * * @param fieldName - The field name to categorize * @returns The detected category or undefined if not recognized */ export declare function detectFieldCategory(fieldName: string): FieldCategory | undefined; /** * Create a language-aware content mapping from a base mapping * * @param baseMapping - The base content mapping (typically English) * @param targetLanguage - The target language for the mapping * @returns A content mapping with language-appropriate field names */ export declare function createLanguageAwareMapping(baseMapping: ContentMapping, targetLanguage: string): ContentMapping; /** * Extract content with language awareness * Tries field names in the detected language first, then falls back to English * * @param data - The data object to extract from * @param fieldCategory - The semantic category of the field to extract * @param language - The detected page language * @returns The extracted value or null */ export declare function extractFieldByCategory(data: unknown, fieldCategory: FieldCategory, language: string): unknown; /** * Extract content from a data object using language-aware field detection * * @param data - The data object to extract from * @param language - The detected page language * @returns Extracted title, description, and body */ export declare function extractContentLanguageAware(data: unknown, language: string): { title: string | null; description: string | null; body: string | null; }; export declare const LanguageAwareExtraction: { detectPageLanguage: typeof detectPageLanguage; extractLanguageCode: typeof extractLanguageCode; getFieldVariants: typeof getFieldVariants; getAllFieldVariants: typeof getAllFieldVariants; translateFieldName: typeof translateFieldName; detectFieldCategory: typeof detectFieldCategory; createLanguageAwareMapping: typeof createLanguageAwareMapping; extractFieldByCategory: typeof extractFieldByCategory; extractContentLanguageAware: typeof extractContentLanguageAware; FIELD_TRANSLATIONS: Record>; }; //# sourceMappingURL=language-aware-extraction.d.ts.map