Commit ·
e6b20e0
1
Parent(s): 873c8b6
fix(grammar): add hamza fixes for ايضا, اول, and position-aware إنّ/أنّ rules
Browse filesAdd ايضا→أيضا and اول→أول to _HAMZA_FIXES (unambiguous).
Add context-dependent إنّ/أنّ hamza: kasra (إ) at sentence start,
fathah (أ) mid-sentence — follows standard Arabic grammar rule.
Fixes S003, S006, S015, S025 benchmark failures.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
src/nlp/grammar/grammar_rules.py
CHANGED
|
@@ -898,6 +898,17 @@ class ArabicGrammarGuard:
|
|
| 898 |
'انقذ': 'أنقذ', 'انقذت': 'أنقذت', 'انقذوا': 'أنقذوا',
|
| 899 |
'الامهات': 'الأمهات', 'الاطفال': 'الأطفال',
|
| 900 |
'الامة': 'الأمة', 'الاستاذ': 'الأستاذ',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 901 |
}
|
| 902 |
_HAMZA_STEMS = {
|
| 903 |
'احب': 'أحب', 'افهم': 'أفهم', 'اعلن': 'أعلن',
|
|
@@ -912,6 +923,14 @@ class ArabicGrammarGuard:
|
|
| 912 |
if w in _HAMZA_FIXES:
|
| 913 |
words[i] = _HAMZA_FIXES[w]
|
| 914 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 915 |
for stem, fixed in _HAMZA_STEMS.items():
|
| 916 |
if w.startswith(stem) and len(w) > len(stem):
|
| 917 |
suffix = w[len(stem):]
|
|
|
|
| 898 |
'انقذ': 'أنقذ', 'انقذت': 'أنقذت', 'انقذوا': 'أنقذوا',
|
| 899 |
'الامهات': 'الأمهات', 'الاطفال': 'الأطفال',
|
| 900 |
'الامة': 'الأمة', 'الاستاذ': 'الأستاذ',
|
| 901 |
+
'ايضا': 'أيضا',
|
| 902 |
+
'اول': 'أول',
|
| 903 |
+
}
|
| 904 |
+
# Context-dependent إنّ/أنّ hamza: kasra (إ) at sentence start, fathah (أ) mid-sentence
|
| 905 |
+
_INNA_SENTENCE_INITIAL = {
|
| 906 |
+
'ان': 'إن', 'انه': 'إنه', 'انها': 'إنها',
|
| 907 |
+
'اننا': 'إننا', 'انهم': 'إنهم', 'انك': 'إنك', 'انكم': 'إنكم',
|
| 908 |
+
}
|
| 909 |
+
_ANNA_MID_SENTENCE = {
|
| 910 |
+
'ان': 'أن', 'انه': 'أنه', 'انها': 'أنها',
|
| 911 |
+
'اننا': 'أننا', 'انهم': 'أنهم', 'انك': 'أنك', 'انكم': 'أنكم',
|
| 912 |
}
|
| 913 |
_HAMZA_STEMS = {
|
| 914 |
'احب': 'أحب', 'افهم': 'أفهم', 'اعلن': 'أعلن',
|
|
|
|
| 923 |
if w in _HAMZA_FIXES:
|
| 924 |
words[i] = _HAMZA_FIXES[w]
|
| 925 |
continue
|
| 926 |
+
# إنّ/أنّ: kasra at sentence start, fathah mid-sentence
|
| 927 |
+
_is_sent_start = (i == 0) or (words[i-1][-1] in '.؟!؛' if words[i-1] else False)
|
| 928 |
+
if _is_sent_start and w in _INNA_SENTENCE_INITIAL:
|
| 929 |
+
words[i] = _INNA_SENTENCE_INITIAL[w]
|
| 930 |
+
continue
|
| 931 |
+
if not _is_sent_start and w in _ANNA_MID_SENTENCE:
|
| 932 |
+
words[i] = _ANNA_MID_SENTENCE[w]
|
| 933 |
+
continue
|
| 934 |
for stem, fixed in _HAMZA_STEMS.items():
|
| 935 |
if w.startswith(stem) and len(w) > len(stem):
|
| 936 |
suffix = w[len(stem):]
|