Commit 39b9b52
committed
fix(autocorrect): route typo-of-contraction-base through alias map (#101)
Follow-up to Tier A — covers the case where the new adjacency-aware
dict scan converges on an alias-keyed bare-form (`dont`, `hadnt`,
`couldnt`, etc.) instead of the contracted target. Before this change,
typing `hadnr` (r↔t adjacent) returned `have` because:
1. `have` won the freq tiebreaker — binary dict scale gives it ≈ 1M
vs `hadnt`'s 5000 after `loadPrimaryContractionKeys` overwrites
the existing freq with `currentDict[withApostrophe] ?: 5000`
(apostrophe form is never in dict → unconditional 5000 anchor).
2. Even when the alias-key was the score-wise best match, the
`autoCorrect` return-path only consulted `contractionAliases`
at step 0 (on the typed input) — never on the dict-scan winner.
Fix routes through two layers:
- `ALIAS_KEY_FLOOR_FREQUENCY` (`Int.MAX_VALUE / 2`) — alias-key
candidates that clear the score threshold are floored above any
non-alias freq, regardless of which loader populated the dict
(JSON ≈ 100-10k, binary ≈ 5500-1M). Among multiple alias-keys
competing on the same typo (`couldnr` matches both `couldnt` and
`couldve`), a `score * 1000` offset added to the floor makes the
higher-scoring candidate win deterministically — eliminates the
hash-map iteration-order race that previously picked `could've`
over `couldn't`.
- End-of-scan alias re-route — after `bestCandidate` is picked,
`contractionAliases[winner]` lookup substitutes the contracted
form. Capitalization rules from step 0 (I-prefix → "I'm"; else
`preserveCapitalization`) are reused.
Tests (3 new in AutocorrectTest, all instrumented):
- `aliasDirect_hadntIsLoaded` — sanity probe that the alias map is
populated for this @before setup (was unclear earlier whether
`loadDictionary` triggered contractions loading in tests).
- `contractionBaseTypo_hadnrToHadntContracted` — `hadnr → hadn't`
via the new scan-then-reroute path.
- `contractionBaseTypo_couldnrToCouldntContracted` — `couldnr →
couldn't`, validating the score-tiebreaker among multiple
alias-key candidates (`couldnt` vs `couldve`).
Verified: 1231 pure + 194 mock + 1279 instrumented tests pass.
— opus 4.71 parent 2213f3b commit 39b9b52
2 files changed
Lines changed: 101 additions & 5 deletions
File tree
- src
- androidTest/kotlin/tribixbite/cleverkeys
- main/kotlin/tribixbite/cleverkeys
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
220 | 269 | | |
221 | 270 | | |
222 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
73 | 95 | | |
74 | 96 | | |
75 | 97 | | |
| |||
1845 | 1867 | | |
1846 | 1868 | | |
1847 | 1869 | | |
1848 | | - | |
1849 | | - | |
1850 | | - | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
1851 | 1886 | | |
1852 | 1887 | | |
1853 | 1888 | | |
1854 | 1889 | | |
1855 | 1890 | | |
1856 | 1891 | | |
1857 | | - | |
1858 | | - | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
1859 | 1906 | | |
1860 | 1907 | | |
1861 | 1908 | | |
| |||
0 commit comments