youssefreda9 commited on
Commit
7db8fbe
·
1 Parent(s): 6e716e3

Cleanup pass 3: Delete debug_verdict.py, rewrite tasks/todo.md and src/README.md for v2.0

Browse files
Files changed (3) hide show
  1. src/README.md +52 -49
  2. tasks/todo.md +45 -34
  3. tests/v2/debug_verdict.py +0 -10
src/README.md CHANGED
@@ -1,55 +1,58 @@
1
- # src/ — source code
2
 
3
- Purpose
4
-
5
- All core project code should live in `src/`: data loaders, preprocessing, training scripts, model definitions, and inference API.
6
-
7
- Suggested layout
8
-
9
- - `src/app.py` — lightweight Flask/FastAPI app for inference and testing
10
- - `src/train.py` — training orchestration (argument parsing, checkpointing)
11
- - `src/evaluate.py` — evaluation scripts and metrics
12
- - `src/data_loader.py` — dataset loaders and helpers
13
- - `src/preprocessing.py` — normalization, tokenization, and text cleaning
14
- - `src/models/` — model classes or adapters
15
- - `src/utils/` — utility functions (logging, metrics, etc.)
16
- - `src/tests/` — unit and integration tests for core modules
17
-
18
- File responsibilities and guidelines
19
-
20
- - Keep functions small and well-documented.
21
- - Expose a stable API for inference (e.g., `predict(text: str) -> dict`). Document the input/output shapes.
22
- - Add type hints where practical.
23
-
24
- Coding conventions
25
-
26
- - Use the project style (PEP8). Add a linter config if needed (e.g., `pyproject.toml` or `.flake8`).
27
- - Write tests for data loaders and small utilities. Place tests under `src/tests/` and use pytest.
28
-
29
- What to add when working in `src/`
30
-
31
- - Small, focused commits that update a single feature or test.
32
- - If adding a new script, update top-level `README.md` with a one-line summary and usage example.
33
- - If you modify input/output shapes for the inference API, update the API docs and communicate in the PR description.
34
-
35
- Quick example: inference contract
36
-
37
- - Input: Arabic text string (utf-8)
38
- - Output: JSON object with fields such as `text`, `suggestions` (list), `confidence` (0-1), and optional `edits` with positions
39
-
40
- Example output shape
41
 
42
  ```
43
- {
44
- "text": "...",
45
- "suggestions": [
46
- {"start": 5, "end": 12, "replacement": "...", "explanation": "grammar: agreement"}
47
- ],
48
- "confidence": 0.87
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  ```
51
 
52
- Testing
 
 
 
 
 
53
 
54
- - Add unit tests for `preprocessing.py` and `data_loader.py` (happy path + one edge case).
55
- - Add a small integration test for `app.py` that exercises the prediction endpoint with a short sample input.
 
 
1
+ # src/ — Source Code
2
 
3
+ ## Structure
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  ```
6
+ src/
7
+ ├── app.py # Flask application — routes + pipeline orchestration
8
+ ├── model_loader.py # Model loading (Spelling, Grammar, Summarization, Autocomplete)
9
+ ├── hf_inference.py # HuggingFace API inference wrappers
10
+ ├── index.html # Main web UI (single-page app)
11
+ ├── favicon.svg # Site icon
12
+ ├── css/ # Stylesheets
13
+ │ ├── tokens.css # Design tokens (colors, spacing)
14
+ │ ├── base.css # Base styles
15
+ │ └── components.css # Component styles
16
+ ├── js/ # Frontend JavaScript modules
17
+ │ ├── editor.js # Editor logic, events, debouncing
18
+ │ ├── renderer.js # Offset-based highlight rendering
19
+ │ ├── selection.js # Cursor/selection save & restore
20
+ │ ├── ui.js # Tooltips, suggestion lists, scores
21
+ │ ├── api.js # Backend API fetch wrappers
22
+ │ ├── format.js # Text formatting
23
+ │ ├── theme.js # Theme switching
24
+ │ ├── autocomplete.js # Autocomplete UI
25
+ │ ├── auth/ # Authentication (Supabase)
26
+ │ ├── documents/ # Local document management
27
+ │ ├── documents-cloud/ # Cloud document sync
28
+ │ ├── summaries/ # Text summarization UI
29
+ │ ├── settings-sync/ # Settings sync
30
+ │ ├── sync/ # Real-time sync engine
31
+ │ └── vendor/ # Third-party libraries
32
+ └── nlp/ # NLP pipeline modules
33
+ ├── spelling/ # AraSpell spelling correction
34
+ │ ├── araspell_rules.py
35
+ │ └── araspell_service.py
36
+ ├── grammar/ # Grammar correction
37
+ │ ├── grammar_rules.py
38
+ │ └── grammar_service.py
39
+ ├── punctuation/ # Punctuation restoration
40
+ │ ├── punctuation_rules.py
41
+ │ └── punctuation_service.py
42
+ ├── autocomplete/ # Text autocomplete
43
+ ├── dialect/ # Dialect detection
44
+ ├── pipeline_context.py # Shared pipeline state
45
+ ├── stage_locker.py # Cross-stage text locking
46
+ └── correction_patch.py # Correction patch utilities
47
  ```
48
 
49
+ ## API Contract
50
+
51
+ - **Input**: Arabic text string (UTF-8)
52
+ - **Output**: JSON with `corrected`, `suggestions[]` (each with `start`, `end`, `replacement`, `explanation`), and `timing_ms`
53
+
54
+ ## Running
55
 
56
+ ```bash
57
+ cd src && gunicorn app:app --bind 0.0.0.0:7860 --timeout 120 --workers 1
58
+ ```
tasks/todo.md CHANGED
@@ -1,41 +1,52 @@
1
- # Task List: Phase 1 Editor Stabilization Refactor
2
 
3
- ## Milestone 1: Modularize Editor Logic
4
- - [ ] Create folder `src/js/` if it doesn't exist
5
- - [ ] Create `src/js/api.js` to handle all API communications
6
- - [ ] Create `src/js/editor.js` to manage editor elements, events, and debouncing
7
- - [ ] Create `src/js/renderer.js` to handle HTML escape and offset-based highlighting
8
- - [ ] Create `src/js/selection.js` to save and restore range/cursor selections
9
- - [ ] Create `src/js/ui.js` to handle tooltips, lists, scores, and loading spinners
10
- - [ ] Update `src/index.html` to load modular JS files instead of inline scripts
11
- - [ ] Verify that the frontend loads correctly and contains no console errors
12
 
13
- ## Milestone 2: Selection & Caret Preservation
14
- - [ ] Implement `saveSelection` and `restoreSelection` based on character offset in `src/js/selection.js`
15
- - [ ] Implement `getCaretCharacterOffsetWithin` and `setCaretCharacterOffsetWithin`
16
- - [ ] Integrate selection restore before and after highlight updates
17
- - [ ] Verify that typing does not cause cursor jumps or selection losses
 
 
 
18
 
19
- ## Milestone 3: Backend Offset Support
20
- - [x] Implement `get_word_positions` in `src/app.py`
21
- - [x] Implement `OffsetMapper` coordinate transform class in `src/app.py`
22
- - [x] Rewrite `/api/analyze` in `src/app.py` to calculate exact character offsets (`start`, `end`) for all suggestions
23
- - [ ] Verify using the test script `reproduce_issue.py` or `test_analyze_api.py` that the backend returns `start` and `end` offsets for all suggestions
 
 
24
 
25
- ## Milestone 4: Offset-Based Rendering
26
- - [ ] Write offset-based rendering parser in `src/js/renderer.js`
27
- - [ ] Ensure the renderer splits the text into highlighted spans and normal text nodes based on sorted, non-overlapping suggestions
28
- - [ ] Support multiple occurrences of duplicate words by matching exact start/end offsets
 
29
 
30
- ## Milestone 5: Secure Rendering
31
- - [ ] Implement `escapeHtml` utility in `src/js/renderer.js`
32
- - [ ] Ensure all user inputs, suggestion corrections, and text are escaped before DOM insertion to prevent XSS
 
 
33
 
34
- ## Milestone 6: Tooltip Mapping
35
- - [ ] Assign unique `data-suggestion-id` (index in suggestions list) to each highlight span
36
- - [ ] Wire click event listeners on the editor container to detect suggestion spans, retrieve the suggestion, and open the tooltip dynamically
 
 
37
 
38
- ## Milestone 7: Integration & Validation
39
- - [ ] Launch backend local server using `run_app.py`
40
- - [ ] Run end-to-end browser check to verify that highlights, suggestions, cursor, and metrics work perfectly
41
- - [ ] Document final results in `tasks/todo.md` and lessons in `tasks/lessons.md`
 
 
 
1
+ # BAYAN v2.0 Task List
2
 
3
+ ## Phase A: Test Infrastructure
4
+ - [x] Create `tests/v2/test_level1_raw.py` Raw model tests with TP/FP/FN/TN verdicts
5
+ - [x] Create `tests/v2/test_level2_solo.py` Solo API endpoint tests
6
+ - [x] Create `tests/v2/test_level3_integrated.py` Full pipeline tests
7
+ - [x] Create `tests/v2/benchmark_matrix.py` Master comparison runner
8
+ - [x] Fix verdict logic (strip terminal punctuation before comparison)
9
+ - [x] Run baseline on entities + spelling datasets
10
+ - [ ] Run full 320-test baseline across all 3 levels
 
11
 
12
+ ## Phase A.1: Project Cleanup
13
+ - [x] Archive legacy scripts (AraSpell.py, Grammer_Rules.py, PuncAra.py)
14
+ - [x] Archive 36 old phase/verification reports
15
+ - [x] Archive 23 old test files + 8 phase10 helpers
16
+ - [x] Delete 35 orphaned debug/temp files
17
+ - [x] Fix .gitignore corruption (binary null bytes)
18
+ - [x] Fix PROJECT_DESCRIPTION.md stale reference
19
+ - [x] Archive docs/audit + docs/audits
20
 
21
+ ## Phase B: Extract Stages (NOT STARTED)
22
+ - [ ] Create `src/nlp/stages/spelling_stage.py`
23
+ - [ ] Create `src/nlp/stages/grammar_stage.py`
24
+ - [ ] Create `src/nlp/stages/punctuation_stage.py`
25
+ - [ ] Each stage wraps: model call filter verdict
26
+ - [ ] Hash (comment out) old inline stage code in `app.py`
27
+ - [ ] Re-run v2 benchmark → must match Phase A baseline
28
 
29
+ ## Phase C: Extract Filters (NOT STARTED)
30
+ - [ ] Create `src/nlp/filters/` module
31
+ - [ ] Extract overlap resolution, religious guard, entity guard
32
+ - [ ] Hash old filter code in `app.py`
33
+ - [ ] Re-run v2 benchmark → must match baseline
34
 
35
+ ## Phase D: Extract Preprocessors (NOT STARTED)
36
+ - [ ] Create `src/nlp/preprocessors/` module
37
+ - [ ] Extract text normalization, diacritic handling, chunk splitting
38
+ - [ ] Hash old preprocessor code in `app.py`
39
+ - [ ] Re-run v2 benchmark → must match baseline
40
 
41
+ ## Phase E: Create Pipeline Orchestrator (NOT STARTED)
42
+ - [ ] Create `src/nlp/pipeline.py` orchestrates stages via PipelineContext
43
+ - [ ] Wire `app.py` /api/analyze to use `pipeline.run(text)`
44
+ - [ ] Hash old monolithic analyze code in `app.py`
45
+ - [ ] Re-run v2 benchmark → must match baseline
46
 
47
+ ## Phase F: Clean app.py (NOT STARTED)
48
+ - [ ] Move helpers (get_word_positions, OffsetMapper, etc.) to utility modules
49
+ - [ ] Remove all hashed (commented) code blocks
50
+ - [ ] app.py should only contain: Flask routes + pipeline.run() calls
51
+ - [ ] Final v2 benchmark → must match baseline
52
+ - [ ] Target: app.py < 500 lines
tests/v2/debug_verdict.py DELETED
@@ -1,10 +0,0 @@
1
- import json
2
-
3
- d = json.load(open('tests/v2/reports/level3_integrated_results.json', 'r', encoding='utf-8'))
4
- for r in d['results'][:5]:
5
- print(f"ID: {r['id']}")
6
- print(f" IN: {r['input_text']}")
7
- print(f" EXP: {r['expected']}")
8
- print(f" OUT: {r['pipeline_corrected']}")
9
- print(f" V: {r['verdict']} | {r['detail']}")
10
- print()