Spaces:
Sleeping
Sleeping
Update helpers/cleaner.py
Browse files- helpers/cleaner.py +8 -8
helpers/cleaner.py
CHANGED
|
@@ -36,7 +36,7 @@ def merge_colon_lines(text: str) -> str:
|
|
| 36 |
if not text:
|
| 37 |
return ""
|
| 38 |
|
| 39 |
-
# تنظيف
|
| 40 |
lines = [re.sub(r"[ \t]+", " ", line).strip() for line in text.splitlines()]
|
| 41 |
text = "\n".join(lines)
|
| 42 |
|
|
@@ -48,21 +48,21 @@ def merge_colon_lines(text: str) -> str:
|
|
| 48 |
flags=re.MULTILINE
|
| 49 |
)
|
| 50 |
|
| 51 |
-
# ⭐
|
| 52 |
-
#
|
| 53 |
text = re.sub(
|
| 54 |
-
r":\s*(?=(
|
| 55 |
r":\n",
|
| 56 |
text
|
| 57 |
)
|
| 58 |
|
| 59 |
-
# 1️⃣ دمج
|
| 60 |
text = re.sub(r"^(.+?):\n(.+)$", r"\1: \2", text, flags=re.MULTILINE)
|
| 61 |
|
| 62 |
-
# 2️⃣ دمج الأرقام
|
| 63 |
text = re.sub(r"^(\d+)-\n(.+)$", r"\1- \2", text, flags=re.MULTILINE)
|
| 64 |
|
| 65 |
-
# 3️⃣ دمج مادة(...) مع السطر التالي إذا لم يكن
|
| 66 |
text = re.sub(
|
| 67 |
r"^(مادة *\([^)]+\))\n(?![أ-ي]\s*-\s*)(.+)$",
|
| 68 |
r"\1 \2",
|
|
@@ -70,7 +70,7 @@ def merge_colon_lines(text: str) -> str:
|
|
| 70 |
flags=re.MULTILINE
|
| 71 |
)
|
| 72 |
|
| 73 |
-
# 4️⃣ دمج الحروف الفرعية
|
| 74 |
text = re.sub(
|
| 75 |
r"^([أ-ي]\s*-\s*)\n(.+)$",
|
| 76 |
r"\1 \2",
|
|
|
|
| 36 |
if not text:
|
| 37 |
return ""
|
| 38 |
|
| 39 |
+
# تنظيف المسافات الزائدة
|
| 40 |
lines = [re.sub(r"[ \t]+", " ", line).strip() for line in text.splitlines()]
|
| 41 |
text = "\n".join(lines)
|
| 42 |
|
|
|
|
| 48 |
flags=re.MULTILINE
|
| 49 |
)
|
| 50 |
|
| 51 |
+
# ⭐ فصل النص بعد ":" إلى سطر جديد إذا تلاه رقم أو حرف فرعي
|
| 52 |
+
# يغطي أمثلة مثل "التالي: 1-..." أو "ما يلي: أ- ..."
|
| 53 |
text = re.sub(
|
| 54 |
+
r":\s*(?=([0-9]+-|[أ-ي]\s*-))",
|
| 55 |
r":\n",
|
| 56 |
text
|
| 57 |
)
|
| 58 |
|
| 59 |
+
# 1️⃣ دمج الأسطر التي تنتهي بـ ":" مع السطر التالي (حالات عادية)
|
| 60 |
text = re.sub(r"^(.+?):\n(.+)$", r"\1: \2", text, flags=re.MULTILINE)
|
| 61 |
|
| 62 |
+
# 2️⃣ دمج الأرقام مع "-"
|
| 63 |
text = re.sub(r"^(\d+)-\n(.+)$", r"\1- \2", text, flags=re.MULTILINE)
|
| 64 |
|
| 65 |
+
# 3️⃣ دمج مادة(...) مع السطر التالي إذا لم يكن حرف فرعي
|
| 66 |
text = re.sub(
|
| 67 |
r"^(مادة *\([^)]+\))\n(?![أ-ي]\s*-\s*)(.+)$",
|
| 68 |
r"\1 \2",
|
|
|
|
| 70 |
flags=re.MULTILINE
|
| 71 |
)
|
| 72 |
|
| 73 |
+
# 4️⃣ دمج الحروف الفرعية مع السطر التالي
|
| 74 |
text = re.sub(
|
| 75 |
r"^([أ-ي]\s*-\s*)\n(.+)$",
|
| 76 |
r"\1 \2",
|