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_dev2-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa5a836ec64d9e1037d03e44d4dbdc2f054ca37d5bbc0579d8e612a6c6010b2c |
|
MD5 | a1ddb62a0a85475742f0e4623f748990 |
|
BLAKE2b-256 | 46cab0a8f7c08f9357d847ba70a21650ed6a9af09239f5f1b68bbe72edc5d2d4 |
Hashes for rtfcre-2.0.0_dev2-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf571926f23ed5c5712bada6bd4fd50cfae52536e2784f9a722f7ce153b9e40e |
|
MD5 | 1f78d46bf7aee1949773b7d76e031610 |
|
BLAKE2b-256 | 746c989722378013dd325a5fcc8f4fd432ea1faf8c6b423c1145cd0c7ba036bd |
Hashes for rtfcre-2.0.0_dev2-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bd6d7ac0e28c45a1e65eb33a4ecfdacb8b41cb0c0d8d7469fb2631e74e66ca0 |
|
MD5 | 0d73743d907ee78c1076338ac1c9242f |
|
BLAKE2b-256 | a07f1a1adc9d4c2ae1a35db7b0557c4b9cc35da31250edffdddffcca1bc73892 |
Hashes for rtfcre-2.0.0_dev2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa140964bcdf56f046a8497d871e6e4358bb8d42145dee5ec8d6d3037e514355 |
|
MD5 | 2c2547af19cae182b12fadbaa096e832 |
|
BLAKE2b-256 | 20227defe606d12d4e5d1805badbb7aee7a52b8638f2636b337e3972d379116f |
Hashes for rtfcre-2.0.0_dev2-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c09f8bb1fd382ce33fc5b2f41ccfdb0f88281820a99b729fed4abd8584a8b9a |
|
MD5 | 776298bf2cdf044329527b0ffd341f86 |
|
BLAKE2b-256 | e2e445c8ef5376362f500ca1a74eea1dd54a0b880fea27ded3ebeef0d0e3b4b6 |
Hashes for rtfcre-2.0.0_dev2-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d63e54b3f137b56b2e95facd99561d93c0515868d710b7d541d9822e6d7e9b9 |
|
MD5 | 10da95819ce66095e1695a14a40244bb |
|
BLAKE2b-256 | b1effec0f7dae124e8a9d7922dcfc6ab7b2462d0719b675650db7841bc3a93df |
Hashes for rtfcre-2.0.0_dev2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1d1b67e0f1466f6733fa3aeaa36a7cc5b098de1eba8a4d7514e47c561cbbd22 |
|
MD5 | 864ceb9b2a84673c2a121d015e058026 |
|
BLAKE2b-256 | 86d1d39c4f05adc58eca267563c280654af65c37775d0802fda0724045f60a11 |
Hashes for rtfcre-2.0.0_dev2-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdea49a27254bb45239ff2bb72416a60fb1d32af2ba541d86bb528d63115583d |
|
MD5 | ad9451692696debfc4aa884097346d6c |
|
BLAKE2b-256 | 4c3b1bef7f46aeb6bfb3959e8cca20d0741a2c762f16bfd47a37026166cde15b |
Hashes for rtfcre-2.0.0_dev2-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10f13313685de65a7098eca3b2d1b7f1d0e412c796b06b0b9676861b334d0ced |
|
MD5 | f46bbbb2e524c5c1cb5cc10e0fa4a36f |
|
BLAKE2b-256 | 27bf8e25aa1dbd6d0fba045e0022bdb1ca32b42a3976a6926a66399b934c8d16 |
Hashes for rtfcre-2.0.0_dev2-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eeebb2ec5e7256d612cc3ba21017abd6f33033814dd04d1e328b57cdb47a7f9 |
|
MD5 | 416caad65efe2ea45d9b5509e4713fbc |
|
BLAKE2b-256 | 01c0ed470cf849c8a2baf96df2fc196ca06870ea896183ed8b048befb5c6e964 |
Hashes for rtfcre-2.0.0_dev2-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d0013d11fb21d1eea1b1441acb588dd674cb114b34d6a7e2708f6a90a6bcf96 |
|
MD5 | 35254fc07e0f85b833ae68b3289b55fb |
|
BLAKE2b-256 | abc4cceb406aa2a1ba8ba8c27e818ab2cc280086b88ef505f1addefcf4ec6eb2 |
Hashes for rtfcre-2.0.0_dev2-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | face92faceb6f9615fd3e4e6004ef337bd171eb0fc254f4963c36983160b0019 |
|
MD5 | 24ebdc6b371e1a042d66c90f9a6defec |
|
BLAKE2b-256 | 94117627bfd3d8c8ac650049e60241d46f80bc04742357138d9c9dce921e4aac |