Metadata-Version: 2.4
Name: UNAM-G2P
Version: 0.1.0
Summary: A Python G2P tool for IPA transcription of Central Mexican Spanish.
Author: Carlos Daniel Hernández Mena
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/CarlosDanielMena/UNAM-G2P
Project-URL: Documentation, https://github.com/CarlosDanielMena/UNAM-G2P/tree/main/docs
Project-URL: Repository, https://github.com/CarlosDanielMena/UNAM-G2P.git
Project-URL: Issues, https://github.com/CarlosDanielMena/UNAM-G2P/issues
Keywords: grapheme-to-phoneme,g2p,IPA,phonetics,phonology,Spanish,Mexican Spanish,Central Mexican Spanish,speech technology,ASR,TTS
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Natural Language :: Spanish
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# UNAM-G2P

**UNAM-G2P is a Python grapheme-to-phoneme (G2P) tool for IPA transcription of Spanish spoken in Central Mexico.**

UNAM-G2P converts Spanish orthographic text into a syllabified phonological transcription in the **International Phonetic Alphabet (IPA)**. Its main interface, `unam_g2p()`, accepts complete sentences, including ordinary capitalization, punctuation, and whitespace.

The package is the current evolution of a rule-based transcription system developed over more than a decade, from an early 2013 **FONETIZADOR** program through **Fonetica2** and **Fonetica3**. The historical implementation was connected to the Mexbet computational phonetic alphabet and to Mexican Spanish speech-resource work at UNAM, but **new users do not need to know Mexbet**: IPA is the primary public-facing representation of UNAM-G2P.

> **Current release:** version `0.1.0`.

## Installation

To install from the project directory:

```bash
python3 -m pip install .
```

After the public release on PyPI, installation will be:

```bash
pip install unam-g2p
```

The distribution name is `UNAM-G2P`; the Python import package is `unam_g2p`.

## Quick start

```python
from unam_g2p import unam_g2p

text = "¡Esta es una frase en español!"
print(unam_g2p(text))
```

Output:

```text
/ e s . t a / e s / u . n a / f ɾ a . s e / e n / e s . p a . ɲ o l /
```

Slashes delimit words and periods delimit syllables.

## The letter `<x>` in Mexican Spanish

The grapheme `<x>` is an important source of orthographic ambiguity in Mexican Spanish. Depending on the word, it may correspond to different phonological values. Four particularly relevant cases are:

| Value | Approximate sound | Examples |
|---|---|---|
| /s/ | `s` | `Xochimilco`, `xilófono` |
| /ʃ/ | English `sh` | `xolos`, `xoloescuincle` |
| /ks/ | `ks` | `exacto`, `externo` |
| /x/ | Spanish `j` | `México`, `Xavier` |

This means that the spelling `<x>` alone is not always sufficient to determine the intended pronunciation. A rule-based G2P system therefore needs an explicit way to disambiguate these cases when the ordinary spelling does not uniquely identify the intended sound.

### Explicit disambiguation

UNAM-G2P provides simple input conventions for explicitly selecting the intended value:

| Intended phoneme | Input convention | Example |
|---|---|---|
| /x/ | `j` | `México` → `méjico` |
| /ʃ/ | `sh` | `xolos` → `sholos` |
| /s/ | `s` | `Xochimilco` → `sochimilco` |
| /ks/ | `x` | `exacto` → `exacto` |

For example:

```python
from unam_g2p import IPA29

print(IPA29("méjico"))
print(IPA29("sholos"))
print(IPA29("sochimilco"))
print(IPA29("exacto"))
```

Output:

```text
m é . x i . k o
ʃ o . l o s
s o . ʧ i . m i l . k o
e k . s a k . t o
```

These forms are **input conventions for phonological disambiguation**. They are not intended as alternative orthographic spellings.

For example, `méjico` is used here only to request the /x/ pronunciation corresponding to the `<x>` in `México`; similarly, `sholos` is used to request /ʃ/ in `xolos`, and `sochimilco` to request /s/ in `Xochimilco`.

The four conventions can be summarized as:

- `j` → /x/
- `sh` → /ʃ/
- `s` → /s/
- `x` → /ks/

This explicit convention is useful because UNAM-G2P is a rule-based grapheme-to-phoneme system rather than a complete lexical pronunciation dictionary. It allows the user to preserve the intended pronunciation in words whose ordinary spelling contains an ambiguous `<x>`.

`unam_g2p()` is the recommended entry point for most users. Selected word-level functions are also public for researchers and advanced workflows.

## Public API

### `unam_g2p()` — sentence-level IPA transcription

Transcribes a complete Spanish sentence into a phonological IPA representation. The function lowercases the input, treats punctuation and unsupported characters as boundaries, normalizes whitespace, and transcribes each resulting Spanish word.

```python
from unam_g2p import unam_g2p

print(unam_g2p("¡Esta es una frase en español!"))
print(unam_g2p("¿Cómo estás?"))
```

Output:

```text
/ e s . t a / e s / u . n a / f ɾ a . s e / e n / e s . p a . ɲ o l /
/ k ó . m o / e s . t á s /
```

### `IPA29()` — word-level IPA transcription

Produces the word-level IPA counterpart of the historical T29 phonological representation.

```python
from unam_g2p import IPA29

print(IPA29("palabra"))
print(IPA29("acción"))
```

Output:

```text
p a . l a . b ɾ a
a k . s i ó n
```

For ordinary sentences, prefer `unam_g2p()`.

### `T29()` — historical phonological Mexbet transcription

Produces a phonological transcription using the T29 level of **Mexbet**, an ASCII-oriented computational representation historically used by this project for pronunciation dictionaries and speech-technology resources.

```python
from unam_g2p import T29

print(T29("palabra"))
print(T29("acción"))
print(T29("excelente"))
```

Output:

```text
p a . l a . b r( a
a k . s i o_7 n
e k . s e . l e n . t e
```

Most new users should use IPA through `unam_g2p()` or `IPA29()`. T29 remains public for reproducibility and compatibility with historical research workflows.

### `T66()` — detailed historical Mexbet transcription

Produces a finer-grained phonetic transcription using the T66 representation developed for CIEMPIESS-related work.

```python
from unam_g2p import T66

print(T66("palabra"))
print(T66("acción"))
print(T66("excelente"))
```

Output:

```text
p a . l a . V r( a
a k . s j O_7 n
E k . s e . l e n_[ . t e
```

### `div_sil()` — syllabification

Divides a Spanish word into syllables; periods mark syllable boundaries.

```python
from unam_g2p import div_sil

print(div_sil("palabra"))
print(div_sil("acción"))
print(div_sil("excelente"))
print(div_sil("lingüística"))
```

Output:

```text
pa.la.bra
ac.ción
ex.ce.len.te
lin.güís.ti.ca
```

### `vocal_tonica()` — stressed-vowel detection

Returns the input word with its stressed vowel marked in uppercase according to the conventions used internally by the toolkit.

```python
from unam_g2p import vocal_tonica

print(vocal_tonica("palabra"))
print(vocal_tonica("acción"))
print(vocal_tonica("excelente"))
```

Output:

```text
palAbra
acciOn
excelEnte
```

### `acento_grafico()` — Spanish written-accent assignment

Receives a word whose stressed vowel is marked in uppercase and returns the orthographic form with a written accent when required.

```python
from unam_g2p import acento_grafico

print(acento_grafico("canciOn"))
print(acento_grafico("lingüIstica"))
print(acento_grafico("dEbil"))
```

Output:

```text
canción
lingüística
débil
```

### `num_sil()` — syllable count

```python
from unam_g2p import num_sil

print(num_sil("palabra"))
print(num_sil("acción"))
print(num_sil("excelente"))
```

Output:

```text
3
2
4
```

### `pos_tonica()` — stressed-syllable position

Returns the position of an explicitly represented stressed syllable as a negative integer counted from right to left: `-1` is final, `-2` penultimate, and so on.

```python
from unam_g2p import pos_tonica

print(pos_tonica("salomé"))
print(pos_tonica("cAsa"))
print(pos_tonica("ambulAncia"))
```

Output:

```text
-1
-2
-2
```

### `patron_sil()` — syllabic consonant/vowel pattern

```python
from unam_g2p import patron_sil

print(patron_sil("palabra"))
print(patron_sil("acción"))
print(patron_sil("excelente"))
```

Output:

```text
CV.CV.CCV
VC.CVVC
VC.CV.CVC.CV
```

## Internal implementation functions

`TT()` and `TT_INV()` are **not part of the public API**. They perform reversible text transformations required by the historical algorithms. Their intermediate symbols are implementation details, although the functions remain regression-tested because other modules depend on them.

## Linguistic basis

UNAM-G2P combines several strands of linguistic and computational work.

The phonetic and phonological lineage is connected to **Mexbet**, a computational phonetic alphabet for Mexican Spanish that evolved through work at UNAM and related projects. Javier Octavio Cuétara Priede's 2004 master's thesis substantially reviewed and reformulated the inventory for Mexico City Spanish and its speech-technology use [1]. Mexbet then served as the principal transcription reference for the **DIMEx100** corpus, which was transcribed at multiple levels of granularity [2, 3].

Beginning with the author's early implementations and later **Fonetica2**, the rules were translated into reusable Python code, reviewed, and extended. The 2014 paper *A Set of Phonetic and Phonological Rules for Mexican Spanish Revisited, Updated, Enhanced and Implemented* documents Fonetica2, the rule set, and an evaluation of its T22 transcription against DIMEx100/TRANSCRÍBEMEX [4]. CIEMPIESS subsequently used this rule-based lineage for pronunciation dictionaries and speech-recognition resources [5, 6]. The later nomenclature **T29/T66** corrected the earlier T22/T50 names so that the level names reflected the actual number of symbols represented [6].

Syllabification and stress processing have a separate linguistic source: the implementation follows the treatment of the **syllable** and **stress** in Antonio Quilis's *Tratado de fonología y fonética españolas* (Chapters 11 and 13) [7].

UNAM-G2P preserves this research lineage while making **IPA transcription** its primary interface.

## A compact project history

| Period | Stage | Significance |
|---|---|---|
| 1999–2004 | Mexbet development and revision | Earlier computational representations were progressively revised; Cuétara's 2004 thesis provided a major linguistic re-evaluation for Mexico City Spanish [1, 4]. |
| 2004–2010 | DIMEx100 | Mexbet and its associated phonetic description were used as the main reference for the multi-level transcription of DIMEx100 [2, 3]. |
| 2013 | **FONETIZADOR** | Archived source code by Carlos Daniel Hernández Mena shows an early multi-stage implementation: syllabification, stress marking, Mexbet transcription, IPA/AFI conversion, and LaTeX document generation. |
| 2014 | **Fonetica2** | The rules were exposed as a reusable open-source Python library and documented/evaluated in published work [4]. |
| 2014 onward | **CIEMPIESS** | Mexbet-based pronunciation dictionaries and automatic transcription became part of CIEMPIESS speech resources [5, 6]. |
| 2017 onward | **Fonetica3 / T29 / T66** | The library evolved, the T29/T66 naming was consolidated, and additional linguistic utilities were added [6]. |
| 2021 | `IPA29()` | Direct IPA output was added to the historical library. |
| 2026 | **UNAM-G2P** | The project was modernized as an installable Python package with sentence-level, IPA-first transcription. |

A fuller evidence-based chronology is available in [`docs/HISTORY.md`](docs/HISTORY.md). The IPA/Mexbet inventory used by the project is summarized in [`docs/PHONETIC_INVENTORY.md`](docs/PHONETIC_INVENTORY.md).

## Acknowledgments and attribution

UNAM-G2P acknowledges **Javier Octavio Cuétara Priede** for the foundational linguistic work on Mexico City Spanish and the major revision of the Mexbet framework on which the historical transcription rules are based [1]. The 2014 Fonetica2 paper also explicitly acknowledges Cuétara's advice in adapting these rules into programming code [4].

**Carlos Daniel Hernández Mena** is the author of the software implementation and of the later revisions and extensions embodied in FONETIZADOR, Fonetica2, Fonetica3, and UNAM-G2P. Published work documents the extension of the historical system and its use in CIEMPIESS and later Mexican Spanish speech-technology research [4–6].

The syllabification and accentuation components are based on the treatment described by **Antonio Quilis** [7].

## Selected references

1. Cuétara Priede, J. O. (2004). *Fonética de la Ciudad de México. Aportaciones desde las tecnologías del habla*. Master's thesis, Universidad Nacional Autónoma de México. https://repositorio.unam.mx/contenidos/79194
2. Pineda, L. A., Villaseñor, L., Cuétara, J., Castellanos, H., & López, I. (2004). *DIMEx100: A New Phonetic and Speech Corpus for Mexican Spanish*. In IBERAMIA 2004, LNCS 3315, 974–984. https://doi.org/10.1007/978-3-540-30498-2_97
3. Pineda, L. A., Castellanos, H., Cuétara, J., Galescu, L., Juárez, J., Llisterri, J., Pérez, P., & Villaseñor, L. (2010). *The Corpus DIMEx100: Transcription and Evaluation*. Language Resources and Evaluation, 44(4), 347–370. https://doi.org/10.1007/s10579-009-9109-9
4. Hernández-Mena, C. D., Martínez-Gómez, N. N., & Herrera-Camacho, J. A. (2014). *A Set of Phonetic and Phonological Rules for Mexican Spanish Revisited, Updated, Enhanced and Implemented*. Research in Computing Science, 83, 61–71.
5. Hernández Mena, C. D., & Herrera Camacho, A. (2014). *CIEMPIESS: A New Open-Sourced Mexican Spanish Radio Corpus*. Proceedings of LREC 2014, 371–375. https://aclanthology.org/L14-1189/
6. Hernández-Mena, C. D., Meza-Ruiz, I. V., & Herrera-Camacho, J. A. (2017). *Automatic speech recognizers for Mexican Spanish and its open resources*. Journal of Applied Research and Technology, 15(3), 259–270. https://doi.org/10.1016/j.jart.2017.02.001
7. Quilis, A. (1999). *Tratado de fonología y fonética españolas* (2nd ed.). Madrid: Gredos. See Chapter 11, "La sílaba", and Chapter 13, "Suprasegmentos. Acento".

A broader bibliography, including later uses of Fonetica3 and Mexbet, is maintained in [`docs/REFERENCES.md`](docs/REFERENCES.md).

## Citation

GitHub citation metadata is provided in [`CITATION.cff`](CITATION.cff). If UNAM-G2P is used in academic work, please cite the software and, when relevant, the linguistic and corpus sources listed above and in [`docs/REFERENCES.md`](docs/REFERENCES.md).

## Examples and tests

The `examples/` directory contains executable examples for every public function. The regression suite preserves historical Fonetica behavior while packaging and documentation are modernized.

Run:

```bash
python -m pytest
```

## License

UNAM-G2P is licensed under the **Apache License, Version 2.0**.

The license permits use, modification, distribution, and commercial use subject to its terms. Scientific attribution to the linguistic and published sources above is preserved independently of the software license.
