Skip to main content

Python library for Rich Text Format with Court Reporting Extensions (RTF/CRE) dictionaries

Project description

rtfcre

pypi python build

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

rtfcre-1.0.0-cp39-cp39-manylinux1_x86_64.whl (5.8 MB view hashes)

Uploaded CPython 3.9

rtfcre-1.0.0-cp39-cp39-macosx_10_7_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

rtfcre-1.0.0-cp38-cp38-manylinux1_x86_64.whl (5.8 MB view hashes)

Uploaded CPython 3.8

rtfcre-1.0.0-cp38-cp38-macosx_10_7_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

rtfcre-1.0.0-cp37-cp37m-manylinux1_x86_64.whl (5.8 MB view hashes)

Uploaded CPython 3.7m

rtfcre-1.0.0-cp37-cp37m-macosx_10_7_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

rtfcre-1.0.0-cp36-cp36m-manylinux1_x86_64.whl (5.8 MB view hashes)

Uploaded CPython 3.6m

rtfcre-1.0.0-cp36-cp36m-macosx_10_7_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.6m macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page