Skip to main content

LatinCy Preprocess

PyPI version Python versions CI License: MIT

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

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.5.1.tar.gz (174.1 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.5.1-cp310-abi3-win_amd64.whl (367.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (501.6 kB view details)

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

latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (492.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

latincy_preprocess-0.5.1-cp310-abi3-macosx_11_0_arm64.whl (461.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

latincy_preprocess-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl (466.7 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for latincy_preprocess-0.5.1.tar.gz
Algorithm Hash digest
SHA256 d17be0cc629bfa1f2b361e9dea3a7eeb9e0a12d87498d76fd9ab2fc2b87bd7c6
MD5 10c636f80d8590b42cd2b56b5627de5e
BLAKE2b-256 c13ef2dbf33a06292d33b38805f919bc7a1443573693babfbbe0456cf831f8a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.5.1.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.5.1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.5.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 21b3732044cf9ba9ac425da24cff412fba47483c01d0472eb3a67fdfe7834914
MD5 b531ceaa5d0f5b05dda8d44a4b7bbc88
BLAKE2b-256 32b077ed2f9fafa24d960039dda86233cf2cb3d9028115b6c29b72a4798500a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.5.1-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.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4e6cd6c5dc5a44dcf3e7897900f1284e263fec6f30aabbb1750068e1188e4703
MD5 eb82b78a8564dff363300b871998a5e3
BLAKE2b-256 e21aae7f295ebc7b3093d6188413efa1e5d92b77987b32c6b33c62de76232ddc

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.5.1-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.5.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.5.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d5baf55141ad40e23a746141f187a34d2b14acf0aab884ce712b2e234bfe7eec
MD5 e67b938a642f47bc4493501b5fe8abcb
BLAKE2b-256 a0ea6b55a49eb6026d9786faffb799e3792dff223ec398d264117a687b4e36bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.5.1-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.5.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e4d8a7aa63260616b6ac0fbdcb9fd840a8c21db6924e9e15827e3a96efa99b0
MD5 7724d8d5f23083bed00ba7ff6f831c86
BLAKE2b-256 03e7efb59bba2ccd447617a04d4813049f179f9341971ec69f1ed3a6dc1172f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.5.1-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.5.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for latincy_preprocess-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7574ec6133d607f05ee64d0a8c773f94c9b9cbdbaf5798f2c99632b48877b3c9
MD5 a8941c170cd026697e0d7f679144c3d9
BLAKE2b-256 cfb0ae919b37cf417ac50e4d496a777a6ce6f44edff238fce9d182c7707ae21d

See more details on using hashes here.

Provenance

The following attestation bundles were made for latincy_preprocess-0.5.1-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

This release

0.5.1 This release

6 files

0.5.0

6 files

0.4.0

6 files

0.3.3

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