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_dev3-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03239d19fbf680f79e3e81f39976bb89d70dd10bbc33e645d7eb39a058594552 |
|
MD5 | 6537dec5f72ab4762309740e317fc046 |
|
BLAKE2b-256 | 4ec0b5b71a3db04c5d5f004fa5af0d958e17d5ffd08dc3c4e42d4a363f8009a7 |
Hashes for rtfcre-2.0.0_dev3-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a83de2d8bb2eedefbed32d164b90e183b9a90df9f242735e0b6475ad42ed3011 |
|
MD5 | dadf81605dea2eaf0a8a0a35b413723e |
|
BLAKE2b-256 | 1620ca73e1440e753766f6ce7e6d31d744b40ba416542a76077be32c56d62a93 |
Hashes for rtfcre-2.0.0_dev3-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a25e652cbabc46c20fd2e57a40018fe2c6f3460d7da99f9fac37c04c5231ba60 |
|
MD5 | db9cde2869a94749f9d82cc58ef31409 |
|
BLAKE2b-256 | 98346d550f073bb94cc51d0b4bd4e49ca891cc116c754530737a97d8eba06453 |
Hashes for rtfcre-2.0.0_dev3-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cf7837bfdbffeab02865a431b40ab8e77f52bc0430be4a7d01012d77e453275 |
|
MD5 | d8174da69df92bc1818314b7cc288623 |
|
BLAKE2b-256 | 356d8fd36c93fdd5892ebc158d818a867b17a92dad4d431916bb606183855950 |
Hashes for rtfcre-2.0.0_dev3-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca2c8076dd0cd57691ca5ab38bfaee09f31c4427a3411e866d3808d840b3d63c |
|
MD5 | 77538889d7211d5de928aa784689543c |
|
BLAKE2b-256 | ffe7161578c79f298d0e8bb6fa0524ef3a4b0e7f3772cb70ebe85fd38ad51639 |
Hashes for rtfcre-2.0.0_dev3-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dd776e4f86f4dc7a053a1c3549f897068eea294cfe29e7501cd3a7a4f78787b |
|
MD5 | 8dda3700bb2a9ed30af38f4564262d0a |
|
BLAKE2b-256 | 7c39528db9b04a2b53afd61010de6e92d461a215bfbd495c96b17d9e1d10e55e |
Hashes for rtfcre-2.0.0_dev3-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f91c8b257798c2918a39ea635f0e7935c0c45ace508302b155c8f5d838e0bba8 |
|
MD5 | 4037f5efcf72a60a7a7f4d07fc8b4de2 |
|
BLAKE2b-256 | a4db35cafc87203c82a84e1660c878751dce95481833d74004e1a741a8d218bf |
Hashes for rtfcre-2.0.0_dev3-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18752772a07ac8233b1d93903a5804477e4cbbf1f32ed6e26d59764cc90a736 |
|
MD5 | edcd7490b788a0474695fb9874207d10 |
|
BLAKE2b-256 | 2baef27f2c28096e7aea02312decce7bde1ce237b6053c4ca65ee2b9caeb87eb |
Hashes for rtfcre-2.0.0_dev3-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37f2d14273d3a23ae1deadb40a07266321e70adb7b89eb8e7f66b1743d490059 |
|
MD5 | 0f4501f4802a07541e380278daaad717 |
|
BLAKE2b-256 | fd59f2281af94abd4c14203592d8fef049d864caafe381046d15ded461281e1c |
Hashes for rtfcre-2.0.0_dev3-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5b2a62e6e5a03477a0e2466d314442e34a383fcfc69051c6c166283f0803062 |
|
MD5 | 26fc29a71c7ca73ae17dda2ba7f56ff5 |
|
BLAKE2b-256 | c3939c289557010d3ea862c2ccc6e4dc7f00355f877cda29b8a7e5928e124672 |
Hashes for rtfcre-2.0.0_dev3-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63a59df7490242cff538449a8c05fd8bf246820c6374ffc056d64d419ae8e61f |
|
MD5 | ddad794cd43b4e16c3106fdf47e26dc2 |
|
BLAKE2b-256 | fa8bf63a521ded1d59d6733a55a415ea94ddc746935f5f25d60dd1699ff8a32c |
Hashes for rtfcre-2.0.0_dev3-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4643b50e6a63aa15aa40fc2f6ce63058fffb114e21366835b6c35ffdeafe0e4c |
|
MD5 | 235cb66dfc375c6e620208784bcd363f |
|
BLAKE2b-256 | 760c431d031826d39674ae28c12ab0902dec073579b05aecd43c573f4efcdc2f |