Skip to content

Commit 36cf0e6

Browse files
committed
SpatialMatch: Add AZERTY keyboard support
- data-scripts/build_keyboard_adjacency_graphs.py: - switch to unicode to allow to handle not-ascii characters in keyboad layouts - make some assertion errors more explicit - add AZERTY keyboard layout - src/Matchers/SpatialMatch.php: add AZERTY keyboard layout - src/Matchers/adjacency_graphs.json: update it using new build_keyboard_adjacency_graphs.py script to add AZERTY keyboard layout
1 parent 5268743 commit 36cf0e6

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

data-scripts/build_keyboard_adjacency_graphs.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python
2+
# coding: utf-8
23
import sys
34
import json as simplejson
45

@@ -10,29 +11,36 @@ def usage():
1011
%s src/Matchers/adjacency_graphs.json
1112
''' % sys.argv[0]
1213

13-
qwerty = r'''
14+
qwerty = u'''
1415
`~ 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0) -_ =+
1516
qQ wW eE rR tT yY uU iI oO pP [{ ]} \|
1617
aA sS dD fF gG hH jJ kK lL ;: '"
1718
zZ xX cC vV bB nN mM ,< .> /?
1819
'''
1920

20-
dvorak = r'''
21+
azerty = u'''
22+
œŒ“ &1´ é2~ "3# '4{ (5[ -6| è7` _8\\ ç9^ à0@ )°] =+}
23+
aAâ zZå eE€ rRç tTþ yYý uUû iIî oOô pP¶ ^"~ $£ê
24+
qQÂ sSø dDÊ fF± gGæ hHð jJÛ kKÎ lLÔ mM¹ ù%² *µ³
25+
<>| wW« xX» cC© vV® bBß nN¬ ,?¿ ;.× :/÷ !§¡
26+
'''
27+
28+
dvorak = u'''
2129
`~ 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0) [{ ]}
2230
'" ,< .> pP yY fF gG cC rR lL /? =+ \|
2331
aA oO eE uU iI dD hH tT nN sS -_
2432
;: qQ jJ kK xX bB mM wW vV zZ
2533
'''
2634

27-
keypad = r'''
35+
keypad = u'''
2836
/ * -
2937
7 8 9 +
3038
4 5 6
3139
1 2 3
3240
0 .
3341
'''
3442

35-
mac_keypad = r'''
43+
mac_keypad = u'''
3644
= / *
3745
7 8 9 -
3846
4 5 6 +
@@ -68,13 +76,21 @@ def build_graph(layout_str, slanted):
6876
token_size = len(tokens[0])
6977
x_unit = token_size + 1 # x position unit len is token len plus 1 for the following whitespace.
7078
adjacency_func = get_slanted_adjacent_coords if slanted else get_aligned_adjacent_coords
71-
assert all(len(token) == token_size for token in tokens), 'token len mismatch:\n ' + layout_str
72-
for y, line in enumerate(layout_str.split('\n')):
79+
for token in tokens:
80+
assert len(token) == token_size, (
81+
u'token "%s" len mismatch (%d != %d):\n%s ' % (
82+
token, len(token), token_size, layout_str
83+
).encode('utf-8')
84+
)
85+
for y, line in enumerate(layout_str.split(u'\n')):
7386
# the way I illustrated keys above, each qwerty row is indented one space in from the last
7487
slant = y - 1 if slanted else 0
7588
for token in line.split():
7689
x, remainder = divmod(line.index(token) - slant, x_unit)
77-
assert remainder == 0, 'unexpected x offset for %s in:\n%s' % (token, layout_str)
90+
assert remainder == 0, (
91+
u'unexpected x offset for %s (%d != 0) in:\n%s' % (
92+
token, remainder, layout_str)
93+
).encode('utf8')
7894
position_table[(x,y)] = token
7995

8096
adjacency_graph = {}
@@ -96,10 +112,11 @@ def build_graph(layout_str, slanted):
96112
with open(sys.argv[1], 'w') as f:
97113
data = {
98114
'qwerty': build_graph(qwerty, True),
115+
'azerty': build_graph(azerty, True),
99116
'dvorak': build_graph(dvorak, True),
100117
'keypad': build_graph(keypad, False),
101118
'mac_keypad': build_graph(mac_keypad, False),
102119
}
103-
simplejson.dump(data, f)
120+
f.write(simplejson.dumps(data, ensure_ascii=False).encode('utf8'))
104121
sys.exit(0)
105122

src/Matchers/SpatialMatch.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public static function getAdjacencyGraphs(): array
208208
// can be found in multiple graphs (such as 789), the one that's listed first is that one that will be picked.
209209
$data = [
210210
'qwerty' => $data['qwerty'],
211+
'azerty' => $data['azerty'],
211212
'dvorak' => $data['dvorak'],
212213
'keypad' => $data['keypad'],
213214
'mac_keypad' => $data['mac_keypad'],

0 commit comments

Comments
 (0)