Skip to main content

Python dictionaries support for Plover

Project description

Plover Python dictionary

Add support for Python dictionaries to Plover.

Usage

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.

Release history

1.1.0

  • fix type checks for lookup and reverse_lookup: allow bound methods and functors
  • fix reverse_lookup implementation: return a set.
  • fix __getitem__ / get implementations: when the key length is out of bounds
  • fix __contains__ implementation
  • fix __delitem__ / __setitem__ implementations: raise the correct exception type

1.0.0

  • fix possible encoding issue when loading a dictionary: from now on, assume and force UTF-8

0.5.12

  • update changelog...

0.5.11

  • drop support for Python < 3.6
  • fix use of deprecated imp module
  • rework tests to use plover_build_utils.testing
  • use PEP 517/518

0.5.10

  • fix ./setup.py test handling
  • fix default implementation of reverse_lookup to return a list (not a tuple)

0.5.9

  • update to Plover's latest API

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plover_python_dictionary-1.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

plover_python_dictionary-1.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file plover_python_dictionary-1.1.0.tar.gz.

File metadata

  • Download URL: plover_python_dictionary-1.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.5

File hashes

Hashes for plover_python_dictionary-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6251d398cb4a59469d39b19bb2bb05f8f52ca420782abf9a9b2e7b0d0e1e090b
MD5 15bb34a84e2139b8bd0ec89b14515b45
BLAKE2b-256 8dabbcffe845da95f30fc9871ee0423570ad780c7b13c7b1a740da12cc7f5cfc

See more details on using hashes here.

File details

Details for the file plover_python_dictionary-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: plover_python_dictionary-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.5

File hashes

Hashes for plover_python_dictionary-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89073dcdb4500615074f5c04528177a9e81d04ad97f338d4e81b4c81db568f39
MD5 27e12c1e00d4ff9a1e532d911baabed1
BLAKE2b-256 156142845042f6ee303eb4a7c958eff4b0d8b063e93282a653a4dd233195c97c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page