Mazenbs commited on
Commit
b771743
·
verified ·
1 Parent(s): 8db4722

Update parser/section_extractor.py

Browse files
Files changed (1) hide show
  1. parser/section_extractor.py +19 -5
parser/section_extractor.py CHANGED
@@ -1,19 +1,33 @@
 
 
 
1
  def extract_sections(texts: list):
2
  """
3
- تقسيم النصوص إلى أقسام وفصول
4
  """
5
  sections = []
6
  current = {"name": "", "texts": []}
7
 
8
  for t in texts:
9
- t = t.strip()
10
- if any(keyword in t for keyword in ["الباب", "الفصل"]):
 
 
 
 
 
 
11
  if current["texts"] or current["name"]:
12
  sections.append(current)
13
- current = {"name": t, "texts": []}
 
 
 
14
  else:
15
- current["texts"].append(t)
 
16
 
 
17
  if current["texts"] or current["name"]:
18
  sections.append(current)
19
 
 
1
+ # parser/section_extractor.py
2
+ from helpers.utils import is_section, normalize_digits
3
+
4
  def extract_sections(texts: list):
5
  """
6
+ تقسيم النصوص إلى أقسام وفصول باستخدام الأنماط الذكية
7
  """
8
  sections = []
9
  current = {"name": "", "texts": []}
10
 
11
  for t in texts:
12
+ if not isinstance(t, str):
13
+ continue
14
+
15
+ t_norm = normalize_digits(t.strip())
16
+
17
+ # هل السطر عنوان قسم أو فصل؟
18
+ if is_section(t_norm):
19
+ # لو يوجد قسم سابق → نحفظه
20
  if current["texts"] or current["name"]:
21
  sections.append(current)
22
+
23
+ # نبدأ قسم/فصل جديد
24
+ current = {"name": t_norm, "texts": []}
25
+
26
  else:
27
+ # السطور التابعة للقسم الحالي
28
+ current["texts"].append(t_norm)
29
 
30
+ # إضافة آخر قسم
31
  if current["texts"] or current["name"]:
32
  sections.append(current)
33