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.
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
pip install rtfcre
Usage
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")
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.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 101d65b1f8de2f9c9048b51f498ff2f228ae49edb67dcd135a5d93b12770cb23 |
|
MD5 | 5a13f2da0ddd808ef7794c298b3969ec |
|
BLAKE2b-256 | f665568fb2ab51271efb93aec1bde72f2d99d984d5b6446478a124bbaa1feb2a |
Hashes for rtfcre-1.0.0-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd92760d10586a2cc9685d2ffc0636abe4909d89d29db4d2d56acb934b4e89bb |
|
MD5 | 78b48f15bce664d05e69fcbd94023bd9 |
|
BLAKE2b-256 | 56bc02755053008e5e55e7a285f1a1582a8c6f521f80b3edddb1b0b0fc1cd5d1 |
Hashes for rtfcre-1.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55c3f16fad30fe4f262c3d63083bb30d295a2a11194c983aa89f3dd3cc39b1b7 |
|
MD5 | cb54271419e16b56ef44db9ecdeea018 |
|
BLAKE2b-256 | b256b9cfaa8fb74142ccedac247a19fe4fc6481eddcb41aeb0465c56b7d95a57 |
Hashes for rtfcre-1.0.0-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26b7bcd63e5a9b5640036a562efab87bf4b83d3155210f64d083c780c7213eef |
|
MD5 | 5b35fab3ba5ad69f2729fab082d216fd |
|
BLAKE2b-256 | f580128fc7687d0350476bd8f36bd72ecac69e6ad8c32a1f0f0abe6da65eb37c |
Hashes for rtfcre-1.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba259f17faf67995684da4620d11124af0f809ab7042e87edac800ec0d23ca2b |
|
MD5 | bd30ef09a6b3acac17878aa029af13d3 |
|
BLAKE2b-256 | 91ab85e258712a76e92fabc6b4d2fcea39712f7fd7b5271a13bddd37bcfef010 |
Hashes for rtfcre-1.0.0-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31462484ddd1d6c5a13474ac2d8d790c556e09054af2684bd9d062031cbd3625 |
|
MD5 | 3db38fbb32d8b0ea3a254ed70859f49b |
|
BLAKE2b-256 | 98b8836ca0330f3f888c3d81a5b247611e54b0da0735b6676ec4a27576299d3b |
Hashes for rtfcre-1.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ac6909eea400542855563ebed0d6ade61a1a259fe81d01ca15d352d5ec1d57b |
|
MD5 | ae84ce9e5886769f22056618e91eaf9b |
|
BLAKE2b-256 | ae0505dcfac56abb4855d1361f1cdfb80c3ec8d705a4e3c0e8c18ab1cb1ffc98 |
Hashes for rtfcre-1.0.0-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7123823ddcc24745d8f686e5fb6d3d2fb02c059214495b95c0b1c5e6c0e4c24 |
|
MD5 | f019f54b0f241fdb2473825e1d72aebd |
|
BLAKE2b-256 | b178149061fcc4b892715d84b329aeeeb546c07a2bf1dbe9050f449a191b86ab |