Simple utility to turn swipes into words -- "plugin" for wvkbd to enable swipe-typing under wayland SXMO.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
import sys

def makeMap(filename):
  l= [(0,0) for x in range(0,127)]
  with open(filename) as f:
    x=0;y=0
    while 1:
      c = f.read(1)
      if c == '\t':
        x=x+1
      elif c == '\n':
        x=0;y=y+1
      elif c:
        l[ord(c)] =(x,y)
      else:
        break
  return l

def scoreWord(word,mm):
  pc=word[0] or ' '
  s=0
  for c in word:
    #manhattan dist
    s+=abs(mm[ord(pc)][0]-mm[ord(c)][0])
    s+=abs(mm[ord(pc)][1]-mm[ord(c)][1])
    pc=c
  return s

def main(argv):
  mm=makeMap(argv[1])
  while 1:
   line = sys.stdin.readline()
   if not line:
     break
   w=line.strip()
   if w:
    print(scoreWord(w,mm),w,sep='\t')

if __name__ == '__main__':
  main(sys.argv)