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.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8070a9a9d016e4d318d3c31db30b09619d6f4548a98094c00a60f7ffc555f23 |
|
MD5 | 743316c10a7f9699f8d5493bc1b051bf |
|
BLAKE2b-256 | 0fe4b2e79264b29f0dc028d4949bd7435a4dc5b33253221d43dd055d055d06b1 |
Hashes for rtfcre-2.0.1-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cc1984a643182808ea9d336eeee45e47f06ce04a08c12e54a50373a5a7d3587 |
|
MD5 | ab724d0032fac106ee5257dcf87e1491 |
|
BLAKE2b-256 | 0b5b08bddd8c33ca2dae829c42b2af6dc7cdac3a6ec365ee8ba9e7cf1609b17f |
Hashes for rtfcre-2.0.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca0b3a1e43ac8e556565b15aaa034a2d8bd7826dfc4261be39cd0b48830a2e64 |
|
MD5 | e857e3b29d161f89bfab715a0a82249f |
|
BLAKE2b-256 | 21bfaaa6154b18f8361dfae81b8338e8233673d23e447d41dbbff4289524a6ad |
Hashes for rtfcre-2.0.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b48bac7c69ed2de40d3919df268fc8a5d2cb95d6bb4a7564f258930d0b0529e5 |
|
MD5 | 05a254bd9732130e702a93d842f321e2 |
|
BLAKE2b-256 | b5c77dcdaea412cf0996fe07b8b6bca71179a536347e509f386d94bff86aacc7 |
Hashes for rtfcre-2.0.1-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fd2014458f9513d07b6ed50f0d7b1205b84833499117436020a49268fc42a17 |
|
MD5 | 6aa3fd315e788105c3dd9ccaac952553 |
|
BLAKE2b-256 | da5dc1967849d2aee4ed3ae7bbe000eb4fa02ce1496f9fec7c64689e48f1fe81 |
Hashes for rtfcre-2.0.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dc5ecafeb96fc5e179f907c10cd8a2769726a860dae57ac18b74ee79c1a57e4 |
|
MD5 | d453c89b6afb9b98e2361a3c23ee3555 |
|
BLAKE2b-256 | 39ee351c8bd5319664e18cae2b93a3bdef6adb314f9730e57a05cf3b73beca79 |
Hashes for rtfcre-2.0.1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 076eb7d5f528ba52161df64b73929a9f09d3a759bb3d8be4b36e629b915989c5 |
|
MD5 | 28ff098d0ce4bb5376d2e404538f62b0 |
|
BLAKE2b-256 | dcb47a3b843b56324d4e48472482dd7fbf79c799975213e8193ed184768daca6 |
Hashes for rtfcre-2.0.1-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87e6bcbe1d9b13b8b2dad297c2c00de769f909ce8a80f0712355792b09347d8c |
|
MD5 | e89041eb1c811540a6045c17c58e449c |
|
BLAKE2b-256 | 9b41fbcaee49428b072ab9419201e36936d73f408fb78fba969e964682bccde8 |
Hashes for rtfcre-2.0.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe2a790c9c4cd3e0bc10514a583660c33d78ed277161362b2a9a5438f09bcb44 |
|
MD5 | a114a302e30e223c8f44e2f3852d0232 |
|
BLAKE2b-256 | 526570d1a43acd5e6c8595421e2239d2c90a04dc824947ce3779bba1a1d7649e |
Hashes for rtfcre-2.0.1-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79bf050f3ed7adba53143b9eabe2e8ef205e6e47b819de261845fde6c8c0501f |
|
MD5 | 9231a97fa15bb2a9e559109e7d687fcb |
|
BLAKE2b-256 | 52a0a23a23db12553ce68b6b099d96652f065249b082c4a155b8fb6c6951880e |
Hashes for rtfcre-2.0.1-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c07d71aa82b8a9a2f041ba7e97986bd9d60aab61f6c7e1d2d9dcf96ab38edb4 |
|
MD5 | 89689bf551de93ea5ede3ddc8c5d2738 |
|
BLAKE2b-256 | 375a49f5e8198d56347bc8df31d99f506301fd68be76e2f2c8b0384b1694f3b3 |
Hashes for rtfcre-2.0.1-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e56a9a8935af0c96cb3fc648bebec392a38c077358c17618f469b8ef25650a18 |
|
MD5 | 67c9e3ac9edb07f432ce8b22c052b5f8 |
|
BLAKE2b-256 | e10b95e814654f0399a84aa267bbee871024fe06723c876953e70f814526882d |