Simple utility to turn swipes into words -- "plugin" for wvkbd to enable swipe-typing under wayland SXMO.
doc changes, minor fix
| -rw-r--r-- | README.md | 11 | ||||
| -rwxr-xr-x | mapScore.py | 17 |
2 files changed, 20 insertions, 8 deletions
@@ -18,6 +18,8 @@ There's a WIP Merge Request towards proycon's wvkbd for an example of this. This should be a list of words, sorted by preferability of choice. +### sorting tips + Note: you probably want longest words first, otherewise, it may be impossible to type them. ``` @@ -26,6 +28,15 @@ ls $PATH | awk '{ print length, $0 }' | sort -nr | cut -d" " -f2- > binsSorted.t ``` +Smarter sorting would be keyboard-layout aware. mapscore.py can do that for you + +```sh +./mapScore.py map.txt <words.txt | sort -nr | cut -f2 > wordsSorted.txt +``` +map.txt uses tabs and newlines to create the grid-based layout. + +### alternate formats + Alternatively, for performance, you can use a directory with the following format: each file is named with the first and last letters of the contained words. The script `makeDir.sh` is provided to help create these. diff --git a/mapScore.py b/mapScore.py index 2385106..61a5259 100755 --- a/mapScore.py +++ b/mapScore.py @@ -17,23 +17,24 @@ def makeMap(filename): break return l -def scoreWord(word,mmap): - pc=word[0] +def scoreWord(word,mm): + pc=word[0] or ' ' s=0 for c in word: #manhattan dist - s+=abs(mmap[ord(pc)][0]-mmap[ord(c)][0]) - s+=abs(mmap[ord(pc)][1]-mmap[ord(c)][1]) + 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() + line = sys.stdin.readline() + if not line: + break + w=line.strip() + if w: print(scoreWord(w,mm),w,sep='\t') if __name__ == '__main__': |