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-1.2.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45a4194819595a9763bd63bce3ce5ebd9a8098efb6cd71de69e6034176f4a6ca |
|
MD5 | cdc6729b031f3932ab3c37ef738298e3 |
|
BLAKE2b-256 | 353b41ee8054b6a520147f7d7ad58a5e22b42ca525f46f5c30abee806316dc26 |
Hashes for rtfcre-1.2.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 038c31f96ad4bf564c547268b11b55167a0348fdac4b717fb16428b3263a9aa7 |
|
MD5 | 0e5ac56298aca07b5022d580d91d73ab |
|
BLAKE2b-256 | e86a3eeb69541006a4ce3121aefb777ed50bd779f5643d6ebee64e7381f9cb71 |
Hashes for rtfcre-1.2.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a747b6068ddd0fd6ceb11089a973ab098f85b9ef1f201de1817773492d6a2156 |
|
MD5 | ff3a3463083b8bdba4ddcf8de54a80ea |
|
BLAKE2b-256 | d1ac9781aaceefef8397fa5c837c9d479b7bab96039b6e479015878bb5b19027 |
Hashes for rtfcre-1.2.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64b9a2fc693ba25ae390bc6a6a086f6bf00b98199345c3f032b407284cb84b71 |
|
MD5 | 60939f1c003e66a5f7c378ea62563350 |
|
BLAKE2b-256 | fa5757fbf6809f3b1c774ec5668b0bc81e5630ca59bff520100f31b090d8a717 |
Hashes for rtfcre-1.2.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fbd6a9343f38c3f7c767e3183c65da4e69c5795a41d68f01e8148995b953ad2 |
|
MD5 | 1d870ab9e5dc7cc303c6f2a1fe0749ca |
|
BLAKE2b-256 | 455d66dbd8be6d3b00fedd3b7a8ab92a12975a8fb2a43a0b635cbbb0331402f8 |
Hashes for rtfcre-1.2.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88f32eb6949bb160486ae954a4a64d5a4f03dc31d7252b67c44e9adcc6c5e706 |
|
MD5 | f4847dbfba0bda8ffeaea5e25490af3c |
|
BLAKE2b-256 | bae9fc7918294d9a756ed398a45c76c6a73dfce741d5897b09f86baf446ed08f |
Hashes for rtfcre-1.2.1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fbe83e5dc4acea28f1477b76582b8f8beb877463b442c2f980b6cc4c1fa705c |
|
MD5 | 40758d75f594ff3d9f8a9c3e920672ce |
|
BLAKE2b-256 | 6288fa1b2065b001a00a1a44b92dcbca1d373e9a8790236931f824b035bdf761 |
Hashes for rtfcre-1.2.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e46745223b2e27c7673fad095c4e282348d8e511f6bb2b7ab08e587e4c048ee |
|
MD5 | 159b6a650d42f52bbd6f2b03bd30434e |
|
BLAKE2b-256 | a73dd4f94a2e6a4dbc0791292c457645e7679ecf80380f546794cce4f381b27d |
Hashes for rtfcre-1.2.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 103e6943e3e1d21747c1e73683294ccfb6966bb6586acc1924851075a3a01940 |
|
MD5 | 958ab933b4025c4bc8251aa1eec1df74 |
|
BLAKE2b-256 | f310a9f350674650a519d264fde66032c6f35e40cad0ceecc24121119f01ec4b |
Hashes for rtfcre-1.2.1-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cdaea0fa0e2017325dd5cc8c53034dea89ec90041cc81d4a28936fed3925c5f |
|
MD5 | d1080d794f9da379a6f0748c03460bba |
|
BLAKE2b-256 | 512b824d0380b2858e12a00eeef6dc5392f50af2745168c7bc8d076a24e91368 |
Hashes for rtfcre-1.2.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03ef71ad6e51105a96bf816f48ca6f73198c6934c297ba2ee2458e239818b643 |
|
MD5 | 52a29147ac9eee337e6cd262425abe4c |
|
BLAKE2b-256 | 2c948ec2519025d5e5fab5593345413b0bf84fb00d603ab98e599ced77f6ee64 |
Hashes for rtfcre-1.2.1-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e8818a04971cb872942b0cde637a0f9264aec418b3fdab16f929664674d6111 |
|
MD5 | 01c6a0184e6ba6f1a8aed3a3c5e459eb |
|
BLAKE2b-256 | ff30780fac0fc513adbf45a4cea66e1980073083f8b03083a117bf50e73d9ae9 |