Update pipeline/postprocess.py
Browse files- pipeline/postprocess.py +12 -7
pipeline/postprocess.py
CHANGED
|
@@ -158,16 +158,21 @@ def split_long_segment(seg: dict) -> list:
|
|
| 158 |
prev_word = words[idx - 1]["word"].strip().strip(".,!?;:").lower() if idx > 0 else ""
|
| 159 |
return prev_word in weak_endings
|
| 160 |
|
| 161 |
-
# اولویت اول: یه علامت نگارشی توی
|
| 162 |
-
# یه پایان طبیعیِ دیرتر، بهتر از شکستن مجبوری وسط یه عبارته
|
| 163 |
-
|
|
|
|
|
|
|
| 164 |
best_punct = -1
|
|
|
|
| 165 |
|
| 166 |
-
for i in range(len(words) -
|
| 167 |
word = words[i]["word"].strip()
|
| 168 |
-
if word and word[-1] in punct_chars and i
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
| 171 |
|
| 172 |
# اگه علامت پایانی مناسبی نبود، برگرد به روش قبلی: نزدیکترین علامت به وسط جمله
|
| 173 |
if best_punct == -1:
|
|
|
|
| 158 |
prev_word = words[idx - 1]["word"].strip().strip(".,!?;:").lower() if idx > 0 else ""
|
| 159 |
return prev_word in weak_endings
|
| 160 |
|
| 161 |
+
# اولویت اول: یه علامت نگارشی توی یه محدودهی مشخص از انتهای جمله (۷۰٪ تا ۹۰٪ طول) پیدا کن -
|
| 162 |
+
# یه پایان طبیعیِ دیرتر، بهتر از شکستن مجبوری وسط یه عبارته - ولی نه اونقدر دیر که
|
| 163 |
+
# تیکهی دوم خیلی کوچیک بشه و اصلاً نشکنه
|
| 164 |
+
late_start = len(words) * 0.7
|
| 165 |
+
late_end = len(words) * 0.9
|
| 166 |
best_punct = -1
|
| 167 |
+
best_late_dist = float('inf')
|
| 168 |
|
| 169 |
+
for i in range(1, len(words) - 1):
|
| 170 |
word = words[i]["word"].strip()
|
| 171 |
+
if word and word[-1] in punct_chars and late_start <= i <= late_end and not is_weak_split(i):
|
| 172 |
+
dist = abs(i - late_start) # نزدیکترین به شروع این محدوده (۷۰٪) رو ترجیح بده
|
| 173 |
+
if dist < best_late_dist:
|
| 174 |
+
best_late_dist = dist
|
| 175 |
+
best_punct = i + 1
|
| 176 |
|
| 177 |
# اگه علامت پایانی مناسبی نبود، برگرد به روش قبلی: نزدیکترین علامت به وسط جمله
|
| 178 |
if best_punct == -1:
|