| """ | |
| Rule-based sentence-level dyslexic writing pattern inference. | |
| This module implements dominance-aware, interpretable rules | |
| for identifying dyslexic writing patterns from surface features. | |
| """ | |
| def infer_pattern(features: dict) -> str: | |
| """ | |
| Infer the dominant dyslexic writing pattern for a sentence | |
| using surface-level error signals. | |
| Parameters | |
| ---------- | |
| features : dict | |
| Dictionary containing extracted surface features. | |
| Returns | |
| ------- | |
| str | |
| One of the predefined dyslexic writing pattern labels. | |
| """ | |
| # Priority 1: Word boundary confusion | |
| if features.get("has_spacing_issue"): | |
| return "Word Boundary Confusion" | |
| has_sub = features.get("has_substitution", False) | |
| has_omit = features.get("has_omission", False) | |
| has_diacritic = features.get("has_diacritic_loss", False) | |
| # Priority 2: Mixed dyslexic pattern | |
| if has_sub and has_omit: | |
| return "Mixed Dyslexic Pattern" | |
| # Priority 3: Phonetic confusion | |
| if has_sub: | |
| return "Phonetic Confusion" | |
| # Priority 4: Orthographic instability | |
| if has_omit or has_diacritic: | |
| return "Orthographic Instability" | |
| # Fallback | |
| return "No Dominant Pattern" | |