Skip to main content

xpfcorpus

Documentation Status

A Python package for grapheme-to-phoneme transcription based on the XPF Corpus.

Documentation: xpfcorpus.readthedocs.io

XPF Corpus Resources:

Installation

pip install xpfcorpus

Python API

from xpfcorpus import Transcriber, available_languages

# Basic usage - languages with a default script
es = Transcriber("es")
es.transcribe("ejemplo")  # ['e', 'x', 'e', 'm', 'p', 'l', 'o']

# Languages with multiple scripts require explicit script choice
tt_latin = Transcriber("tt", "latin")
tt_cyrillic = Transcriber("tt", "cyrillic")

# BCP-47 style language codes with script/region
es_es = Transcriber("es-ES")  # Region code stripped, uses default script
yi = Transcriber("yi-Latn")   # Script extracted from code
tt = Transcriber("tt-cyrillic")  # Script name in code
zh = Transcriber("zh-Hans-CN")  # Script extracted, region stripped

# Explicit script parameter overrides code
yi = Transcriber("yi-Latn", script="hebrew")  # Uses hebrew, not latin

# Skip verification on load
es = Transcriber("es", verify=False)

# List available languages
available_languages()
# {"es": {"scripts": ["latin"], "default": "latin"},
#  "tt": {"scripts": ["latin", "cyrillic"], "default": None}, ...}

Language Code Format

The package supports BCP-47 style language codes:

  • Simple codes: "es", "tt", "yi"
  • With region (variants): "es-ES", "en-US" → treated as language variants
  • With script (extracted): "yi-Latn", "tt-Cyrl" → extracts script
  • Script names (extracted): "tt-cyrillic", "yi-latin" → extracts script
  • Complex codes: "zh-Hans-CN" → extracts "hans" script, preserves "CN" region

When both a script in the code and an explicit script parameter are provided, the explicit parameter takes precedence.

Language Variants

Region codes are treated as language variants. The package will:

  1. Try to load variant-specific data (e.g., es-ES.json) if available
  2. Fall back to base language (e.g., es.json) with a warning if variant not found
  3. Store the variant information in the variant property (only if variant file exists)
# Base language
es = Transcriber("es")
print(es.variant)  # None

# Variant request (falls back to base with warning if es-ES.json doesn't exist)
es_es = Transcriber("es-ES")
print(es_es.variant)  # None (because es-ES.json doesn't exist, fell back to es.json)

# If es-ES.json existed, then:
# es_es.variant would be "ES"

Behavior:

  • If variant file exists: variant property returns the region code (e.g., "ES")
  • If variant file doesn't exist: falls back to base language, variant is None

To create a variant, add a JSON file like es-ES.json to the xpfcorpus/data/languages/ directory with variant-specific rules.

Command-Line Interface

# Transcribe words
xpfcorpus transcribe es ejemplo hola mundo

# Transcribe from file (extracts first word from each line)
xpfcorpus transcribe es -f words.txt

# Transcribe from stdin
echo -e "mundo\nbueno" | xpfcorpus transcribe es
cat words.txt | xpfcorpus transcribe es -f -

# Combine command-line words and file
xpfcorpus transcribe es ejemplo hola -f more_words.txt

# List available languages
xpfcorpus list
xpfcorpus list --json

# Export language rules as YAML
xpfcorpus export es
xpfcorpus export es -o spanish.yaml

# Verify language rules
xpfcorpus verify es -v
xpfcorpus verify --all

Supported Languages

The package includes rules for 201 languages with 203 language/script combinations. Some languages have multiple scripts:

  • iu (Inuktitut): latin, syllabics
  • tt (Tatar): latin, cyrillic

Use xpfcorpus list or available_languages() for the full list.

Citation

If you use this package in your research, please cite the XPF Corpus:

@Manual{XPF2021manual,
  author={Cohen Priva, Uriel and Strand, Emily and Yang, Shiying and Mizgerd, William and Creighton, Abigail and Bai, Justin and Mathew, Rebecca and Shao, Allison and Schuster, Jordan and Wiepert, Daniela},
  title = 	 {The Cross-linguistic Phonological Frequencies (XPF) Corpus manual},
  year = 	 {2021},
  note =         {Accessible online, \url{https://cohenpr-xpf.github.io/XPF/manual/xpf_manual.pdf}}
}

License

MIT

Metadata

Release files for xpfcorpus 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xpfcorpus 0.1.1
File Size Uploaded Provenance
xpfcorpus-0.1.1.tar.gz 308.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for xpfcorpus 0.1.1
File Interpreter ABI Platform
xpfcorpus-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 726.8 kB

Release files / xpfcorpus-0.1.1.tar.gz

Download URL xpfcorpus-0.1.1.tar.gz
Size 308.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f7204963adc3afa92f4cb7b7861e445e8b03656861cf3999a11de5d7d496bfa8
BLAKE2b-256 checksum
How to use checksums
db810ccd0666933a17a1d459fa73e45a8d6274232576368331dbadb549f3b795
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / xpfcorpus-0.1.1-py3-none-any.whl

Download URL xpfcorpus-0.1.1-py3-none-any.whl
Size 418.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0fbe401e2e9c9a64568b5477b0104e54edb1971a78d8557f77826dbf5555dfa
BLAKE2b-256 checksum
How to use checksums
7048471c7655c2d814a5d59fd681eb3c80580bd662c9719ecc5bd668f3fd6937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for xpfcorpus 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page