Skip to main content

Library for writing Python dictionary for Plover, and generating JSON dictionary file from Python dictionary.

Project description

plover-python-dictionary-lib

Library for writing Python dictionary for Plover, and generating JSON dictionary file from Python dictionary.

Installation

This package is available on PyPI. To install it, run the command

pip install plover-python-dictionary-lib

This is required to use/run the Python dictionaries that use this library.

Example & Usage

Imports And Setup

  • The example code assumes you have run the code below
from plover.system import english_stenotype as e
from plover_python_dictionary_lib import get_context_from_system
context=get_context_from_system(e)
s=context.SingleDictionary
stroke=context.stroke
translation=context.translation

Dictionary Operations

  • The | operator
    • Compute the union of two dictionaries together (basically updating one dictionary with another as like a normal python dictionary)
you = s({"KPWR": "you"})
they = s({"TWH": "they"})
dict1 = you | they
dict1.print_items()
# {"KPWR": "you", "TWH": "they"}
  • The * operator
    • Compute the Cartesian product of two dictionaries such that:
      • Adjacent strokes are merged as according to steno order
      • Adjacent translations are merged using the + operator
    • Example:
dict1 = s({
		"KPWR": "you",
		"TWH": "they"
	})
dict2 = s({
		"-R": " are"
	})
dict = dict1 * dict2
dict.print_items()
# {"KPWR-R": "you are", "TWH-R": "they are"}

Named Dictionaries

  • Sometimes you want to have custom behavior for your translations
  • For example applying mods on some characters
def applyMods(mods, characters):
	for mod in mods:
		characters = f"{mod}({characters})"
	return characters
mods = s({"-R": ["shift"], "": []}).named("mods") 
characters = s({"A": "a"}).named("characters")
dict = (mods * characters).map(applyMods)
dict.print_items()
# {"AR": "shift(a)", "A": "a"}

Extra Notes

Generate JSON

The Python dictionary must be written with this plugin.

Call .print_items() on the main Dictionary object. (see also the example dictionaries above)

Note: because of an incompatibility between Plover and the plover_stroke library, sometimes the JSON dictionary may not work in Plover.

For example: if this code is included at the end of the Python dictionary file named dictionary.py

if __name__=="__main__":
	dictionary.print_items()

(assuming that the main dictionary object is named dictionary) then running python dictionary.py will print the dictionary as JSON to the standard output.

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_lib-0.4.2.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plover_python_dictionary_lib-0.4.2-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file plover_python_dictionary_lib-0.4.2.tar.gz.

File metadata

  • Download URL: plover_python_dictionary_lib-0.4.2.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.6.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.5

File hashes

Hashes for plover_python_dictionary_lib-0.4.2.tar.gz
Algorithm Hash digest
SHA256 16ff51d15a7ca405263787f52dc1b7dabf514adbacefff97cf3890415c6cb725
MD5 b4ed3364105f61ae143becb32cb8485f
BLAKE2b-256 63d4c3d028fb3e93a78a17f97a18d26aae032a8b2d2e5a770c2e7b4baf6d6923

See more details on using hashes here.

File details

Details for the file plover_python_dictionary_lib-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: plover_python_dictionary_lib-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.6.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.5

File hashes

Hashes for plover_python_dictionary_lib-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 60a9fd26b00a1e995924919c0d2ffdc483c3958ecca80db087f86aec87905a07
MD5 3987c2cc0539035449c09e44c8241c38
BLAKE2b-256 1da70511b25c57e4e08b079fdece17a48bbe3e55e7e6bd5e693667521109c997

See more details on using hashes here.

Supported by

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