"""Utility module for managing cultural context annotations.""" from typing import Dict, Tuple, List # Initial database of idioms and their cultural context # Format: {idiom: (literal_translation, cultural_explanation)} ENGLISH_IDIOMS: Dict[str, Tuple[str, str]] = { "break the ice": ("شکستن یخ", "To initiate social interaction and reduce tension. In Persian culture, this concept is similar to 'گرم گرفتن' (warm taking) which emphasizes creating a warm, friendly atmosphere."), "costs an arm and a leg": ("به قیمت یک دست و پا", "Very expensive. In Persian, a similar expression is 'سر به فلک کشیدن' (reaching the sky) to describe extremely high prices."), "piece of cake": ("تکه کیک", "Something very easy to do. In Persian culture, the equivalent idiom is 'آب خوردن' (like drinking water) to describe a task that's very simple.") } PERSIAN_IDIOMS: Dict[str, Tuple[str, str]] = { "آب خوردن": ("drinking water", "Used to describe something very easy, similar to the English 'piece of cake'."), "دست و پنجه نرم کردن": ("softening hand and fingers", "To struggle or deal with something difficult, similar to 'wrestling with' in English."), "دیوار موش داره موش هم گوش داره": ("the wall has mice and mice have ears", "Be careful what you say as others might be listening, similar to 'walls have ears' in English.") } def detect_idioms(text: str, source_lang: str) -> List[Tuple[str, str, str]]: """ Detect idioms in the input text and return their cultural context. Returns: List of tuples (idiom, literal_translation, cultural_explanation) """ idioms_db = ENGLISH_IDIOMS if source_lang == "en" else PERSIAN_IDIOMS found_idioms = [] for idiom in idioms_db: if idiom.lower() in text.lower(): found_idioms.append((idiom, *idioms_db[idiom])) return found_idioms def get_cultural_context(text: str, source_lang: str) -> Dict[str, List[Tuple[str, str, str]]]: """ Get cultural context annotations for a given text. Returns: Dictionary with 'idioms' key containing list of detected idioms and their context """ return { 'idioms': detect_idioms(text, source_lang) }