Name | plover-custom-folding JSON |
Version |
0.0.1
JSON |
| download |
home_page | None |
Summary | Define custom folding rules (e.g., prefix folds) |
upload_time | 2024-08-31 00:51:48 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | None |
keywords |
plover
plover_plugin
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Plover custom folding
Plugin that lets users use Python dictionaries to define custom folding rules.
After installing, the extension `EngineGetterExtension` must be enabled from Plover's config > `Plugins` in order for folding dictionaries to work.
## Setup
This plugin is currently not available from Plover's Plugins Manager. [Instructions are available on the Plover wiki](https://plover.wiki/index.php/Plugins#Find_the_plugin_on_PyPI_or_as_a_git_repo) on how to install this plugin from PyPI or this Git repository.
## Dictionary examples
To avoid overwriting explicitly defined entries, folding dictionaries should most likely be placed at the bottom of the dictionary list.
```py
# Example of a Python folding dictionary with some basic rules. File extension is `fold-py`.
import plover_custom_folding as f
# Required. A list of rules or lookup functions of type `Callable[[tuple[Stroke, ...], Translator], str]`.
rules: list[f.Lookup] = [
# Allows the `#` key to be included in the first stroke to capitalize a word.
# E.g., `#KAP/TAL` => `{-|}capital` ("Capital")
f.when(f.first_stroke.folds("#")).then(f.prefix_translation("{-|}")).preferring_folds(),
# Allows the `-R` key to be included in the last stroke to append "{^er}".
# E.g., `SHEURPL` => `shim {^er}` ("shimmer")
f.when(f.last_stroke.folds("-R")).then(f.suffix_translation(" {^er}")),
# Allows the substrokes `-GS` or `-GZ` to be included in the last stroke to append "{^ings}".
# E.g., `WAUFPGS` => `watchings`
f.when(f.last_stroke.folds("-GS", "-GZ")).then(f.suffix_translation(" {^ings}")),
# Allows `-G` to be included and `*` to be toggled in the last stroke to append "{^in'}".
# We can use `unfold_suffix` because `*G` is defined as "{^in'}" in main.json already.
f.when(f.last_stroke.folds("-G").toggles("*")).then(f.unfold_suffix),
]
# Optional. The maximum length of the outline to check these folding rules for.
LONGEST_KEY: int = 8
```
```py
# Dictionary with some more complex rules. This dictionary requires a system with the `^` and `+` keys.
import plover_custom_folding as f
rules: list[f.Lookup] = [
# Note: the rules are grouped in a specific order. The higher rules will take precedence over (be checked earlier
# than) lower ones, but modifications to the outline/translation occur in reverse order to the order in which each
# rule is found to be satisfied.
# Allows the `^` key to be included in every stroke to make the translation a suffix (preserving case),
# or when the first stroke also includes `+`, then also hyphenate it (preserving case).
# E.g., `^PWUFT/^*ER` => `{^~|^}buster`
f.when(f.all_strokes.fold("^")).then(f.prefix_translation("{^~|^}"))
.unless_also(
f.when(f.first_stroke.folds("+")).then(f.prefix_translation("{^~|-^}")),
),
# See above.
f.when(f.first_stroke.folds("#")).then(f.prefix_translation("{-|}")).preferring_folds(),
# Allows the `STK` substroke to be included in the first stroke and if so, we then lookup the de-folded outline
# but with the stroke `TKEUS` behind it, and then again with the stroke `TKEU` behind it and `S` added to the first
# stroke, and then just the de-folded stroke with "{dis^}" prefixed to the resulting translation.
# E.g., `STKEPL/TPHAEUT` => `disseminate`
# E.g., `STKPWHRAOEF` => `{dis^} belief` ("disbelief")
f.when(f.first_stroke.folds("STK")).then(
f.prefix_outline("TKEUS/"),
f.prefix_outline("TKEU/S"),
f.prefix_translation("{dis^} "),
),
# Plover's default suffix folding rules based on the current system. Included so they take precedence over the
# custom rules below.
f.default_system_rules(),
# See above.
f.when(f.last_stroke.folds("-R")).then(f.suffix_translation(" {^er}")),
f.when(f.last_stroke.folds("-GS", "-GZ")).then(f.suffix_translation(" {^ings}")),
f.when(f.last_stroke.folds("-G").toggles("*")).then(f.unfold_suffix),
]
```
Note that separate folding rules defined in a folding dictionary can be combined, e.g., `#^+WAUFPGS` with the above rules translates to `{-|}{^~|-^}watch {^ings}` ("-Watchings" as a suffix). The order in which the rules modify the translation depends on the order in which they are specified in the list; e.g., since the `#` rule is specified first, it applies the outermost modification to the translation.
```py
# If desired, we can manually define our own custom functions as rules.
from plover.steno import Stroke
from plover.translation import Translator
import plover_custom_folding as f
def _lookup(strokes: tuple[Stroke, ...], translator: Translator):
if "#" not in strokes[0].keys():
raise KeyError
translation = translator.lookup([strokes[0] - Stroke.from_steno("#")] + strokes[1:])
if translation is None:
raise KeyError
return f"{{-|}}{translation}"
rules: list[f.Lookup] = [
_lookup,
]
```
## Methods
TODO.
### `Rule.preferring_folds(self)`
Using built-in folding, Plover will give precedence to a shorter outline that is explicitly defined as opposed to a longer outline that is found using a fold. This plugin matches this behavior by default, but `preferring_folds` overrides this behavior, which may come in handy especially for prefix folds.
This makes certain multistroke entries more predictable:
* `SRAL/TKAEUGT` → `validate {^ing}` (original: `val dating`; conflict occurs because `TKAEUGT` → `dating` is explicitly defined in main.json)
… but others may have unexpected results:
* `SKP/HREUD` → `and I will {^ed}` (original: `and lid`; conflict occurs because of misstroke entry `SKP/HREU` → `and I will` in main.json)
Raw data
{
"_id": null,
"home_page": null,
"name": "plover-custom-folding",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "plover plover_plugin",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/c3/b4/634e1232852c414e50166fada0b164b0c4b65ed263cacc18d0b50cd81a85/plover_custom_folding-0.0.1.tar.gz",
"platform": null,
"description": "# Plover custom folding\r\nPlugin that lets users use Python dictionaries to define custom folding rules.\r\n\r\nAfter installing, the extension `EngineGetterExtension` must be enabled from Plover's config > `Plugins` in order for folding dictionaries to work.\r\n\r\n\r\n## Setup\r\nThis plugin is currently not available from Plover's Plugins Manager. [Instructions are available on the Plover wiki](https://plover.wiki/index.php/Plugins#Find_the_plugin_on_PyPI_or_as_a_git_repo) on how to install this plugin from PyPI or this Git repository.\r\n\r\n\r\n## Dictionary examples\r\nTo avoid overwriting explicitly defined entries, folding dictionaries should most likely be placed at the bottom of the dictionary list.\r\n\r\n```py\r\n# Example of a Python folding dictionary with some basic rules. File extension is `fold-py`.\r\n\r\nimport plover_custom_folding as f\r\n\r\n# Required. A list of rules or lookup functions of type `Callable[[tuple[Stroke, ...], Translator], str]`.\r\nrules: list[f.Lookup] = [\r\n # Allows the `#` key to be included in the first stroke to capitalize a word.\r\n # E.g., `#KAP/TAL` => `{-|}capital` (\"Capital\")\r\n f.when(f.first_stroke.folds(\"#\")).then(f.prefix_translation(\"{-|}\")).preferring_folds(),\r\n\r\n # Allows the `-R` key to be included in the last stroke to append \"{^er}\".\r\n # E.g., `SHEURPL` => `shim {^er}` (\"shimmer\")\r\n f.when(f.last_stroke.folds(\"-R\")).then(f.suffix_translation(\" {^er}\")),\r\n\r\n # Allows the substrokes `-GS` or `-GZ` to be included in the last stroke to append \"{^ings}\".\r\n # E.g., `WAUFPGS` => `watchings`\r\n f.when(f.last_stroke.folds(\"-GS\", \"-GZ\")).then(f.suffix_translation(\" {^ings}\")),\r\n\r\n # Allows `-G` to be included and `*` to be toggled in the last stroke to append \"{^in'}\".\r\n # We can use `unfold_suffix` because `*G` is defined as \"{^in'}\" in main.json already.\r\n f.when(f.last_stroke.folds(\"-G\").toggles(\"*\")).then(f.unfold_suffix),\r\n]\r\n\r\n# Optional. The maximum length of the outline to check these folding rules for.\r\nLONGEST_KEY: int = 8\r\n```\r\n\r\n```py\r\n# Dictionary with some more complex rules. This dictionary requires a system with the `^` and `+` keys.\r\n\r\nimport plover_custom_folding as f \r\n\r\nrules: list[f.Lookup] = [\r\n # Note: the rules are grouped in a specific order. The higher rules will take precedence over (be checked earlier\r\n # than) lower ones, but modifications to the outline/translation occur in reverse order to the order in which each\r\n # rule is found to be satisfied.\r\n\r\n\r\n # Allows the `^` key to be included in every stroke to make the translation a suffix (preserving case),\r\n # or when the first stroke also includes `+`, then also hyphenate it (preserving case).\r\n # E.g., `^PWUFT/^*ER` => `{^~|^}buster`\r\n f.when(f.all_strokes.fold(\"^\")).then(f.prefix_translation(\"{^~|^}\"))\r\n .unless_also(\r\n f.when(f.first_stroke.folds(\"+\")).then(f.prefix_translation(\"{^~|-^}\")),\r\n ),\r\n\r\n # See above.\r\n f.when(f.first_stroke.folds(\"#\")).then(f.prefix_translation(\"{-|}\")).preferring_folds(),\r\n\r\n\r\n # Allows the `STK` substroke to be included in the first stroke and if so, we then lookup the de-folded outline\r\n # but with the stroke `TKEUS` behind it, and then again with the stroke `TKEU` behind it and `S` added to the first\r\n # stroke, and then just the de-folded stroke with \"{dis^}\" prefixed to the resulting translation.\r\n # E.g., `STKEPL/TPHAEUT` => `disseminate`\r\n # E.g., `STKPWHRAOEF` => `{dis^} belief` (\"disbelief\")\r\n f.when(f.first_stroke.folds(\"STK\")).then(\r\n f.prefix_outline(\"TKEUS/\"),\r\n f.prefix_outline(\"TKEU/S\"),\r\n f.prefix_translation(\"{dis^} \"),\r\n ),\r\n\r\n\r\n # Plover's default suffix folding rules based on the current system. Included so they take precedence over the\r\n # custom rules below.\r\n f.default_system_rules(),\r\n\r\n # See above.\r\n f.when(f.last_stroke.folds(\"-R\")).then(f.suffix_translation(\" {^er}\")),\r\n f.when(f.last_stroke.folds(\"-GS\", \"-GZ\")).then(f.suffix_translation(\" {^ings}\")),\r\n f.when(f.last_stroke.folds(\"-G\").toggles(\"*\")).then(f.unfold_suffix),\r\n]\r\n```\r\n\r\nNote that separate folding rules defined in a folding dictionary can be combined, e.g., `#^+WAUFPGS` with the above rules translates to `{-|}{^~|-^}watch {^ings}` (\"-Watchings\" as a suffix). The order in which the rules modify the translation depends on the order in which they are specified in the list; e.g., since the `#` rule is specified first, it applies the outermost modification to the translation.\r\n\r\n```py\r\n# If desired, we can manually define our own custom functions as rules.\r\n\r\nfrom plover.steno import Stroke\r\nfrom plover.translation import Translator\r\n\r\nimport plover_custom_folding as f\r\n\r\ndef _lookup(strokes: tuple[Stroke, ...], translator: Translator):\r\n if \"#\" not in strokes[0].keys():\r\n raise KeyError\r\n\r\n translation = translator.lookup([strokes[0] - Stroke.from_steno(\"#\")] + strokes[1:])\r\n if translation is None:\r\n raise KeyError\r\n\r\n return f\"{{-|}}{translation}\"\r\n\r\nrules: list[f.Lookup] = [\r\n _lookup,\r\n]\r\n```\r\n\r\n\r\n## Methods\r\nTODO.\r\n\r\n### `Rule.preferring_folds(self)`\r\nUsing built-in folding, Plover will give precedence to a shorter outline that is explicitly defined as opposed to a longer outline that is found using a fold. This plugin matches this behavior by default, but `preferring_folds` overrides this behavior, which may come in handy especially for prefix folds.\r\n\r\nThis makes certain multistroke entries more predictable:\r\n* `SRAL/TKAEUGT` \u2192 `validate {^ing}` (original: `val dating`; conflict occurs because `TKAEUGT` \u2192 `dating` is explicitly defined in main.json)\r\n\r\n\u2026 but others may have unexpected results:\r\n* `SKP/HREUD` \u2192 `and I will {^ed}` (original: `and lid`; conflict occurs because of misstroke entry `SKP/HREU` \u2192 `and I will` in main.json)\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Define custom folding rules (e.g., prefix folds)",
"version": "0.0.1",
"project_urls": null,
"split_keywords": [
"plover",
"plover_plugin"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a556de7a240bf28b5011e2806472224285509be3a2c09deb61441e22d96cc566",
"md5": "7118ed05ccad0983da1535183bd54156",
"sha256": "25148e5438fb014d0c41f4ea0f630a742452749636d79f55c40d7dd1c3d507f3"
},
"downloads": -1,
"filename": "plover_custom_folding-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7118ed05ccad0983da1535183bd54156",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12393,
"upload_time": "2024-08-31T00:51:47",
"upload_time_iso_8601": "2024-08-31T00:51:47.625512Z",
"url": "https://files.pythonhosted.org/packages/a5/56/de7a240bf28b5011e2806472224285509be3a2c09deb61441e22d96cc566/plover_custom_folding-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c3b4634e1232852c414e50166fada0b164b0c4b65ed263cacc18d0b50cd81a85",
"md5": "b1d38fcc731e6a048a6bf71e49b1b692",
"sha256": "a59bb9281e990a4f1f3256a81d13007ce98667c2d9b67141f7c54c3134291e4c"
},
"downloads": -1,
"filename": "plover_custom_folding-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "b1d38fcc731e6a048a6bf71e49b1b692",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12077,
"upload_time": "2024-08-31T00:51:48",
"upload_time_iso_8601": "2024-08-31T00:51:48.849416Z",
"url": "https://files.pythonhosted.org/packages/c3/b4/634e1232852c414e50166fada0b164b0c4b65ed263cacc18d0b50cd81a85/plover_custom_folding-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-31 00:51:48",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "plover-custom-folding"
}