youssefreda9 commited on
Commit
773412e
·
1 Parent(s): 976652b

fix: Grammar rules false positive - الامتحان was incorrectly matched - Increased minimum stem length from 2 to 4 in fix_prepositions_advanced - Prevents root-level ان endings (الامتحان, الإنسان) from being treated as grammatical ون/ان

Browse files
Files changed (1) hide show
  1. src/nlp/grammar/grammar_rules.py +4 -3
src/nlp/grammar/grammar_rules.py CHANGED
@@ -151,13 +151,14 @@ class ArabicGrammarGuard:
151
  def fix_prepositions_advanced(self, text):
152
  # Allow conjunctions (و، ف) before prepositions
153
  # (في المهندسون) -> (في المهندسين)
154
- text = re.sub(r'\b([وف]?(?:في|من|إلى|على|عن|حتى))\s+([أ-ي]{2,})(ون|ان)\b', r'\1 \2ين', text)
 
155
 
156
  # (وبالمبرمجون) -> (وبالمبرمجين)
157
- text = re.sub(r'\b([وف]?[بلكف])ال([أ-ي]{2,})(ون|ان)\b', r'\1ال\2ين', text)
158
 
159
  # (ولمهندسون) -> (ولمهندسين)
160
- text = re.sub(r'\b([وف]?ل)([أ-ي]{2,})(ون|ان)\b', r'\1\2ين', text)
161
  return text
162
 
163
  def regex_rules_fallback(self, text):
 
151
  def fix_prepositions_advanced(self, text):
152
  # Allow conjunctions (و، ف) before prepositions
153
  # (في المهندسون) -> (في المهندسين)
154
+ # Require stem >= 4 chars to avoid matching root-level ان endings (الامتحان, الإنسان, etc.)
155
+ text = re.sub(r'\b([وف]?(?:في|من|إلى|على|عن|حتى))\s+([أ-ي]{4,})(ون|ان)\b', r'\1 \2ين', text)
156
 
157
  # (وبالمبرمجون) -> (وبالمبرمجين)
158
+ text = re.sub(r'\b([وف]?[بلكف])ال([أ-ي]{4,})(ون|ان)\b', r'\1ال\2ين', text)
159
 
160
  # (ولمهندسون) -> (ولمهندسين)
161
+ text = re.sub(r'\b([وف]?ل)([أ-ي]{4,})(ون|ان)\b', r'\1\2ين', text)
162
  return text
163
 
164
  def regex_rules_fallback(self, text):