BMW 218 218d xDrive GT +++++ src/main.py import re from typing import List, Dict, Tuple, Optional from pathlib import Path import json from src.utils import load_json, save_json, load_text, save_text from src.translator import translate_text from src.constants import ( INPUT_DIR, OUTPUT_DIR, TRANSLATIONS_FILE, SERBIAN_LATIN_ALPHABET, SERBIAN_CYRILLIC_ALPHABET, SERBIAN_LATIN_TO_CYRILLIC_MAP, SERBIAN_CYRILLIC_TO_LATIN_MAP, SERBIAN_LATIN_REGEX, SERBIAN_CYRILLIC_REGEX, SERBIAN_LATIN_EXCEPTIONS, SERBIAN_CYRILLIC_EXCEPTIONS, SERBIAN_LATIN_EXCEPTION_MAP, SERBIAN_CYRILLIC_EXCEPTION_MAP, ) def convert_script( text: str, source_script: str, target_script: str, exceptions: Optional[Dict[str, str]] = None, ) -> str: """ Convert text from one script to another (Latin <-> Cyrillic). Args: text: Input text to convert. source_script: Source script ('latin' or 'cyrillic'). target_script: Target script ('latin' or 'cyrillic'). exceptions: Optional dictionary of exceptions to override default conversion. Returns: Converted text in the target script. """ if source_script == target_script: return text if source_script == "latin" and target_script == "cyrillic": conversion_map = SERBIAN_LATIN_TO_CYRILLIC_MAP.copy() if exceptions: conversion_map.update(exceptions) regex = SERBIAN_LATIN_REGEX elif source_script == "cyrillic" and target_script == "latin": conversion_map = SERBIAN_CYRILLIC_TO_LATIN_MAP.copy() if exceptions: conversion_map.update(exceptions) regex = SERBIAN_CYRILLIC_REGEX else: raise ValueError("Invalid script conversion direction") def replace_match(match): matched_text = match.group(0) return conversion_map.get(matched_text, matched_text) return regex.sub(replace_match, text) def process_file( input_path: Path, output_path: Path, translations: Dict[str, str], source_script: str, target_script: str, ) -> None: """ Process a single file: translate and convert script if needed. Args: input_path: Path to the input file. output_path: Path to save the processed file. translations: Dictionary of translations. source_script: Source script ('latin' or 'cyrillic'). target_script: Target script ('latin' or 'cyrillic'). """ text = load_text(input_path) # Translate the text translated_text = translate_text(text, translations) # Convert script if needed if source_script != target_script: if source_script == "latin": exceptions = SERBIAN_LATIN_EXCEPTION_MAP else: exceptions = SERBIAN_CYRILLIC_EXCEPTION_MAP converted_text = convert_script( translated_text, source_script, target_script, exceptions ) else: converted_text = translated_text save_text(output_path, converted_text) def process_directory( input_dir: Path, output_dir: Path, translations: Dict[str, str], source_script: str, target_script: str, ) -> None: """ Process all files in the input directory. Args: input_dir: Path to the input directory. output_dir: Path to the output directory. translations: Dictionary of translations. source_script: Source script ('latin' or 'cyrillic'). target_script: Target script ('latin' or 'cyrillic'). """ output_dir.mkdir(parents=True, exist_ok=True) for input_path in input_dir.glob("*"): if input_path.is_file(): output_path = output_dir / input_path.name process_file( input_path, output_path, translations, source_script, target_script ) def main() -> None: """ Main function to run the translation and script conversion process. """ # Load translations translations = load_json(TRANSLATIONS_FILE) # Process files in the input directory process_directory(INPUT_DIR, OUTPUT_DIR, translations, "latin", "latin") if __name__ == "__main__": main() +++++ src/translator.py import re from typing import Dict, List, Tuple, Optional from src.constants import ( PROPER_NOUN_PATTERNS, UPPERCASE_WORD_PATTERNS, NUMBER_PATTERNS, URL_PATTERN, EMAIL_PATTERN, BRAND_PATTERNS, ADDRESS_PATTERNS, ) def is_proper_noun(word: str, context: str) -> bool: """ Check if a word is a proper noun based on patterns and context. Args: word: The word to check. context: The surrounding text for context. Returns: True if the word is likely a proper noun, False otherwise. """ # Check if the word matches any proper noun patterns for pattern in PROPER_NOUN_PATTERNS: if re.fullmatch(pattern, word): return True # Check if the word is part of a brand name for pattern in BRAND_PATTERNS: if re.search(pattern, context): return True # Check if the word is part of an address for pattern in ADDRESS_PATTERNS: if re.search(pattern, context): return True return False def is_uppercase_word(word: str) -> bool: """ Check if a word is in uppercase and should be translated. Args: word: The word to check. Returns: True if the word is in uppercase and should be translated, False otherwise. """ # Check if the word matches any uppercase word patterns for pattern in UPPERCASE_WORD_PATTERNS: if re.fullmatch(pattern, word): return True return False def should_translate_word(word: str, context: str) -> bool: """ Determine if a word should be translated based on various checks. Args: word: The word to check. context: The surrounding text for context. Returns: True if the word should be translated, False otherwise. """ # Check if the word is a number for pattern in NUMBER_PATTERNS
13 990 EUR
BMW 218 · 2018 · 154 010 km · diesel · automatic · 13 990 EUR · Svilajnac
Karakteristike
- Marka: BMW
- Model: 218
- Godište: 2018
- Kilometraža: 154 010 km
- Gorivo: diesel
- Menjač: automatic
- Zapremina motora: 1995 cm³
- Snaga: 150 KS
- Karoserija: minivan
- Grad: Svilajnac
Opis
*****BMW 218d xDRIVE GRAN TOURER*****
*Uvoz iz Švajcarske
*Originalna kilometraža sa servisnom knjižicom
*Pismena garancija na pređenu kilometražu i na legalnost vozila sa pečatom firme
***Godina proizvodnje 2018. Datum prve registracije 06.11.2018***
*****Garancija na motor i menjač 2 godine ili pređenih 20.000 km*****
*Plaćeni su svi troškovi kupcu ostaje samo trošak registracije
*Besplatne probne tablice ili prevoz do kupca!!!!
***Moguća svaka provera!! Broj šasije: WBA6X11000EN07135!!***
Bezbednost: Vazdušni jastuk za vozača, Vazdušni jastuk za suvozača, Bočni vazdušni jastuk, Dečija brava, ABS, ESP, ASR, Kodirani ključ, Centralno zaključavanje, Ulazak bez ključa, Automatsko kočenje
Oprema: Metalik boja, Branici u boji automobila, Servo volan, Multifunkcionalni volan, Tempomat, Daljinsko zaključavanje, Putni računar, Zatamnjena stakla, Električni podizači prozora, Električni retrovizori, Grejači retrovizora, Sedista podesiva po visini, Električno podešavanje sedišta, Grejanje sedišta, Maglene svetiljke, Ksenon svetla, Senzori za svetlo, Senzori za kišu, Parking senzori, Aluminijumske felne
Slični oglasi
feed