Commit ·
0ec4905
1
Parent(s): f5c89a7
fix: strip Basmala from verse 1 output (DB has it embedded)
Browse files
quran.py
CHANGED
|
@@ -325,11 +325,31 @@ def search_bayan(query_text: str,
|
|
| 325 |
sura_name = next(iter(involved.values()))["sura_name"]
|
| 326 |
|
| 327 |
# ── بناء النص الكامل من الآيات الكاملة (مش من الـ window بس) ──
|
| 328 |
-
#
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
verse_parts = []
|
| 331 |
for (s_num, a_num), data in involved.items():
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
combined_body = " ".join(verse_parts)
|
| 335 |
|
|
|
|
| 325 |
sura_name = next(iter(involved.values()))["sura_name"]
|
| 326 |
|
| 327 |
# ── بناء النص الكامل من الآيات الكاملة (مش من الـ window بس) ──
|
| 328 |
+
# إزالة البسملة من أول آية (مدمجة في الـ DB) — ماعدا الفاتحة
|
| 329 |
+
def _strip_basmala(text):
|
| 330 |
+
"""Remove Basmala from beginning of verse text"""
|
| 331 |
+
words = text.split()
|
| 332 |
+
if len(words) < 4:
|
| 333 |
+
return text
|
| 334 |
+
# Normalize first 4 words and check against known Basmala forms
|
| 335 |
+
first4_norm = normalize_arabic(' '.join(words[:4]), deep=False)
|
| 336 |
+
# ٱ (Alef Wasla) gets stripped during normalization → 'بسم لله لرحمـن لرحيم'
|
| 337 |
+
basmala_forms = [
|
| 338 |
+
'بسم الله الرحمن الرحيم', # standard alef
|
| 339 |
+
'بسم لله لرحمن لرحيم', # alef wasla stripped
|
| 340 |
+
'بسم لله لرحمـن لرحيم', # with tatweel ـ
|
| 341 |
+
]
|
| 342 |
+
if first4_norm in basmala_forms:
|
| 343 |
+
return ' '.join(words[4:])
|
| 344 |
+
return text
|
| 345 |
+
|
| 346 |
verse_parts = []
|
| 347 |
for (s_num, a_num), data in involved.items():
|
| 348 |
+
txt = data['target_text']
|
| 349 |
+
# شيل البسملة من الآية الأولى (إلا سورة الفاتحة)
|
| 350 |
+
if a_num == 1 and s_num != 1:
|
| 351 |
+
txt = _strip_basmala(txt)
|
| 352 |
+
verse_parts.append(f"{txt} ({fmt_num(a_num)})")
|
| 353 |
|
| 354 |
combined_body = " ".join(verse_parts)
|
| 355 |
|