youssefreda9 commited on
Commit
5f5d641
·
1 Parent(s): ea6172b

FIX-48v3: Create patches (not just mutations) for ه→ة

Browse files

ROOT CAUSE: The final corrected output is rebuilt from original +
patches (line 2673), NOT from ctx.current_text. FIX-48v3 was only
mutating ctx.current_text without creating patches, so the changes
were silently discarded in the final output.

Fix: Add ctx.add_patch() calls for each ه→ة whitelist match.
This ensures the changes appear in suggestions AND corrected output.

Tests: 39 passing.

Files changed (1) hide show
  1. src/app.py +7 -1
src/app.py CHANGED
@@ -2525,6 +2525,7 @@ def analyze_text():
2525
  _hata_words = _hata_text.split()
2526
  _hata_changed = False
2527
  _hata_result = []
 
2528
  for _hw in _hata_words:
2529
  _hw_clean = _hw.rstrip('.،؛؟!?!')
2530
  if _hw_clean in _HATA_WHITELIST:
@@ -2533,9 +2534,14 @@ def analyze_text():
2533
  logger.info(f"[HA-TA] Post-grammar ه→ة: '{_hw}'→'{_fixed}{_punct_suffix}'")
2534
  _hata_result.append(_fixed + _punct_suffix)
2535
  _hata_changed = True
 
 
 
 
 
2536
  else:
2537
  _hata_result.append(_hw)
2538
- logger.info(f"[HA-TA] Scan: {len(_hata_words)} words, {sum(1 for w in _hata_words if w.rstrip('.') in _HATA_WHITELIST)} matches, changed={_hata_changed}")
2539
  if _hata_changed:
2540
  _hata_new = ' '.join(_hata_result)
2541
  ctx.mutate_text(_hata_new, OffsetMapper)
 
2525
  _hata_words = _hata_text.split()
2526
  _hata_changed = False
2527
  _hata_result = []
2528
+ _hata_pos = 0 # track position in text for patch offsets
2529
  for _hw in _hata_words:
2530
  _hw_clean = _hw.rstrip('.،؛؟!?!')
2531
  if _hw_clean in _HATA_WHITELIST:
 
2534
  logger.info(f"[HA-TA] Post-grammar ه→ة: '{_hw}'→'{_fixed}{_punct_suffix}'")
2535
  _hata_result.append(_fixed + _punct_suffix)
2536
  _hata_changed = True
2537
+ # Create a patch so the final output includes this fix
2538
+ ctx.add_patch(
2539
+ 'spelling', _hata_pos, _hata_pos + len(_hw),
2540
+ _fixed + _punct_suffix, confidence=0.85,
2541
+ )
2542
  else:
2543
  _hata_result.append(_hw)
2544
+ _hata_pos += len(_hw) + 1 # +1 for space
2545
  if _hata_changed:
2546
  _hata_new = ' '.join(_hata_result)
2547
  ctx.mutate_text(_hata_new, OffsetMapper)