Python library for Rich Text Format with Court Reporting Extensions (RTF/CRE) dictionaries
Project description
rtfcre
rtfcre
is a Python library for reading and writing steno dictionaries in the
RTF/CRE
(Rich Text Format with Court Reporting Extensions) format. The library provides
an API similar to that of the json
module for reading and writing dictionaries.
rtfcre
also comes with a little command-line utility that you can use to
convert your dictionaries between Plover's native JSON format and RTF. See
CLI for more information.
Features
-
Speed: The parsing logic is written in Rust using parser combinators, making it much faster than practically any pure-Python implementation.
-
Comments: Rather than just exposing translations,
rtfcre
also reads the comments embedded in each entry ({\*\cxcomment like this}
). -
Unicode: Full Unicode support -- while the dictionary files are not encoded in UTF-8, Unicode characters in translations are still fully supported. Translations can be in any language and they will seamlessly be converted to escapes when writing.
-
Plover support: Translations are converted automatically to Plover's native syntax (e.g. fingerspelling is represented with
{&a}
rather than{\cxfing a}
) and converted back when writing.
Installation
To install the library:
pip install rtfcre
If you just want to use this with Plover, install the plover-better-rtf plugin instead, since that plugin uses this library under the hood.
If you want the command-line utility, go to the Releases page and download the binary for your system.
Usage
Library
To read an RTF dictionary:
import rtfcre
# Reading directly from a file (make sure to open binary)
with open("dict.rtf", "rb") as file:
dic = rtfcre.load(file)
# Reading from a string
rtf = r"""
{\rtf1\ansi{\*\cxrev100}\cxdict{\*\cxsystem KittyCAT}
{\*\cxs KAT}cat
{\*\cxs KOU}cow
}
""".lstrip()
dic = rtfcre.loads(rtf)
To write the RTF dictionary:
# Writing to a file (make sure to open binary)
with open("dict.rtf", "wb") as file:
dic.dump(file)
# Writing to a string
rtf = dic.dumps()
The dictionary object itself also supports the standard dict
API:
dic["KAT"] = "cat"
"KAT" in dic # True
dic["KAT"] # "cat"
del dic["KAT"]
dic["TKOG"] # KeyError
dic["TKOG"] = "dog"
dic["TKOG"] # "dog"
as well as a reverse lookup API for mapping from translations to steno strokes:
dic.reverse_lookup("cat") # ["KAT"]
To access comments:
dic.lookup("TKOG") # ("dog", None)
dic.add_comment("TKOG", "TK means D")
dic.lookup("TKOG") # ("dog", "TK means D")
dic.remove_comment("TKOG")
CLI
To convert an existing Plover JSON dictionary to RTF:
rtfcre path/to/input.json path/to/output.rtf
To convert an existing RTF dictionary back to Plover JSON:
rtfcre path/to/input.rtf path/to/output.json
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for rtfcre-2.0.0_dev1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 927cdc36841b2c49bf87fa227b5a836cebbea13b7fc47bbbeea1c137685ac0cb |
|
MD5 | 4c0489f3dbe3d3669cd4da455a71d060 |
|
BLAKE2b-256 | 2c7dcc72c2d43c4cfe10e8f2307f22b8b55bb5b35e9cc955955d6f03bd31bb4f |
Hashes for rtfcre-2.0.0_dev1-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa9d2b8eee1affbec16b6e3782e8b53686c7069939eda84421acdd8a3466f19f |
|
MD5 | 8f58306522bc87edb15c6bfe2fe5a808 |
|
BLAKE2b-256 | 01b760a63a7a4dcd45b2b3bb2ed9534717ff6911ed477a3bb794815e6a1f14b9 |
Hashes for rtfcre-2.0.0_dev1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dd3560104791009f2eb5909c9edebd97110c1e8ba10b3dcf7333313f9dff1fa |
|
MD5 | c06f88f9ca2112e261becebd34b4214f |
|
BLAKE2b-256 | 3f5cf25ff044fdd662c6478f955be0135514e4f1e412b7db12a1444465d7c214 |
Hashes for rtfcre-2.0.0_dev1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93724df1b525373695036c53f7150c7921b0a21d8d399d3e7d74699ee47429a3 |
|
MD5 | 7057c9b9f963cf2ee086b5ba4b918347 |
|
BLAKE2b-256 | 7b3c446c032e13ae7d113d9b0acc02e43e4e5fb387109e2eb873a9c936ba6cb6 |
Hashes for rtfcre-2.0.0_dev1-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f906d1c0c6134249364216a504efc96cf767af57c8f960665324d6f2895876ae |
|
MD5 | 82b5492cb9ebbb6bbe86a41cd099c07d |
|
BLAKE2b-256 | bbf7f6bf4d581aaee8a3389e4e917f43293827149e75ab465f61c0f7492543f9 |
Hashes for rtfcre-2.0.0_dev1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4768c2282315d2c6c332bda8909d1249db87af2ece273a320e6ea1178c4da39f |
|
MD5 | aca3520ba0083ac0cfc0ef657da17037 |
|
BLAKE2b-256 | 5d391cc207f409e994997b064397ec9a1f272c7c14741dfdec0b38a2fefc9be9 |
Hashes for rtfcre-2.0.0_dev1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c16d4109ee2a69e561a736503a3556ebf7fee93f0cecfddab48c3e37bcc5c257 |
|
MD5 | e44eacb624a25d38eb69f9e10e18ad1a |
|
BLAKE2b-256 | 61d59a020c2682ae28cccc00d834d500379f66766e1eb75a550d726d6efc9acf |
Hashes for rtfcre-2.0.0_dev1-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23e556f81e09b443c487bdca934700340ef913258bfe9fcaf75439f8a838019b |
|
MD5 | c5c18ee944f94a28143b589ed066aa2b |
|
BLAKE2b-256 | 2f39cc46ccb64da2bd176db4b9a21a3eeaede3bc56665a6489f42189b5978a8b |
Hashes for rtfcre-2.0.0_dev1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cab28a349945aed0437f3e76d076e2103083c6f2b89a5f11b99efde8287ccc83 |
|
MD5 | 305beec7d7b762ad42c78bc0573243fb |
|
BLAKE2b-256 | c0b50bf6b0dd707a98aeeccbabc39a8b4098c9b76f4e037346c140eddef623d8 |
Hashes for rtfcre-2.0.0_dev1-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dee7e8e294b8371c0fb8661648bbd862b7cc310b9cf7c647b9d618c073cd1fbc |
|
MD5 | b15584ffa2adfd540b897ce6ac7977dd |
|
BLAKE2b-256 | 7c8dcacb341b72c50b48485d967f00853bf30a524e83ed095e4159f1907c031a |
Hashes for rtfcre-2.0.0_dev1-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a832beb81aebebc46dfdd450abe1a1d2ddc4f41a6c7b01d1c62e07ac708d7f7f |
|
MD5 | 2c3e149e31ac2cf578443acd535fff33 |
|
BLAKE2b-256 | 28b9cce6182d0ce0c0a9750b22fab7e26a0c6a52efe6c26254b8e530eb12c84a |
Hashes for rtfcre-2.0.0_dev1-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9fcd1f88afe9aae27d7dcd48ed58e2131125c8d20f4e24f6d72d8f1a5477890 |
|
MD5 | aa3d87a0ac90f70681863ae00dbade13 |
|
BLAKE2b-256 | b838ce9d6642e809576535cfae5ff7f4b16363744300cc0b610efc6c1d256fba |