Commit ·
f09d57c
1
Parent(s): 29371b1
fix: Deduplicate spelling/grammar overlap - grammar wins - When spelling and grammar both flag the same word position, keep only grammar suggestion - Prevents double-highlighting on conjugation errors like يعملوا
Browse files- src/app.py +20 -0
src/app.py
CHANGED
|
@@ -920,6 +920,26 @@ def analyze_text():
|
|
| 920 |
logger.error(f"[ANALYZE] Punctuation failed: {e}")
|
| 921 |
|
| 922 |
total_time = time.time() - total_start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 923 |
logger.info(f"[ANALYZE] Total analysis time: {total_time:.2f}s | Suggestions: {len(suggestions)}")
|
| 924 |
|
| 925 |
return jsonify({
|
|
|
|
| 920 |
logger.error(f"[ANALYZE] Punctuation failed: {e}")
|
| 921 |
|
| 922 |
total_time = time.time() - total_start
|
| 923 |
+
|
| 924 |
+
# ── Deduplicate overlapping suggestions ──
|
| 925 |
+
# If grammar and spelling both flag the same position, grammar wins.
|
| 926 |
+
# This prevents double-highlighting on words like "يعملوا" which are
|
| 927 |
+
# grammar errors (not spelling errors).
|
| 928 |
+
grammar_positions = set()
|
| 929 |
+
for s in suggestions:
|
| 930 |
+
if s['type'] == 'grammar':
|
| 931 |
+
grammar_positions.add((s['start'], s['end']))
|
| 932 |
+
|
| 933 |
+
if grammar_positions:
|
| 934 |
+
before_count = len(suggestions)
|
| 935 |
+
suggestions = [
|
| 936 |
+
s for s in suggestions
|
| 937 |
+
if s['type'] != 'spelling' or (s['start'], s['end']) not in grammar_positions
|
| 938 |
+
]
|
| 939 |
+
removed = before_count - len(suggestions)
|
| 940 |
+
if removed > 0:
|
| 941 |
+
logger.info(f"[ANALYZE] Removed {removed} spelling suggestions that overlap with grammar")
|
| 942 |
+
|
| 943 |
logger.info(f"[ANALYZE] Total analysis time: {total_time:.2f}s | Suggestions: {len(suggestions)}")
|
| 944 |
|
| 945 |
return jsonify({
|