Latin text preprocessing: U/V normalization, long-s OCR correction, diacritics stripping, macron removal, and Beta Code → Unicode Greek conversion — plus Ancient Greek elision/accent normalization — 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]"
For Ancient Greek normalization:
pip install "latincy-preprocess[grc]"
For both:
pip install "latincy-preprocess[spacy,grc]"
(The quotes matter in zsh — the default shell on macOS — which otherwise
treats the brackets as a glob pattern and fails with no matches found.)
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.
Ancient Greek Normalization
Requires the grc extra (pip install latincy-preprocess[grc]), which pulls in greek-normalisation.
Canonicalizes Ancient Greek for consistent tokenization and dictionary lookup — collapsing the many treebank/corpus encodings of the elision apostrophe to a single codepoint (U+2019), stripping lexicographic macron/breve marks, and folding grave → acute for lemma matching:
from latincy_preprocess.grc import (
normalize_surface,
normalize_norm,
normalize_lookup_key,
is_greek_word,
)
# Surface form: NFC + canonical elision apostrophe (U+2019)
normalize_surface("μυρίʼ") # 'μυρί’' (Tesserae U+02BC → U+2019)
normalize_surface("ἀλλ'") # 'ἀλλ’' (ASCII apostrophe → U+2019)
# NORM: restore closed-class elision, grave → acute, movable nu/sigma
normalize_norm("δʼ") # 'δέ'
normalize_norm("ἀλλ’") # 'ἀλλά'
# Lookup key: grave → acute + final-sigma folding for dictionary matching
normalize_lookup_key("φονὸς") # 'φονός'
normalize_lookup_key("λογοσ") # 'λογος'
# Guard: Greek letters + the canonical elision mark only
is_greek_word("μυρί’") # True
is_greek_word("anthropos") # False
Consolidates the previously independent normalization implementations across the LatinCy Greek pipelines into a single source of truth for the elision/accent standard.
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.
The grc submodule is built on James Tauber's greek-normalisation.
License
MIT
Metadata
Release files for latincy-preprocess 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| latincy_preprocess-0.5.1.tar.gz | 174.1 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| latincy_preprocess-0.5.1-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| latincy_preprocess-0.5.1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| latincy_preprocess-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 2.5 MB
Release files / latincy_preprocess-0.5.1.tar.gz
| Download URL | latincy_preprocess-0.5.1.tar.gz |
|---|---|
| Size | 174.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d17be0cc629bfa1f2b361e9dea3a7eeb9e0a12d87498d76fd9ab2fc2b87bd7c6
|
|
BLAKE2b-256 checksum How to use checksums |
c13ef2dbf33a06292d33b38805f919bc7a1443573693babfbbe0456cf831f8a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / latincy_preprocess-0.5.1-cp310-abi3-win_amd64.whl
| Download URL | latincy_preprocess-0.5.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 367.7 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
21b3732044cf9ba9ac425da24cff412fba47483c01d0472eb3a67fdfe7834914
|
|
BLAKE2b-256 checksum How to use checksums |
32b077ed2f9fafa24d960039dda86233cf2cb3d9028115b6c29b72a4798500a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 501.6 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4e6cd6c5dc5a44dcf3e7897900f1284e263fec6f30aabbb1750068e1188e4703
|
|
BLAKE2b-256 checksum How to use checksums |
e21aae7f295ebc7b3093d6188413efa1e5d92b77987b32c6b33c62de76232ddc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 492.4 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d5baf55141ad40e23a746141f187a34d2b14acf0aab884ce712b2e234bfe7eec
|
|
BLAKE2b-256 checksum How to use checksums |
a0ea6b55a49eb6026d9786faffb799e3792dff223ec398d264117a687b4e36bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / latincy_preprocess-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | latincy_preprocess-0.5.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 461.7 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6e4d8a7aa63260616b6ac0fbdcb9fd840a8c21db6924e9e15827e3a96efa99b0
|
|
BLAKE2b-256 checksum How to use checksums |
03e7efb59bba2ccd447617a04d4813049f179f9341971ec69f1ed3a6dc1172f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / latincy_preprocess-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | latincy_preprocess-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 466.7 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
7574ec6133d607f05ee64d0a8c773f94c9b9cbdbaf5798f2c99632b48877b3c9
|
|
BLAKE2b-256 checksum How to use checksums |
cfb0ae919b37cf417ac50e4d496a777a6ce6f44edff238fce9d182c7707ae21d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency log