BMV Ks1 20 d N.A.V.I
6 850 EUR
BMW X1 · 2010 · 191 000 km · diesel · manual · 6 850 EUR · Pančevo
Karakteristike
- Marka: BMW
- Model: X1
- Godište: 2010
- Kilometraža: 191 000 km
- Gorivo: diesel
- Menjač: manual
- Zapremina motora: 1995 cm³
- Snaga: 177 KS
- Karoserija: suv
- Grad: Pančevo
Slični oglasi
- BMV 640D — 2018 · Budva · 14 000 EUR
- Bmw E90 316d 2010. godine 85 kW 6 brzina — 2010 · Šabac · 6 000 EUR
- BMV 320i — 2009 · Đurđevo · 7 490 EUR
- BMW X3 2.0 (može zamena) — 2011 · 200 184 km · Futog · 10 250 EUR
- BMV Ks6 40d kDrive — 2013 · 242 284 km · Beograd · 16 490 EUR
- BMW X3 2.0d M PAKET — 2008 · 174 521 km · Svilajnac · 7 990 EUR
- 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 — 2018 · 154 010 km · Svilajnac · 13 990 EUR
- BMW X5 45e xDrive M paket (može zamena) — 2022 · 106 287 km · Beograd · 61 990 EUR
- BMV 418 (moguća zamena) — 2016 · 250 000 km · Niš · 13 800 EUR
- BMV Ks5 2.0KSD LEDNAV/KUKA — 2014 · 255 920 km · Novi Sad · 19 000 EUR
- BMV 320 M kdrive paket — 2021 · 71 600 km · Obrenovac · 36 800 EUR
- BMW X4 xDrive, M paket — 2021 · 190 000 km · Vidikovac · 34 190 EUR
- BMV Ks3 2.0 n.o.v — 2013 · 191 725 km · Novi Sad · 10 500 EUR
- BMW X4 M paket (može zamena) — 2018 · 188 000 km · Subotica · 22 500 EUR
- BMV 420 luksuz — 2015 · 231 425 km · Niš · 14 850 EUR
- BMW X4 20d xDrive M paket (može zamena) — 2020 · 43 499 km · Beograd · 39 990 EUR
- BMV Ks1 2.0 D sDrive 18d — 2021 · 165 515 km · Beograd · 19 999 EUR
- BMV Ks1 2.0 D Sdrive — 2021 · 167 582 km · Beograd · 21 499 EUR
- BMV Ks5 3.0 D/HIBRID/M/CH — 2020 · 186 000 km · Valjevo · 49 990 EUR
- BMV Ks3 2.0 — 2008 · 238 782 km · Voždovac · 6 200 EUR
Pogledajte i
feed