plover-python-dictionary


Nameplover-python-dictionary JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/benoit-pierre/plover_python_dictionary
SummaryPython dictionaries support for Plover
upload_time2025-07-09 17:47:44
maintainerNone
docs_urlNone
authorBenoit Pierre
requires_python>=3.6
licenseGNU General Public License v2 or later (GPLv2+)
keywords plover plover_plugin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

``` python
# 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!

``` python
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.2.0

* use importlib instead of exec ([#12](https://github.com/openstenoproject/plover_python_dictionary/pull/12))

### 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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/benoit-pierre/plover_python_dictionary",
    "name": "plover-python-dictionary",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "plover plover_plugin",
    "author": "Benoit Pierre",
    "author_email": "benoit.pierre@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f6/21/94dd2493f1a2b0fdd506a1981cf76745ab82ac27d46ef91da1ee16f5a4fb/plover_python_dictionary-1.2.0.tar.gz",
    "platform": null,
    "description": "# Plover Python dictionary\n\nAdd support for Python dictionaries to Plover.\n\n\n## Usage\n\nA Python dictionary is simply a single UTF-8 source file with the following API:\n\n``` python\n# Length of the longest supported key (number of strokes).\nLONGEST_KEY = 1\n\n# Lookup function: return the translation for <key> (a tuple of strokes)\n# or raise KeyError if no translation is available/possible.\ndef lookup(key):\n    assert len(key) <= LONGEST_KEY\n    raise KeyError\n\n# Optional: return an array of stroke tuples that would translate back\n# to <text> (an empty array if not possible).\ndef reverse_lookup(text):\n    return []\n```\n\nFor example save the following code to `show_stroke.py`:\n\n> **Note**: make sure the file encoding is UTF-8!\n\n``` python\nLONGEST_KEY = 2\n\nSHOW_STROKE_STENO = 'STR*'\n\ndef lookup(key):\n    assert len(key) <= LONGEST_KEY, '%d/%d' % (len(key), LONGEST_KEY)\n    if SHOW_STROKE_STENO != key[0]:\n        raise KeyError\n    if len(key) == 1:\n        return ' '\n    return key[1]\n```\n\nThen add it to your dictionaries stack as you would a normal dictionary.\n\nNow, if you stroke `STR*`, then the next stroke will be shown verbatim\n(untranslated), e.g. `-T STROEBG TP-R KW-GS STROEBG KR-GS S STR* STROEBG`\noutputs: `the stroke for \"stroke\" is STROEBG`.\n\n\n## Release history\n\n### 1.2.0\n\n* use importlib instead of exec ([#12](https://github.com/openstenoproject/plover_python_dictionary/pull/12))\n\n### 1.1.0\n\n* fix type checks for `lookup` and `reverse_lookup`:\n  allow bound methods and functors\n* fix `reverse_lookup` implementation: return a set.\n* fix `__getitem__` / `get` implementations:\n  when the key length is out of bounds\n* fix `__contains__` implementation\n* fix `__delitem__` / `__setitem__` implementations:\n  raise the correct exception type\n\n### 1.0.0\n\n* fix possible encoding issue when loading a dictionary:\n  from now on, assume and force UTF-8\n\n### 0.5.12\n\n* update changelog...\n\n### 0.5.11\n\n* drop support for Python < 3.6\n* fix use of deprecated `imp` module\n* rework tests to use `plover_build_utils.testing`\n* use PEP 517/518\n\n### 0.5.10\n\n* fix `./setup.py test` handling\n* fix default implementation of `reverse_lookup` to return a list (not a tuple)\n\n### 0.5.9\n\n* update to Plover's latest API\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v2 or later (GPLv2+)",
    "summary": "Python dictionaries support for Plover",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/benoit-pierre/plover_python_dictionary"
    },
    "split_keywords": [
        "plover",
        "plover_plugin"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a6930448560ab40860177dedf82f596359dd5f9816d0456681924a36fb3750e0",
                "md5": "a9ba5008edcb2aeaaf8b7167f3e1f7f2",
                "sha256": "f0a888dfa903b7d339e3c1a21dd10a1322594f9a821bc24b545acd32e16fc92c"
            },
            "downloads": -1,
            "filename": "plover_python_dictionary-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a9ba5008edcb2aeaaf8b7167f3e1f7f2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 3960,
            "upload_time": "2025-07-09T17:47:43",
            "upload_time_iso_8601": "2025-07-09T17:47:43.770593Z",
            "url": "https://files.pythonhosted.org/packages/a6/93/0448560ab40860177dedf82f596359dd5f9816d0456681924a36fb3750e0/plover_python_dictionary-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f62194dd2493f1a2b0fdd506a1981cf76745ab82ac27d46ef91da1ee16f5a4fb",
                "md5": "6e6dbe69d1af83bb7892bf51a6a3be4c",
                "sha256": "dbfcdd59b14797efe7b8f5378bbdc25c0985cbb237ed772a2fa1e4f0784d53a5"
            },
            "downloads": -1,
            "filename": "plover_python_dictionary-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6e6dbe69d1af83bb7892bf51a6a3be4c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5197,
            "upload_time": "2025-07-09T17:47:44",
            "upload_time_iso_8601": "2025-07-09T17:47:44.930339Z",
            "url": "https://files.pythonhosted.org/packages/f6/21/94dd2493f1a2b0fdd506a1981cf76745ab82ac27d46ef91da1ee16f5a4fb/plover_python_dictionary-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-09 17:47:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "benoit-pierre",
    "github_project": "plover_python_dictionary",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "plover-python-dictionary"
}
        
Elapsed time: 1.20460s