Add support for Python dictionaries to Plover.
A Python dictionary is simply a single UTF-8 source file with the following API:
# Length of the longest supported key (number of strokes).
LONGEST_KEY = 1
# Lookup function: return the translation for <key> (a tuple of strokes)
# or raise KeyError if no translation is available/possible.
def lookup(key):
assert len(key) <= LONGEST_KEY
raise KeyError
# Optional: return an array of stroke tuples that would translate back
# to <text> (an empty array if not possible).
def reverse_lookup(text):
return []
For example save the following code to show_stroke.py
:
Note: make sure the file encoding is UTF-8!
LONGEST_KEY = 2
SHOW_STROKE_STENO = 'STR*'
def lookup(key):
assert len(key) <= LONGEST_KEY, '%d/%d' % (len(key), LONGEST_KEY)
if SHOW_STROKE_STENO != key[0]:
raise KeyError
if len(key) == 1:
return ' '
return key[1]
Then add it to your dictionaries stack as you would a normal dictionary.
Now, if you stroke STR*
, then the next stroke will be shown verbatim
(untranslated), e.g. -T STROEBG TP-R KW-GS STROEBG KR-GS S STR* STROEBG
outputs: the stroke for "stroke" is STROEBG
.
lookup
and reverse_lookup
:reverse_lookup
implementation: return a set.__getitem__
/ get
implementations:__contains__
implementation__delitem__
/ __setitem__
implementations:imp
moduleplover_build_utils.testing
./setup.py test
handlingreverse_lookup
to return a list (not a tuple)