{"id":14964400,"url":"https://github.com/user202729/plover-python-dictionary-lib","last_synced_at":"2025-07-20T08:06:41.326Z","repository":{"id":44921595,"uuid":"369390360","full_name":"user202729/plover-python-dictionary-lib","owner":"user202729","description":"Library for writing Python dictionary for Plover, and generating JSON dictionary file from Python dictionary.","archived":false,"fork":false,"pushed_at":"2024-10-23T04:45:48.000Z","size":90,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-24T23:05:08.534Z","etag":null,"topics":["plover","plover-plugins"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/user202729.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-21T02:20:13.000Z","updated_at":"2024-10-23T04:45:52.000Z","dependencies_parsed_at":"2024-07-29T22:52:52.278Z","dependency_job_id":"440dcbfe-983a-4ee8-967d-6101e84e8ca8","html_url":"https://github.com/user202729/plover-python-dictionary-lib","commit_stats":{"total_commits":51,"total_committers":2,"mean_commits":25.5,"dds":"0.039215686274509776","last_synced_commit":"6cce2f2e78936f1c3a0652d72e18f78721e31dc3"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/user202729/plover-python-dictionary-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/user202729%2Fplover-python-dictionary-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/user202729%2Fplover-python-dictionary-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/user202729%2Fplover-python-dictionary-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/user202729%2Fplover-python-dictionary-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/user202729","download_url":"https://codeload.github.com/user202729/plover-python-dictionary-lib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/user202729%2Fplover-python-dictionary-lib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266087790,"owners_count":23874519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["plover","plover-plugins"],"created_at":"2024-09-24T13:33:07.821Z","updated_at":"2025-07-20T08:06:41.304Z","avatar_url":"https://github.com/user202729.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# plover-python-dictionary-lib\n\n[![PyPI](https://img.shields.io/pypi/v/plover-python-dictionary-lib?style=flat)](https://pypi.python.org/pypi/plover-python-dictionary-lib/)\n\nLibrary for writing Python dictionary for Plover,\nand generating JSON dictionary file from Python dictionary.\n\nA Python dictionary is a Plover dictionary that is written in Python.\nRefer to [documentation of the `plover-python-dictionary` package](https://pypi.org/project/plover-python-dictionary/)\nto see what is the advantage of a Python dictionary.\n\nThis library provides some convenient helper tools to write a dictionary.\n\n### Installation\n\nThis package is available on \n[PyPI](https://pypi.org/project/plover-python-dictionary-lib/).\nTo install it, run the command\n\n```bash\npip install plover-python-dictionary-lib\n```\n\nThis is required to use/run the Python dictionaries that use this library.\n\n### Example \u0026 Usage\n\n#### Getting started\n\nThis is a minimal example of a Python dictionary. You can save it as `helloworld.py` and load it into Plover, provided\n`plover-python-dictionary` package is installed.\n\n```python\n#!/bin/python3\nfrom plover.system import english_stenotype as e\nfrom plover_python_dictionary_lib import get_context_from_system\ncontext=get_context_from_system(e)\ns=context.SingleDictionary\nstroke=context.stroke\ntranslation=context.translation\n\ndictionary=s({\n\t\"S\": \"hello world\"\n\t})\n\nlookup = lambda strokes: dictionary.lookup_tuple(strokes)\nLONGEST_KEY = dictionary.longest_key\n\nif __name__==\"__main__\":\n\tdictionary.print_items()\n```\n\nWhen loaded into Plover, it will define a dictionary with a single translation, as suggested by the `dictionary` variable.\n\nIt can also be run as a standalone Python script to print out the JSON dictionary it would corresponds to.\nRefer to [\"Generate JSON\" section](#generate-json) for details.\n\n#### Dictionary Operations\n\nThe power of the package comes from the variety of built-in functions that allows manipulating the components easily\nto build up a whole dictionary.\n\nWhen you have built up the desired dictionary, simply assign it to the `dictionary` variable, and set `lookup` and `LONGEST_KEY` correspondingly.\n\nYou can experiment with the operators simply by running the necessary imports in a Python shell;\nalternatively, just run the Python file standalone to print out the content of the dictionary.\n\n* The `|` operator\n\t* Compute the union of two dictionaries together (basically updating one dictionary with another as like a normal python dictionary)\n```python\nyou = s({\"KPWR\": \"you\"})\nthey = s({\"TWH\": \"they\"})\ndict1 = you | they\ndict1.print_items()\n# {\"KPWR\": \"you\", \"TWH\": \"they\"}\n```\n\n* The `*` operator\n\t* Compute the Cartesian product of two dictionaries such that:\n\t\t* Adjacent strokes are merged as according to steno order\n\t\t* Adjacent translations are merged using the `+` operator\n\t* Example:\n```python\ndict1 = s({\n\t\t\"KPWR\": \"you\",\n\t\t\"TWH\": \"they\"\n\t})\ndict2 = s({\n\t\t\"-R\": \" are\"\n\t})\ndict = dict1 * dict2\ndict.print_items()\n# {\"KPWR-R\": \"you are\", \"TWH-R\": \"they are\"}\n```\n\n#### `map()` method\n\nAllows you to modify the content of an existing dictionary.\n```python\n\u003e\u003e\u003e dict1 = s({\"S\": \"is\", \"K\": \"can\"})\n\u003e\u003e\u003e dict1.map(lambda x: x*2)\nMappedDictionary({(S,): 'isis', (K,): 'cancan'})\n```\n\nYou can also map over the keys provided the arguments are specially named as `strokes` and `result`:\n```python\n\u003e\u003e\u003e dict1.map(lambda strokes, result: f\"{result} ({strokes})\")\nMappedDictionary({(S,): 'is ((S,))', (K,): 'can ((K,))'})\n```\n\nYou can also customize the argument names:\n\n```python\ndef applyMods(mods, characters):\n\tfor mod in mods:\n\t\tcharacters = f\"{mod}({characters})\"\n\treturn characters\nmods = s({\"-R\": [\"shift\"], \"\": []}).named(\"mods\") \ncharacters = s({\"A\": \"a\"}).named(\"characters\")\ndict = (mods * characters).map(applyMods)\ndict.print_items()\n# {\"AR\": \"shift(a)\", \"A\": \"a\"}\n```\nIn this case, `named(\"characters\")` marks that the translation of the `characters` dictionary is\nto be passed to the argument named `characters` in `applyMods`.\n\n#### Extra\n\n* You can read\n\t* [`00_two_letter_fingerspelling_example` example dictionary file](https://github.com/user202729/plover-python-dictionary-lib/blob/main/example/00_two_letter_fingerspelling_example.py) (GitHub link) for an example (this one is the most well-documented example file, with common patterns and explanation),\n\t* the rest of the files in the [`example/` folder](https://github.com/user202729/plover-python-dictionary-lib/tree/main/example),\n\t* and the documentation (as Python docstrings) in the source code,\n* Useful resources: [Frequently used dictionary components](https://github.com/user202729/plover-python-dictionary-lib/wiki/Frequently-used-dictionary-components) *(feel free to edit the wiki)*\n\n### Generate JSON\n\nThe Python dictionary must be written with this plugin.\n\nCall `.print_items()` on the main `Dictionary` object. (see also the example dictionaries above)\n\n\nFor example: if this code\nis included at the end of the Python dictionary file named `dictionary.py`\n\n```python\nif __name__==\"__main__\":\n\tdictionary.print_items()\n```\n\n(assuming that the main dictionary object is named `dictionary`) then running `python dictionary.py`\nwill print the dictionary as JSON to the standard output.\n\n**Note**: If you get the error:\n```\nModuleNotFoundError: No module named 'plover'\n```\nit means Plover was installed in a different Python *environment* from the environment that you ran the script in.\n\nIt depends on the operating-system and specific installation method how to run it in the correct environment. See https://github.com/user202729/plover-python-dictionary-lib/issues/4 for an example.\n\n**Note** (fixed bug, affects old version only): because of [an incompatibility between Plover and the `plover_stroke` library](https://github.com/benoit-pierre/plover_stroke/issues/1),\nsometimes the JSON dictionary may not work in Plover.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuser202729%2Fplover-python-dictionary-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuser202729%2Fplover-python-dictionary-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuser202729%2Fplover-python-dictionary-lib/lists"}