Skip to main content

LatinCy Preprocess

Latin text preprocessing: U/V normalization, long-s OCR correction, diacritics stripping, macron removal, and Beta Code → Unicode Greek conversion — with optional Rust acceleration and spaCy integration.

Consolidates latincy-uv and latincy-long-s into a single package.

Installation

pip install latincy-preprocess

For spaCy pipeline components:

pip install latincy-preprocess[spacy]

Quick Start

from latincy_preprocess import normalize

normalize("Gallia eft omnis diuisa in partes tres")
# 'Gallia est omnis divisa in partes tres'

Per-Normalizer Usage

U/V Normalization

Converts u-only Latin spelling to proper u/v distinction using rule-based analysis:

from latincy_preprocess import normalize_uv

normalize_uv("Arma uirumque cano")
# 'Arma virumque cano'

Rules handle digraphs (qu), trigraphs (ngu), morphological exceptions (cui, fuit), positional context (initial, intervocalic, post-consonant), and case preservation.

Long-S OCR Correction

Corrects OCR errors where historical long-s (ſ) was misread as f, using n-gram frequency analysis from Latin treebank data:

from latincy_preprocess import LongSNormalizer

normalizer = LongSNormalizer()

word, rules = normalizer.normalize_word_full("ftatua")
# ('statua', [TransformationRule(...)])

text = normalizer.normalize_text_full("funt in fundamento reipublicae ftatua")
# 'sunt in fundamento reipublicae statua'

Two-pass strategy: Pass 1 applies high-confidence rules (impossible bigrams like ft, fp, fc). Pass 2 uses 4-gram frequency disambiguation for ambiguous word-initial f- patterns.

Diacritics and Macrons

from latincy_preprocess import strip_diacritics, strip_macrons

strip_macrons("ārma")
# 'arma'

strip_diacritics("λόγος")
# 'λογος'

Beta Code → Unicode Greek

Latin prose corpora often encode embedded Greek quotations as TLG/Perseus-style Beta Code. Convert it to polytonic Unicode (NFC):

from latincy_preprocess import beta_to_unicode

beta_to_unicode("zei/dwros a)/roura")
# 'ζείδωρος ἄρουρα'

Note: this transliterates every ASCII letter to Greek, so apply it only to isolated Beta Code spans, not mixed Latin/Greek text. Use is_betacode() to guard or segment input:

from latincy_preprocess import beta_to_unicode, is_betacode

span = "a)/nqrwpos"
clean = beta_to_unicode(span) if is_betacode(span) else span
# 'ἄνθρωπος'  —  Latin spans are left untouched

is_betacode() is a heuristic (Beta Code written with no diacritics is indistinguishable from Latin), but it reliably catches accented Greek and ignores ordinary Latin punctuation.

spaCy Integration

Three pipeline components are available as spaCy factories:

Unified Preprocessor (recommended)

Chains long-s correction → U/V normalization in the correct order:

import spacy

nlp = spacy.blank("la")
nlp.add_pipe("latin_preprocessor")

doc = nlp("Gallia eft omnis diuisa in partes tres")
doc._.preprocessed          # 'Gallia est omnis divisa in partes tres'
doc[2]._.preprocessed       # 'est'
doc[2]._.preprocessed_lemma # normalized lemma

Either normalizer can be disabled:

nlp.add_pipe("latin_preprocessor", config={"uv": False})
nlp.add_pipe("latin_preprocessor", config={"long_s": False})

Standalone Components

nlp.add_pipe("uv_normalizer")
# doc._.uv_normalized, token._.uv_normalized, token._.uv_normalized_lemma

nlp.add_pipe("long_s_normalizer")
# doc._.long_s_normalized, token._.long_s_normalized

Rust Backend

When compiled with maturin, a Rust backend provides ~3x throughput for both normalizers. The backend is selected automatically:

from latincy_preprocess import backend

backend()  # 'rust' or 'python'

The Python backend is fully functional and used as the fallback.

Accuracy

U/V Normalization

Dataset Accuracy
Curated test set (100 sentences) 100%
UD Latin PROIEL (~21K u/v chars) ~98%
UD Latin Perseus (~18K u/v chars) ~97%

Long-S Correction

Pass 1 rules have a 0.00% false positive rate. Pass 2 disambiguation uses a protected allowlist of ~170 common Latin f- words (inline in long_s/_rules.py) plus n-gram frequency tables (JSON files in long_s/data/ngrams/).

Changelog

See CHANGELOG.md for release history.

Citation

@software{latincy_preprocess,
  title = {latincy-preprocess: Text Preprocessing for LatinCy Projects},
  author = {Burns, Patrick J.},
  year = {2026},
  url = {https://github.com/latincy/latincy-preprocess}
}

Acknowledgments

The betacode submodule adapts the Beta Code → Unicode conversion tables and algorithm from the Classical Language Toolkit (cltk.alphabet.grc.beta_to_unicode), used under the MIT License (Copyright © 2013 Classical Language Toolkit). It is reimplemented here on the Python standard library so the package remains dependency-free.

License

MIT

Download files

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

Source Distribution

latincy_preprocess-0.3.3.tar.gz (165.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

latincy_preprocess-0.3.3-cp310-abi3-win_amd64.whl (358.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

latincy_preprocess-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (492.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

latincy_preprocess-0.3.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

latincy_preprocess-0.3.3-cp310-abi3-macosx_11_0_arm64.whl (452.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

latincy_preprocess-0.3.3-cp310-abi3-macosx_10_12_x86_64.whl (457.7 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file latincy_preprocess-0.3.3.tar.gz.

File metadata

  • Download URL: latincy_preprocess-0.3.3.tar.gz
  • Upload date:
  • Size: 165.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for latincy_preprocess-0.3.3.tar.gz
Algorithm Hash digest
SHA256 9c47c8dfd89d62db6e383733b60f64dc63cd4d9690f53ee5e8fd26a6c377068e
MD5 c4598fa5160acf5139293dd2ae476b49
BLAKE2b-256 b7d0638ac5e137b8e7d8ca3202edfbdaad50138d491a9729b15d25641c259de5

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.3.3.tar.gz:

Publisher: release.yml on latincy/latincy-preprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file latincy_preprocess-0.3.3-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.3.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4f1027aa389766288672538297e79fd6f373c34781143c5989b6b5e4e2a63407
MD5 6a363b53be7a83b512b5970f80e79b9b
BLAKE2b-256 0ac889bd972723def6945e52f6b37172657d64cf108cea51295f7f038daac133

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.3.3-cp310-abi3-win_amd64.whl:

Publisher: release.yml on latincy/latincy-preprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file latincy_preprocess-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 66568facdfd12e498068fbe61f416c227dcf2ee28dafa8bb958c81fa4be9c7af
MD5 52a8d00fd5f7caa06ba16f3343a7a040
BLAKE2b-256 23ae28e6f427416798e5527029ea8c7b56bb54284b69324d026f4d76da2d170a

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on latincy/latincy-preprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file latincy_preprocess-0.3.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.3.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 163d655b6d4d1c275260b09eefa669a5913e308dc8c8d953923448e66a405c7e
MD5 ce35f49110b2b4a5e41133e4b676b612
BLAKE2b-256 c2c9eba2016c5789d2d311149825aa448005fd7dce14aac9daaa417c2abff2d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.3.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on latincy/latincy-preprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file latincy_preprocess-0.3.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.3.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c59de1e01a50738e973d5fa8cc48d5c35437373f241a648d2f9204ed143c5df7
MD5 7f6e95ecd612fa7e101d6db3905b9139
BLAKE2b-256 7f9cd6698a49b0bcfc8682bc9fdc35f5d0fd1639e272240a6d90c86ae353c244

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.3.3-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on latincy/latincy-preprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file latincy_preprocess-0.3.3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.3.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f90b5589f2d36aa074231be1f0304e386709909904e310fe69828c4267e34931
MD5 c80761b764d580e7201aa25661405fa7
BLAKE2b-256 43b3acb30a5aa5319bd09fdfcd04ca5da2cf99b5f8ed6e859184da8c947ce0e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.3.3-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on latincy/latincy-preprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.5.1

6 files

0.5.0

6 files

0.4.0

6 files

This release

0.3.3 This release

6 files

0.3.2

15 files

0.3.1

15 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page