Commit ·
7d31635
1
Parent(s): 6285a1c
feat: Arabic-Indic numerals + range format (٣١-٣٣) in Quran output
Browse files
quran.py
CHANGED
|
@@ -296,6 +296,13 @@ def search_bayan(query_text: str,
|
|
| 296 |
# ==========================================
|
| 297 |
# تشكيل المخرجات
|
| 298 |
# ==========================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
matched_words = best_rows[best_match_idx: best_match_idx + n]
|
| 300 |
|
| 301 |
# بناء matched_segment مع رقم كل آية
|
|
@@ -308,7 +315,7 @@ def search_bayan(query_text: str,
|
|
| 308 |
|
| 309 |
if lang_code == "uthmani":
|
| 310 |
seg_parts = [
|
| 311 |
-
" ".join(words) + f" ({a_num})"
|
| 312 |
for (_, a_num), words in aya_words.items()
|
| 313 |
]
|
| 314 |
matched_segment = " ".join(seg_parts)
|
|
@@ -319,7 +326,7 @@ def search_bayan(query_text: str,
|
|
| 319 |
txt = words[0] # target_text مكرر لكل كلمة، نأخذ الأول
|
| 320 |
if txt not in seen_texts:
|
| 321 |
seen_texts.add(txt)
|
| 322 |
-
seg_parts.append(f"{txt} ({a_num})")
|
| 323 |
matched_segment = " ".join(seg_parts)
|
| 324 |
|
| 325 |
# الآيات المشمولة — مرتبة بالترتيب
|
|
@@ -334,15 +341,17 @@ def search_bayan(query_text: str,
|
|
| 334 |
|
| 335 |
verse_body_parts = []
|
| 336 |
for (s_num, a_num), data in involved.items():
|
| 337 |
-
verse_body_parts.append(f"{data['target_text']} ({a_num})")
|
| 338 |
|
| 339 |
combined_body = " ".join(verse_body_parts)
|
| 340 |
|
|
|
|
| 341 |
if len(ayah_nums) == 1:
|
| 342 |
-
ref = f"{sura_name}: {ayah_nums[0]}"
|
| 343 |
else:
|
| 344 |
-
|
| 345 |
-
|
|
|
|
| 346 |
|
| 347 |
full_verse_formatted = f"({combined_body}) [{ref}]"
|
| 348 |
matched_segment = f"({matched_segment}) [{ref}]"
|
|
|
|
| 296 |
# ==========================================
|
| 297 |
# تشكيل المخرجات
|
| 298 |
# ==========================================
|
| 299 |
+
|
| 300 |
+
# تحويل الأرقام اللاتينية إلى عربية
|
| 301 |
+
def to_arabic_nums(n):
|
| 302 |
+
"""Convert 31 → ٣١"""
|
| 303 |
+
ar_digits = '٠١٢٣٤٥٦٧٨٩'
|
| 304 |
+
return ''.join(ar_digits[int(d)] for d in str(n))
|
| 305 |
+
|
| 306 |
matched_words = best_rows[best_match_idx: best_match_idx + n]
|
| 307 |
|
| 308 |
# بناء matched_segment مع رقم كل آية
|
|
|
|
| 315 |
|
| 316 |
if lang_code == "uthmani":
|
| 317 |
seg_parts = [
|
| 318 |
+
" ".join(words) + f" ({to_arabic_nums(a_num)})"
|
| 319 |
for (_, a_num), words in aya_words.items()
|
| 320 |
]
|
| 321 |
matched_segment = " ".join(seg_parts)
|
|
|
|
| 326 |
txt = words[0] # target_text مكرر لكل كلمة، نأخذ الأول
|
| 327 |
if txt not in seen_texts:
|
| 328 |
seen_texts.add(txt)
|
| 329 |
+
seg_parts.append(f"{txt} ({to_arabic_nums(a_num)})")
|
| 330 |
matched_segment = " ".join(seg_parts)
|
| 331 |
|
| 332 |
# الآيات المشمولة — مرتبة بالترتيب
|
|
|
|
| 341 |
|
| 342 |
verse_body_parts = []
|
| 343 |
for (s_num, a_num), data in involved.items():
|
| 344 |
+
verse_body_parts.append(f"{data['target_text']} ({to_arabic_nums(a_num)})")
|
| 345 |
|
| 346 |
combined_body = " ".join(verse_body_parts)
|
| 347 |
|
| 348 |
+
# بناء المرجع: نطاق (من-إلى) بدل سرد كل الأرقام
|
| 349 |
if len(ayah_nums) == 1:
|
| 350 |
+
ref = f"{sura_name}: {to_arabic_nums(ayah_nums[0])}"
|
| 351 |
else:
|
| 352 |
+
first_ar = to_arabic_nums(ayah_nums[0])
|
| 353 |
+
last_ar = to_arabic_nums(ayah_nums[-1])
|
| 354 |
+
ref = f"{sura_name}: {first_ar}-{last_ar}"
|
| 355 |
|
| 356 |
full_verse_formatted = f"({combined_body}) [{ref}]"
|
| 357 |
matched_segment = f"({matched_segment}) [{ref}]"
|