wrongkeys 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wrongkeys/__init__.py +20 -0
- wrongkeys/__main__.py +3 -0
- wrongkeys/cli.py +102 -0
- wrongkeys/convert.py +125 -0
- wrongkeys/data/__init__.py +1 -0
- wrongkeys/data/ar.py +109 -0
- wrongkeys/data/el.py +105 -0
- wrongkeys/data/en.py +129 -0
- wrongkeys/data/he.py +106 -0
- wrongkeys/data/ru.py +102 -0
- wrongkeys/data/uk.py +103 -0
- wrongkeys/engine.py +450 -0
- wrongkeys/layouts.py +286 -0
- wrongkeys/models.py +277 -0
- wrongkeys-0.1.2.dist-info/METADATA +433 -0
- wrongkeys-0.1.2.dist-info/RECORD +20 -0
- wrongkeys-0.1.2.dist-info/WHEEL +5 -0
- wrongkeys-0.1.2.dist-info/entry_points.txt +2 -0
- wrongkeys-0.1.2.dist-info/licenses/LICENSE +21 -0
- wrongkeys-0.1.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wrongkeys
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Detect and repair text typed with the wrong keyboard layout (English with Arabic, Hebrew, Russian, Ukrainian, Greek).
|
|
5
|
+
Author: wrongkeys contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/RealAoss/wrongkeys
|
|
8
|
+
Project-URL: Issues, https://github.com/RealAoss/wrongkeys/issues
|
|
9
|
+
Keywords: keyboard,layout,arabic,hebrew,russian,ukrainian,greek,transliteration
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# wrongkeys
|
|
27
|
+
|
|
28
|
+
Detect and repair text that was typed with the wrong keyboard layout active.
|
|
29
|
+
|
|
30
|
+
You meant to write Arabic, the keyboard was still on English, and you got
|
|
31
|
+
`hgsghl ugd;l`. Or you meant English and got a row of Cyrillic letters.
|
|
32
|
+
`wrongkeys` maps the key presses back to the layout you meant, and tries to
|
|
33
|
+
tell when that is needed and when the text is fine as it is.
|
|
34
|
+
|
|
35
|
+
Pure Python, standard library only, Python 3.10 or newer. No data files are
|
|
36
|
+
downloaded; the small language models are part of the source.
|
|
37
|
+
|
|
38
|
+
## The problem, one example per language
|
|
39
|
+
|
|
40
|
+
Each line shows what ended up on screen and what the same key presses give on
|
|
41
|
+
the intended layout.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
>>> from wrongkeys import fix
|
|
45
|
+
>>> fix("hgsghl ugd;l") # meant Arabic, keyboard was on English
|
|
46
|
+
'السلام عليكم'
|
|
47
|
+
>>> fix("akuo guko") # meant Hebrew
|
|
48
|
+
'שלום עולם'
|
|
49
|
+
>>> fix("ghbdtn? rfr ltkf&") # meant Russian
|
|
50
|
+
'привет, как дела?'
|
|
51
|
+
>>> fix("lzre. pf ljgjvjue") # meant Ukrainian
|
|
52
|
+
'дякую за допомогу'
|
|
53
|
+
>>> fix("kalhm;era ti k;aneiw") # meant Greek
|
|
54
|
+
'καλημέρα τι κάνεις'
|
|
55
|
+
>>> fix("руддщ цщкдв") # meant English, keyboard was on Russian
|
|
56
|
+
'hello world'
|
|
57
|
+
>>> fix("اثممخ صخقمي") # meant English, keyboard was on Arabic
|
|
58
|
+
'hello world'
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Supported pairs: English (US QWERTY) with each of Arabic (101), Hebrew
|
|
62
|
+
(SI-1452), Russian (ЙЦУКЕН), Ukrainian and Greek, in both directions.
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
pip install git+https://github.com/RealAoss/wrongkeys
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The package is not published on a package index; install it from the
|
|
71
|
+
repository as shown. It has no dependencies.
|
|
72
|
+
|
|
73
|
+
## Python API
|
|
74
|
+
|
|
75
|
+
### convert(text, src, dst)
|
|
76
|
+
|
|
77
|
+
A deterministic remap of every character from one layout to another. No
|
|
78
|
+
guessing is involved. Shift state is kept, characters the source layout cannot
|
|
79
|
+
produce pass through unchanged.
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
>>> from wrongkeys import convert
|
|
83
|
+
>>> convert("ghbdtn", "en", "ru")
|
|
84
|
+
'привет'
|
|
85
|
+
>>> convert("Привет, мир!", "ru", "en")
|
|
86
|
+
'Ghbdtn? vbh!'
|
|
87
|
+
>>> convert("akuo", "en", "he")
|
|
88
|
+
'שלום'
|
|
89
|
+
>>> convert("kalhm;era", "en", "el") # ';' is the Greek accent dead key
|
|
90
|
+
'καλημέρα'
|
|
91
|
+
>>> convert("ghbdtn 😀", "en", "ru") # unknown characters are left alone
|
|
92
|
+
'привет 😀'
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The Arabic `B` key types two characters, lam and alef. Going back from Arabic
|
|
96
|
+
to key presses is therefore ambiguous, because the same two letters can also
|
|
97
|
+
be typed as `G` then `H`. `convert` always assumes the single key;
|
|
98
|
+
`conversions` lists the alternatives:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
>>> from wrongkeys import convert, conversions
|
|
102
|
+
>>> convert("b", "en", "ar")
|
|
103
|
+
'لا'
|
|
104
|
+
>>> convert("high", "en", "ar")
|
|
105
|
+
'اهلا'
|
|
106
|
+
>>> convert("اهلا", "ar", "en")
|
|
107
|
+
'hib'
|
|
108
|
+
>>> conversions("اهلا", "ar", "en")
|
|
109
|
+
['hib', 'high']
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### detect(text)
|
|
113
|
+
|
|
114
|
+
Judges the text as a whole and returns a `Guess`.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
>>> from wrongkeys import detect
|
|
118
|
+
>>> guess = detect("hgsghl ugd;l")
|
|
119
|
+
>>> guess.mistyped, guess.typed_layout, guess.language
|
|
120
|
+
(True, 'en', 'ar')
|
|
121
|
+
>>> guess.repaired
|
|
122
|
+
'السلام عليكم'
|
|
123
|
+
>>> guess.confidence > 0.9, guess.runner_up
|
|
124
|
+
(True, 'keep')
|
|
125
|
+
>>> detect("hello world").mistyped
|
|
126
|
+
False
|
|
127
|
+
>>> detect("id").mistyped # could be Arabic 'هي', but two letters prove nothing
|
|
128
|
+
False
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Fields of `Guess`:
|
|
132
|
+
|
|
133
|
+
| field | meaning |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| `mistyped` | `True` if the whole text looks typed on the wrong layout |
|
|
136
|
+
| `language` | the intended language if mistyped, otherwise the language the text is in as written (`None` if unknown) |
|
|
137
|
+
| `typed_layout` | the layout that was active, or `None` |
|
|
138
|
+
| `repaired` | the remapped text if mistyped, otherwise the input unchanged |
|
|
139
|
+
| `confidence` | 0 to 1, computed from the score margin between the best and the second-best explanation. It is not a calibrated probability. |
|
|
140
|
+
| `runner_up` | the second-best explanation: `"keep"` or a pair such as `"en->ru"` |
|
|
141
|
+
|
|
142
|
+
`detect` answers for the text as a whole. A sentence that is only partly
|
|
143
|
+
mistyped is reported as not mistyped; use `fix` for that.
|
|
144
|
+
|
|
145
|
+
### fix(text)
|
|
146
|
+
|
|
147
|
+
Repairs the mistyped parts and leaves the rest alone. It works word by word
|
|
148
|
+
with context, one line at a time.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
>>> from wrongkeys import fix
|
|
152
|
+
>>> fix("I said ghbdtn vbh to him")
|
|
153
|
+
'I said привет мир to him'
|
|
154
|
+
>>> fix("yfgbib vyt yf user@example.com gj;fkeqcnf")
|
|
155
|
+
'напиши мне на user@example.com пожалуйста'
|
|
156
|
+
>>> fix("pfgecnb `git status` gj;fkeqcnf")
|
|
157
|
+
'запусти `git status` пожалуйста'
|
|
158
|
+
>>> fix("hello world")
|
|
159
|
+
'hello world'
|
|
160
|
+
>>> fix("for i in range(10): print(i)")
|
|
161
|
+
'for i in range(10): print(i)'
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
These are never changed: URLs that start with a scheme (`https://`) or
|
|
165
|
+
`www.`; domain names (two or more characters before the first dot), with
|
|
166
|
+
or without a path, whose last label is a known
|
|
167
|
+
top-level domain, either ASCII (`.com`, `.ru`, ...) or internationalised in
|
|
168
|
+
any script (`яндекс.рф`, `.укр`, `.срб`, `.ελ`, `.ישראל`, `.السعودية`,
|
|
169
|
+
`.امارات`, `.مصر`, ...; the list is `_IDN_TLDS` in `engine.py`); e-mail
|
|
170
|
+
addresses (non-ASCII ones only at such a domain); code spans in backticks
|
|
171
|
+
and fenced code blocks. Among tokens written in ASCII, the following are
|
|
172
|
+
never changed as well: `@handles`, `#tags`, anything containing a digit,
|
|
173
|
+
file names with a common extension (`main.py`) and tokens that look like
|
|
174
|
+
code (`snake_case`, `f(x)`, `a=b`, `--flag`, paths). A domain whose
|
|
175
|
+
top-level domain is not on the lists is treated like any other word.
|
|
176
|
+
|
|
177
|
+
## Command line
|
|
178
|
+
|
|
179
|
+
```console
|
|
180
|
+
$ wrongkeys fix "hgsghl ugd;l"
|
|
181
|
+
السلام عليكم
|
|
182
|
+
$ wrongkeys fix "I said ghbdtn vbh to him"
|
|
183
|
+
I said привет мир to him
|
|
184
|
+
$ echo "ghbdtn vbh" | wrongkeys fix
|
|
185
|
+
привет мир
|
|
186
|
+
$ wrongkeys convert --from en --to he "akuo"
|
|
187
|
+
שלום
|
|
188
|
+
$ wrongkeys detect "kalhm;era"
|
|
189
|
+
mistyped: typed on en, meant el (confidence 0.84, runner-up keep)
|
|
190
|
+
καλημέρα
|
|
191
|
+
$ wrongkeys detect "hello world"
|
|
192
|
+
not mistyped: looks like en (confidence 0.98, runner-up en->ar)
|
|
193
|
+
$ wrongkeys detect --json "ghbdtn vbh"
|
|
194
|
+
{"mistyped": true, "language": "ru", "typed_layout": "en", "repaired": "привет мир", "confidence": 0.963, "runner_up": "en->ar"}
|
|
195
|
+
$ wrongkeys layouts
|
|
196
|
+
ar Arabic (101, Windows) [unshifted sure; shifted layer moderately sure]
|
|
197
|
+
...
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
`fix`, `convert` and `detect` read standard input when no text is given.
|
|
201
|
+
Input and output are always UTF-8, also on Windows, so the tool can be used
|
|
202
|
+
in pipes there. A UTF-8 byte order mark at the start of standard input (as
|
|
203
|
+
saved by Notepad or PowerShell) is dropped; output never has one.
|
|
204
|
+
`python -m wrongkeys` works the same way as the `wrongkeys`
|
|
205
|
+
command.
|
|
206
|
+
|
|
207
|
+
## How detection works
|
|
208
|
+
|
|
209
|
+
There is no third-party data in the package. For each of the six languages it
|
|
210
|
+
contains a few hundred common words, some first names and about forty sample
|
|
211
|
+
sentences, all written by hand for this project (`src/wrongkeys/data/`). From
|
|
212
|
+
that material two things are built at import time:
|
|
213
|
+
|
|
214
|
+
1. a word list, and
|
|
215
|
+
2. a character trigram model with Witten-Bell backoff.
|
|
216
|
+
|
|
217
|
+
A piece of text gets a plausibility score for a language: the log-likelihood
|
|
218
|
+
of its letters under the trigram model, minus the log-likelihood under
|
|
219
|
+
uniformly random letters, plus a bonus for words in the word list, minus
|
|
220
|
+
penalties for characters that do not belong (letters of another script,
|
|
221
|
+
`;` in the middle of a word, and so on). Positive means "looks like this
|
|
222
|
+
language", negative means "looks like noise".
|
|
223
|
+
|
|
224
|
+
Every whitespace-separated token is scored as written and after remapping
|
|
225
|
+
with each of the ten layout pairs. A remap is considered only where the
|
|
226
|
+
remapped text scores higher than the original by a margin, and several
|
|
227
|
+
conservative rules apply on top:
|
|
228
|
+
|
|
229
|
+
- at least four letters in words of three or more letters must be involved;
|
|
230
|
+
- a result shorter than six letters must contain a listed word;
|
|
231
|
+
- single letters and bare punctuation never count as evidence;
|
|
232
|
+
- English to Greek needs extra evidence, because the Greek layout is close to
|
|
233
|
+
phonetic and Latin words turn into Greek-looking strings easily;
|
|
234
|
+
- protected tokens (URLs, numbers, code, see above) are never touched.
|
|
235
|
+
|
|
236
|
+
`detect` applies this to the whole text. `fix` runs a Viterbi pass over the
|
|
237
|
+
tokens of each line with a cost for switching between "keep" and "remap", so
|
|
238
|
+
a run of mistyped words inside a correct sentence is found, and a short word
|
|
239
|
+
inside a mistyped run is carried along.
|
|
240
|
+
|
|
241
|
+
For Arabic, both readings of lam-alef (one key or two) are tried and the one
|
|
242
|
+
that gives better English is used.
|
|
243
|
+
|
|
244
|
+
All thresholds were set by hand on the development set described below.
|
|
245
|
+
|
|
246
|
+
## Layout tables and how sure they are
|
|
247
|
+
|
|
248
|
+
The tables in `src/wrongkeys/layouts.py` were written from memory. They
|
|
249
|
+
describe the default **Windows / PC** layouts. `wrongkeys layouts` prints the
|
|
250
|
+
list of uncertain keys; the same notes are in the source.
|
|
251
|
+
|
|
252
|
+
| layout | sure | not sure |
|
|
253
|
+
| --- | --- | --- |
|
|
254
|
+
| English, US QWERTY | everything | |
|
|
255
|
+
| Russian, ЙЦУКЕН | letters and the shifted number row | |
|
|
256
|
+
| Ukrainian | letters | the key left of `1` (assumed `'` and `₴`, as in the "Enhanced" layout); the backslash key; `ґ` is not on any modelled key and passes through unchanged |
|
|
257
|
+
| Greek | letters, final sigma on `W`, tonos dead key on `;` | Shift+`;` (assumed dialytika dead key), Shift+`W` (assumed dialytika-tonos dead key), the exact characters a dead key leaves when no vowel follows |
|
|
258
|
+
| Hebrew, SI-1452 | letters | the punctuation that moves (`q` `w` `'` `/` and the key left of `1`), and the assumption that `( ) [ ] { } < >` are mirrored |
|
|
259
|
+
| Arabic 101 | the whole unshifted layer, including the two-character lam-alef key on `B` | the shifted layer: which key carries which diacritic, the bracket and brace keys on Shift+`D F C V`, Shift+`[ ]`, the quote characters on Shift+`U M`, `÷` and `×` on Shift+`I O`, mirrored parentheses, Shift+`Z` |
|
|
260
|
+
|
|
261
|
+
Consequences: plain words typed without Shift convert reliably in all five
|
|
262
|
+
languages. Text that depends on an uncertain key (Arabic diacritics, Hebrew
|
|
263
|
+
brackets, a Ukrainian apostrophe) may convert to the wrong character.
|
|
264
|
+
|
|
265
|
+
Not modelled at all: AltGr (third-level) characters, Caps Lock, the extra key
|
|
266
|
+
of ISO keyboards, Hebrew niqqud, and the newer Hebrew SI-1452-2 layout.
|
|
267
|
+
|
|
268
|
+
## Evaluation
|
|
269
|
+
|
|
270
|
+
`bench/dataset.py` is a development set written for this project:
|
|
271
|
+
200 phrases per language (60 with four or more words, 70 with two or three
|
|
272
|
+
words, 70 single words including ten names and ten very short words), plus
|
|
273
|
+
581 items that must be left alone (code, URLs and e-mail addresses, numbers,
|
|
274
|
+
short tokens and abbreviations, English words, names and Latin-script text in
|
|
275
|
+
other languages, mixed-language sentences). Every phrase is used twice: as
|
|
276
|
+
written, where it must not be changed, and remapped to the wrong layout with
|
|
277
|
+
`convert`, where it must be repaired. English phrases are mistyped on each of
|
|
278
|
+
the five other layouts. Arabic phrases that contain lam-alef are included
|
|
279
|
+
twice, typed with the `B` key and typed with `G` `H`.
|
|
280
|
+
|
|
281
|
+
Run it with:
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
PYTHONPATH=src python bench/run.py
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Results of a run on 2026-11-24 (Python 3.14, 2026 mistyped items, 1781
|
|
288
|
+
correct items). "Exact repair" means `fix()` returned the intended text
|
|
289
|
+
character for character. "Wrongly changed" is the share of correct texts that
|
|
290
|
+
`fix()` altered.
|
|
291
|
+
|
|
292
|
+
| | detect precision | detect recall | exact repair | repaired wrongly | correct text wrongly changed |
|
|
293
|
+
| --- | --- | --- | --- | --- | --- |
|
|
294
|
+
| wrongkeys, all | 100.0% | 88.2% | 88.1% | 0.1% | 0.0% (0 of 1781) |
|
|
295
|
+
| wrongkeys, 1 word | 100.0% | 68.0% | 68.0% | 0.0% | 0.0% (0 of 905) |
|
|
296
|
+
| wrongkeys, 2-3 words | 100.0% | 97.7% | 97.5% | 0.3% | 0.0% (0 of 469) |
|
|
297
|
+
| wrongkeys, 4+ words | 100.0% | 100.0% | 100.0% | 0.0% | 0.0% (0 of 407) |
|
|
298
|
+
| naive baseline, all | 79.0% | 90.9% | 88.2% | 2.7% | 27.6% (491 of 1781) |
|
|
299
|
+
| naive baseline, 1 word | 61.7% | 95.9% | 94.0% | 1.9% | 46.2% (418 of 905) |
|
|
300
|
+
| naive baseline, 2-3 words | 91.2% | 94.2% | 89.5% | 4.7% | 13.6% (64 of 469) |
|
|
301
|
+
| naive baseline, 4+ words | 98.2% | 81.5% | 80.1% | 1.5% | 2.2% (9 of 407) |
|
|
302
|
+
|
|
303
|
+
The baseline is: if the text is ASCII and none of its words is in the English
|
|
304
|
+
word list, remap it to the layout whose word list matches most words; if it
|
|
305
|
+
is in another script and none of its words is in that language's list, remap
|
|
306
|
+
it to English. It repairs about as many mistyped items as `wrongkeys`, and it
|
|
307
|
+
damages more than a quarter of the correct texts.
|
|
308
|
+
|
|
309
|
+
Exact repair by intended language and length (wrongkeys):
|
|
310
|
+
|
|
311
|
+
| intended | 1 word | 2-3 words | 4+ words | all |
|
|
312
|
+
| --- | --- | --- | --- | --- |
|
|
313
|
+
| Arabic | 52.8% | 96.3% | 100.0% | 83.7% |
|
|
314
|
+
| Greek | 65.7% | 95.6% | 100.0% | 86.5% |
|
|
315
|
+
| English | 74.2% | 98.6% | 100.0% | 90.5% |
|
|
316
|
+
| Hebrew | 41.4% | 94.3% | 100.0% | 77.5% |
|
|
317
|
+
| Russian | 78.6% | 98.6% | 100.0% | 92.0% |
|
|
318
|
+
| Ukrainian | 71.4% | 97.1% | 100.0% | 89.0% |
|
|
319
|
+
|
|
320
|
+
Correct text wrongly changed was 0 in every language and in every leave-alone
|
|
321
|
+
category on this set.
|
|
322
|
+
|
|
323
|
+
The same run also passes the English help text that ships with Python
|
|
324
|
+
(`pydoc_data.topics`, technical prose with many code fragments, not written
|
|
325
|
+
for this project) through `fix()`: 4 of 10696 lines were wrongly changed
|
|
326
|
+
(0.04%), all of them lines of code-like tokens such as `"pdb.Pdb"`, and none
|
|
327
|
+
of 3717 distinct words when given alone.
|
|
328
|
+
|
|
329
|
+
### How to read these numbers
|
|
330
|
+
|
|
331
|
+
- **They are optimistic.** The development set was written by the same author
|
|
332
|
+
as the word lists, the thresholds were tuned on it, and a second batch of
|
|
333
|
+
vocabulary was added to the word lists after looking at its failures.
|
|
334
|
+
Between 59% and 92% of the distinct words in the development set are in the
|
|
335
|
+
built-in word lists (`bench/run.py` prints the figure per language). Real
|
|
336
|
+
text has a much wider vocabulary.
|
|
337
|
+
- **Single words are weak, by design.** A run needs at least four letters in
|
|
338
|
+
words of three or more letters before anything is changed, so one- to
|
|
339
|
+
three-letter inputs are never repaired. Most of the missing single-word
|
|
340
|
+
recall is exactly that: common three-letter words, which are especially
|
|
341
|
+
frequent in Arabic and Hebrew. Lowering the limit repaired more of them
|
|
342
|
+
but started to change correct short words (an English `gym` became an
|
|
343
|
+
Arabic word), so the limit stayed.
|
|
344
|
+
- **A zero on 1781 items is not zero.** It bounds the rate of wrongly changed
|
|
345
|
+
text on this kind of input to a fraction of a percent at best, and says
|
|
346
|
+
nothing about text unlike the set. The standard-library check above shows
|
|
347
|
+
the first real failures.
|
|
348
|
+
|
|
349
|
+
### Blind set
|
|
350
|
+
|
|
351
|
+
`bench/blind_data.py` was written by someone who never saw the package, its
|
|
352
|
+
word lists or the development set: 600 phrases (100 per language, chat
|
|
353
|
+
messages, queries, names, slang), 580 leave-alone items in 28 categories, and
|
|
354
|
+
74 pairs where the author worked out the mistyped text key by key from their
|
|
355
|
+
own knowledge of the layouts. It was run once and the engine was not changed
|
|
356
|
+
afterwards. `bench/run.py` prints these numbers.
|
|
357
|
+
|
|
358
|
+
| | detect precision | detect recall | exact repair | correct text wrongly changed |
|
|
359
|
+
|---|---|---|---|---|
|
|
360
|
+
| all | 99.6% | 90.8% | 90.3% | 3/1180 (0.3%) |
|
|
361
|
+
| 1 word | 99.3% | 77.0% | 77.0% | 1/527 |
|
|
362
|
+
| 2-3 words | 99.5% | 94.2% | 93.7% | 1/383 |
|
|
363
|
+
| 4+ words | 100.0% | 99.5% | 98.6% | 1/270 |
|
|
364
|
+
| naive baseline, all | 62.8% | 90.2% | 78.7% | 320/1180 (27.1%) |
|
|
365
|
+
|
|
366
|
+
Exact repair by intended language: uk 93, en 93, ru 91, ar 90, he 90, el 85.
|
|
367
|
+
Single words: uk 87, en 83, ru 81, he 73, ar 70, el 67.
|
|
368
|
+
|
|
369
|
+
The three correct texts that were changed, in full:
|
|
370
|
+
|
|
371
|
+
- the English word `rhythm` (no vowels, so it looks unlike English to the
|
|
372
|
+
trigram model) became Cyrillic;
|
|
373
|
+
- an Iraqi-dialect Arabic sentence was turned into Latin letters: the word
|
|
374
|
+
lists are close to standard Arabic and dialect words are missing;
|
|
375
|
+
- a line of JavaScript, `const sum = (a, b) => a + b;`, had `sum` and the
|
|
376
|
+
single-letter names remapped to Arabic. Do not run `fix` over source code.
|
|
377
|
+
|
|
378
|
+
The 74 hand-typed pairs agree with the layout tables in every case, for
|
|
379
|
+
lowercase letters only; `fix` repaired 73 of them. Punctuation keys, shifted
|
|
380
|
+
layers and the Arabic lam-alef key were not in that check and remain as
|
|
381
|
+
uncertain as the layout section says.
|
|
382
|
+
|
|
383
|
+
## Limits
|
|
384
|
+
|
|
385
|
+
- **Short text.** One to three letters are never changed. Four- and
|
|
386
|
+
five-letter inputs are changed only if the result is a listed word.
|
|
387
|
+
- **Small models.** A few hundred words per language. Rare words, slang,
|
|
388
|
+
dialect, names and technical terms are judged by the trigram model alone,
|
|
389
|
+
which is rough. Expect misses on such text, and occasional wrong repairs on
|
|
390
|
+
unusual Latin-script tokens whose remap happens to look like Arabic or
|
|
391
|
+
Hebrew (seen on identifiers such as `pdb.Pdb`).
|
|
392
|
+
- **Words that are valid both ways.** `اهلا` is an Arabic greeting and also
|
|
393
|
+
`high` typed on the Arabic layout; `μετα` is Greek and also `meta`. Such
|
|
394
|
+
text is left as it is.
|
|
395
|
+
- **Protected tokens can hide real words.** A mistyped word that happens to
|
|
396
|
+
look like a file name or domain (`something.py`; `ищщл.рф`, which is
|
|
397
|
+
`book/ha` typed on the Russian layout), starts with `@` or `#`
|
|
398
|
+
(the Russian opening quote and `№` are on those keys), or contains a digit
|
|
399
|
+
is left alone. A pair of backticks that starts one word and ends another
|
|
400
|
+
is taken for a code span, although the backtick key is a letter on the
|
|
401
|
+
Russian and Arabic layouts.
|
|
402
|
+
- **Mac layouts are not covered.** Apple's Arabic, Hebrew, Russian, Ukrainian
|
|
403
|
+
and Greek layouts differ from the PC ones in several keys.
|
|
404
|
+
- **Uncertain keys**, listed in the table above, mostly on shifted layers.
|
|
405
|
+
- **Caps Lock and AltGr** are not modelled. A capital letter is always
|
|
406
|
+
treated as Shift plus the key, which is not what Caps Lock does on every
|
|
407
|
+
layout (not verified for Arabic and Hebrew).
|
|
408
|
+
- **Only pairs with English.** Russian typed on a Ukrainian layout, or Arabic
|
|
409
|
+
on Hebrew, is not detected. `convert` does handle any pair of the six
|
|
410
|
+
layouts.
|
|
411
|
+
- **Languages not covered:** everything else, including other Cyrillic
|
|
412
|
+
languages (Belarusian, Bulgarian, Serbian, Kazakh), Persian and Urdu (which
|
|
413
|
+
use different Arabic-script layouts), Turkish, and non-US Latin layouts
|
|
414
|
+
such as AZERTY, QWERTZ or UK English.
|
|
415
|
+
- Not a spell checker: it reproduces what the keys would have typed,
|
|
416
|
+
including your typos.
|
|
417
|
+
|
|
418
|
+
## Development
|
|
419
|
+
|
|
420
|
+
```
|
|
421
|
+
python -m unittest discover -s tests -v
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
The tests need no network and no installation; they add `src` to the import
|
|
425
|
+
path themselves. Every example in this README is executed by
|
|
426
|
+
`tests/test_readme.py`.
|
|
427
|
+
|
|
428
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for how to add a layout or correct a
|
|
429
|
+
key, and [CHANGELOG.md](CHANGELOG.md) for the history.
|
|
430
|
+
|
|
431
|
+
## License
|
|
432
|
+
|
|
433
|
+
MIT, see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
wrongkeys/__init__.py,sha256=fAnDktCBvb_VUM5OdGRa9crlUqOEk_DIKzIZRpO-isM,419
|
|
2
|
+
wrongkeys/__main__.py,sha256=k1ocEWawweo1qCJWNFAAvyxz3tcY13dzvCenHszij30,48
|
|
3
|
+
wrongkeys/cli.py,sha256=WDy9mBo8J2tFISUq9ZdVovRt6yWVt1YECwcVZapVwwM,4052
|
|
4
|
+
wrongkeys/convert.py,sha256=-1VxOhTCbthlGFf6jqQIULJ_5MrdBMeQisX97M4XI8U,4146
|
|
5
|
+
wrongkeys/engine.py,sha256=XVBQn_RD1GVEMm35iaN2bPGursdut3OvmtdHYSh_BCM,18198
|
|
6
|
+
wrongkeys/layouts.py,sha256=EH_2qucRQX5A1oZx-6KOekRFdtc8x-buD9KiV0RUiPc,13072
|
|
7
|
+
wrongkeys/models.py,sha256=kSltq11bAnhUea0AVdHjSKsXRfwQQ-9h7nY9RFzNCtA,10474
|
|
8
|
+
wrongkeys/data/__init__.py,sha256=9a-IsDHs0CtzyILo6hT1hh39f9JVxW48TXAwRSuG9eU,77
|
|
9
|
+
wrongkeys/data/ar.py,sha256=pHgSHKSeAXmnBhxr7QdtZoOjhs-Elxs-XOE1u6z-ykw,10286
|
|
10
|
+
wrongkeys/data/el.py,sha256=_C3mLaX4jGnldzVakKecrwQxXFPteTrPhQ_sznb940Y,11036
|
|
11
|
+
wrongkeys/data/en.py,sha256=Ntk1CzhuBwRqsj8EytP8cC2EgxxZS3Y5ggjRfrlfN0c,9017
|
|
12
|
+
wrongkeys/data/he.py,sha256=5L2y20kUUWLoTrMwHR0ggnKoQHllzRRfOzYLv77QDWo,9824
|
|
13
|
+
wrongkeys/data/ru.py,sha256=9FDvGTMKV7dJAqgrBPGN75r4RqdyFa56STH2Rv_uHDQ,11513
|
|
14
|
+
wrongkeys/data/uk.py,sha256=jC4ql30PTNwLShZ9pLzJaR00PjjXLC60LP9kcJkCkcQ,11430
|
|
15
|
+
wrongkeys-0.1.2.dist-info/licenses/LICENSE,sha256=kOtG5CD6okSs7rnlW-hZMFfjfSFoAkagiwD4klRD8so,1079
|
|
16
|
+
wrongkeys-0.1.2.dist-info/METADATA,sha256=0X3Ipv0Ls_V49-h10WtAWomLq7MsV2m2gRBcq_-wSs4,19532
|
|
17
|
+
wrongkeys-0.1.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
18
|
+
wrongkeys-0.1.2.dist-info/entry_points.txt,sha256=nM_9qC8vI38w_1g4yB2pDPhNt8SyWuxHkd_JJ1XoyQ8,49
|
|
19
|
+
wrongkeys-0.1.2.dist-info/top_level.txt,sha256=iLiNv8h7slRyXNEobDyvOxJS1ff75MkYbqr9UiC9tOo,10
|
|
20
|
+
wrongkeys-0.1.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wrongkeys contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wrongkeys
|