Mazenbs commited on
Commit
1a4e84b
·
verified ·
1 Parent(s): 79556ef

Update helpers/utils.py

Browse files
Files changed (1) hide show
  1. helpers/utils.py +29 -14
helpers/utils.py CHANGED
@@ -1,20 +1,6 @@
1
  import re
2
  from helpers.cleaner import clean_text
3
 
4
- # ----------- تحويل الأرقام الهندية إلى عربية -----------
5
- ARABIC_INDIC_DIGITS = str.maketrans("٠١٢٣٤٥٦٧٨٩", "0123456789")
6
-
7
- def normalize_digits(s: str) -> str:
8
- if not isinstance(s, str):
9
- return ""
10
- return s.translate(ARABIC_INDIC_DIGITS)
11
-
12
- # ----------- تنظيف النص + تحويل الأرقام -----------
13
- def clean_text_block(text: str) -> str:
14
- if not isinstance(text, str):
15
- return ""
16
- return clean_text(normalize_digits(text.strip()))
17
-
18
  # ----------- الأنماط -----------
19
  ARTICLE_PATTERN = re.compile(
20
  r"^\s*ماد[ةه]\s*[\(\s]*([0-9]+)[\)\s]*",
@@ -32,6 +18,35 @@ LAW_ISSUE_PATTERN = re.compile(
32
  r'أصدرنا القانون\s+(.*?)(?=\s{2,}|$)', # المجموعة 1 = التفاصيل
33
  re.IGNORECASE | re.UNICODE
34
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  # ----------- تحديد نوع السطر -----------
 
1
  import re
2
  from helpers.cleaner import clean_text
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # ----------- الأنماط -----------
5
  ARTICLE_PATTERN = re.compile(
6
  r"^\s*ماد[ةه]\s*[\(\s]*([0-9]+)[\)\s]*",
 
18
  r'أصدرنا القانون\s+(.*?)(?=\s{2,}|$)', # المجموعة 1 = التفاصيل
19
  re.IGNORECASE | re.UNICODE
20
  )
21
+ def is_article(text: str) -> bool:
22
+ """هل السطر عبارة عن مادة قانونية؟"""
23
+ if not isinstance(text, str):
24
+ return False
25
+ text_norm = normalize_digits(text)
26
+ return bool(ARTICLE_PATTERN.match(text_norm))
27
+
28
+ def is_section(text: str) -> bool:
29
+ """هل السطر عنوان قسم (باب / فصل / قسم)؟"""
30
+ if not isinstance(text, str):
31
+ return False
32
+ return bool(SECTION_PATTERN.match(text))
33
+
34
+
35
+ # ----------- تحويل الأرقام الهندية إلى عربية -----------
36
+ ARABIC_INDIC_DIGITS = str.maketrans("٠١٢٣٤٥٦٧٨٩", "0123456789")
37
+
38
+ def normalize_digits(s: str) -> str:
39
+ if not isinstance(s, str):
40
+ return ""
41
+ return s.translate(ARABIC_INDIC_DIGITS)
42
+
43
+ # ----------- تنظيف النص + تحويل الأرقام -----------
44
+ def clean_text_block(text: str) -> str:
45
+ if not isinstance(text, str):
46
+ return ""
47
+ return clean_text(normalize_digits(text.strip()))
48
+
49
+
50
 
51
 
52
  # ----------- تحديد نوع السطر -----------