tugalex 2.2.2a2__tar.gz → 2.2.2a3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/PKG-INFO +57 -17
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/README.md +56 -16
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/__init__.py +36 -8
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/version.py +1 -1
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex.egg-info/PKG-INFO +57 -17
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/LICENSE +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/pyproject.toml +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/setup.cfg +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tests/test_given_names.py +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tests/test_ipa_velar_stop.py +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tests/test_lexicon.py +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tests/test_noun_gender.py +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tests/test_stress_marks.py +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/data/acordo_ortografico_pt_BR.csv +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/data/acordo_ortografico_pt_PT.csv +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/data/archaisms.csv +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/data/given_names.csv.gz +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/data/heterophonic_homographs.csv +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/data/noun_gender_exceptions.csv.gz +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex/data/regional_dict.csv.gz +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex.egg-info/SOURCES.txt +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex.egg-info/dependency_links.txt +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex.egg-info/requires.txt +0 -0
- {tugalex-2.2.2a2 → tugalex-2.2.2a3}/tugalex.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tugalex
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.2a3
|
|
4
4
|
Summary: A lexicon handler and linguistic utility for Portuguese dialects
|
|
5
5
|
Author-email: JarbasAi <jarbasai@mailfence.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -40,11 +40,14 @@ TugaLex maps standard ISO codes to internal regional datasets:
|
|
|
40
40
|
| `pt-MZ` | `mpx` | Mozambique (Maputo) |
|
|
41
41
|
| `pt-TL` | `dli` | Timor-Leste (Díli) |
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
`spx` has no ISO alias. Pass it as `region="spx"`.
|
|
44
|
+
|
|
45
|
+
The regional dictionary ships as a slim gzip extract (word, phones,
|
|
46
|
+
syllables, region) of the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon),
|
|
47
|
+
with 53,147 to 53,148 words in each region. Regenerate it with
|
|
48
|
+
`python scripts/build_regional_dict.py`. The regional dictionary has no
|
|
49
|
+
part of speech: each word has one pronunciation per region, and it answers
|
|
50
|
+
every POS query. Only the heterophonic homograph table is keyed by POS.
|
|
48
51
|
|
|
49
52
|
---
|
|
50
53
|
|
|
@@ -52,7 +55,7 @@ entry that answers every POS query.
|
|
|
52
55
|
|
|
53
56
|
### 1. Phonemes & Syllables
|
|
54
57
|
|
|
55
|
-
Retrieve IPA transcriptions and syllable breaks
|
|
58
|
+
Retrieve IPA transcriptions and syllable breaks for a word in a region. For the 27 heterophonic homographs, the part of speech (POS) selects the pronunciation.
|
|
56
59
|
|
|
57
60
|
```python
|
|
58
61
|
from tugalex import TugaLexicon
|
|
@@ -79,16 +82,19 @@ Convert text between pre-agreement and post-agreement (AO1990) spelling for Port
|
|
|
79
82
|
* **Reverse:** Modern spelling to old regional spelling (PT or BR).
|
|
80
83
|
|
|
81
84
|
```python
|
|
82
|
-
|
|
85
|
+
lex.normalize_ao1900("acção óptimo") # 'ação ótimo'
|
|
86
|
+
lex.reverse_ao1900_pt("ótimo") # 'óptimo'
|
|
83
87
|
```
|
|
84
88
|
|
|
89
|
+
The conversion splits on whitespace and matches each word exactly, so a word with attached punctuation or a capital letter is not converted ([#46](https://github.com/TigreGotico/tugalex/issues/46)).
|
|
90
|
+
|
|
85
91
|
### 3. Linguistic Insights
|
|
86
92
|
|
|
87
93
|
TugaLex identifies specific linguistic phenomena programmatically:
|
|
88
94
|
|
|
89
|
-
* **Homographs:** Words that change pronunciation
|
|
95
|
+
* **Homographs:** Words that change pronunciation with POS (e.g., *acordo* the noun `ɐˈkoɾdu` vs *acordo* the verb `ɐˈkɔɾdu`). Two readings with the same POS, such as *sede* thirst vs headquarters, need [bifonia](https://github.com/TigreGotico/bifonia).
|
|
90
96
|
* **Archaic Words:** Mapping 19th-century etymological spellings to modern ones.
|
|
91
|
-
* **Silent Letters:** Identifying words with silent 'p'
|
|
97
|
+
* **Silent Letters:** Identifying words with a silent 'p' in the `mpc`/`mpç`/`mpt` clusters of pre-1990 spelling. Silent 'c' detection does not exist ([#2](https://github.com/TigreGotico/tugalex/issues/2)).
|
|
92
98
|
* **Voiced 'u':** Detecting words where 'u' is pronounced in 'gue/gui/que/qui' clusters (formerly marked with a trema `ü`).
|
|
93
99
|
|
|
94
100
|
### 4. Noun Gender
|
|
@@ -119,10 +125,10 @@ TugaLexicon.get_given_name_gender("Raio") # None
|
|
|
119
125
|
|
|
120
126
|
## Datasets
|
|
121
127
|
|
|
122
|
-
TugaLex ships the following datasets
|
|
128
|
+
TugaLex ships the following datasets under `tugalex/data/`.
|
|
123
129
|
|
|
124
|
-
*
|
|
125
|
-
*
|
|
130
|
+
* `regional_dict.csv.gz`: phoneme and syllable mappings, 318,884 rows for 53,150 distinct words in six regions. `scripts/build_regional_dict.py` builds it from the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon) and keeps six of its [Portal da Língua Portuguesa](http://www.portaldalinguaportuguesa.org) regions. The scraped Portal data with all ten regional variants is the [`portuguese_phonetic_lexicon`](https://huggingface.co/datasets/TigreGotico/portuguese_phonetic_lexicon) dataset.
|
|
131
|
+
* `heterophonic_homographs.csv`: 27 words pronounced differently depending on POS, 55 rows.
|
|
126
132
|
* [`acordo_ortografico_pt_PT.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-PT): Portugal old orthographic spellings.
|
|
127
133
|
* [`acordo_ortografico_pt_BR.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-BR): Brazil old orthographic spellings.
|
|
128
134
|
* [`archaisms.csv`](https://huggingface.co/datasets/TigreGotico/archaisms_pt): normalized words from before the 20th century.
|
|
@@ -143,10 +149,10 @@ mislead, each with its evidence.
|
|
|
143
149
|
## Install
|
|
144
150
|
|
|
145
151
|
```bash
|
|
146
|
-
pip install
|
|
152
|
+
pip install --pre tugalex
|
|
147
153
|
```
|
|
148
154
|
|
|
149
|
-
TugaLex has no third-party runtime dependencies. All datasets ship inside the package under `tugalex/data/`.
|
|
155
|
+
TugaLex publishes alpha releases from the `dev` branch. Use `--pre` to get the API that this README describes. TugaLex has no third-party runtime dependencies. All datasets ship inside the package under `tugalex/data/`.
|
|
150
156
|
|
|
151
157
|
---
|
|
152
158
|
|
|
@@ -154,13 +160,47 @@ TugaLex has no third-party runtime dependencies. All datasets ship inside the pa
|
|
|
154
160
|
|
|
155
161
|
TugaLex is one piece of the TigreGotico Portuguese NLP stack:
|
|
156
162
|
|
|
157
|
-
* [tugaphone](https://github.com/TigreGotico/tugaphone): phonemizes arbitrary Portuguese text across dialects, using TugaLex plus a rule-based fallback.
|
|
163
|
+
* [tugaphone](https://github.com/TigreGotico/tugaphone): phonemizes arbitrary Portuguese text across dialects, using TugaLex plus a rule-based fallback. tugaphone depends on TugaLex.
|
|
164
|
+
* [bifonia](https://github.com/TigreGotico/bifonia): picks the reading of a heterophonic homograph by meaning, including the same-POS pairs that the TugaLex homograph table cannot separate.
|
|
158
165
|
* [tugamorph](https://github.com/TigreGotico/tugamorph): rule-based morphological analyzer for Portuguese.
|
|
159
|
-
* [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese.
|
|
166
|
+
* [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese. Its `lexicon` extra installs TugaLex.
|
|
160
167
|
* [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform.
|
|
161
168
|
|
|
162
169
|
---
|
|
163
170
|
|
|
171
|
+
## Documentation
|
|
172
|
+
|
|
173
|
+
Read the pages in this order. Each page links to the next one.
|
|
174
|
+
|
|
175
|
+
1. [`docs/quickstart.md`](docs/quickstart.md): install, the first lookups, dialects and AO1990.
|
|
176
|
+
2. [`docs/api.md`](docs/api.md): every public method and property.
|
|
177
|
+
3. [`docs/advanced.md`](docs/advanced.md): recipes and gotchas.
|
|
178
|
+
|
|
179
|
+
Runnable scripts for each feature are in [`examples/`](examples).
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Development
|
|
184
|
+
|
|
185
|
+
| path | contents |
|
|
186
|
+
| --- | --- |
|
|
187
|
+
| `tugalex/__init__.py` | the `TugaLexicon` class and the noun-gender suffix rules |
|
|
188
|
+
| `tugalex/data/` | the packaged datasets |
|
|
189
|
+
| `scripts/` | the build scripts for `regional_dict.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
|
|
190
|
+
| `tests/` | the pytest suite |
|
|
191
|
+
| `examples/` | one runnable script per feature |
|
|
192
|
+
| `*.ipynb` | analysis notebooks for the phonetic lexicon and the AO1990 tables |
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
uv venv --python 3.12 .venv
|
|
196
|
+
uv pip install --python .venv/bin/python --prerelease=allow -e ".[test]"
|
|
197
|
+
.venv/bin/python -m pytest tests
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
CI runs the same suite on Python 3.11 to 3.14 (`.github/workflows/build-tests.yml`). The build scripts download their sources, so run them only to regenerate a dataset. Each row of `scripts/given_name_overrides.csv` carries its evidence in the `reason` column.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
164
204
|
## License
|
|
165
205
|
|
|
166
206
|
TugaLex is released under the [Apache License 2.0](LICENSE).
|
|
@@ -19,11 +19,14 @@ TugaLex maps standard ISO codes to internal regional datasets:
|
|
|
19
19
|
| `pt-MZ` | `mpx` | Mozambique (Maputo) |
|
|
20
20
|
| `pt-TL` | `dli` | Timor-Leste (Díli) |
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
`spx` has no ISO alias. Pass it as `region="spx"`.
|
|
23
|
+
|
|
24
|
+
The regional dictionary ships as a slim gzip extract (word, phones,
|
|
25
|
+
syllables, region) of the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon),
|
|
26
|
+
with 53,147 to 53,148 words in each region. Regenerate it with
|
|
27
|
+
`python scripts/build_regional_dict.py`. The regional dictionary has no
|
|
28
|
+
part of speech: each word has one pronunciation per region, and it answers
|
|
29
|
+
every POS query. Only the heterophonic homograph table is keyed by POS.
|
|
27
30
|
|
|
28
31
|
---
|
|
29
32
|
|
|
@@ -31,7 +34,7 @@ entry that answers every POS query.
|
|
|
31
34
|
|
|
32
35
|
### 1. Phonemes & Syllables
|
|
33
36
|
|
|
34
|
-
Retrieve IPA transcriptions and syllable breaks
|
|
37
|
+
Retrieve IPA transcriptions and syllable breaks for a word in a region. For the 27 heterophonic homographs, the part of speech (POS) selects the pronunciation.
|
|
35
38
|
|
|
36
39
|
```python
|
|
37
40
|
from tugalex import TugaLexicon
|
|
@@ -58,16 +61,19 @@ Convert text between pre-agreement and post-agreement (AO1990) spelling for Port
|
|
|
58
61
|
* **Reverse:** Modern spelling to old regional spelling (PT or BR).
|
|
59
62
|
|
|
60
63
|
```python
|
|
61
|
-
|
|
64
|
+
lex.normalize_ao1900("acção óptimo") # 'ação ótimo'
|
|
65
|
+
lex.reverse_ao1900_pt("ótimo") # 'óptimo'
|
|
62
66
|
```
|
|
63
67
|
|
|
68
|
+
The conversion splits on whitespace and matches each word exactly, so a word with attached punctuation or a capital letter is not converted ([#46](https://github.com/TigreGotico/tugalex/issues/46)).
|
|
69
|
+
|
|
64
70
|
### 3. Linguistic Insights
|
|
65
71
|
|
|
66
72
|
TugaLex identifies specific linguistic phenomena programmatically:
|
|
67
73
|
|
|
68
|
-
* **Homographs:** Words that change pronunciation
|
|
74
|
+
* **Homographs:** Words that change pronunciation with POS (e.g., *acordo* the noun `ɐˈkoɾdu` vs *acordo* the verb `ɐˈkɔɾdu`). Two readings with the same POS, such as *sede* thirst vs headquarters, need [bifonia](https://github.com/TigreGotico/bifonia).
|
|
69
75
|
* **Archaic Words:** Mapping 19th-century etymological spellings to modern ones.
|
|
70
|
-
* **Silent Letters:** Identifying words with silent 'p'
|
|
76
|
+
* **Silent Letters:** Identifying words with a silent 'p' in the `mpc`/`mpç`/`mpt` clusters of pre-1990 spelling. Silent 'c' detection does not exist ([#2](https://github.com/TigreGotico/tugalex/issues/2)).
|
|
71
77
|
* **Voiced 'u':** Detecting words where 'u' is pronounced in 'gue/gui/que/qui' clusters (formerly marked with a trema `ü`).
|
|
72
78
|
|
|
73
79
|
### 4. Noun Gender
|
|
@@ -98,10 +104,10 @@ TugaLexicon.get_given_name_gender("Raio") # None
|
|
|
98
104
|
|
|
99
105
|
## Datasets
|
|
100
106
|
|
|
101
|
-
TugaLex ships the following datasets
|
|
107
|
+
TugaLex ships the following datasets under `tugalex/data/`.
|
|
102
108
|
|
|
103
|
-
*
|
|
104
|
-
*
|
|
109
|
+
* `regional_dict.csv.gz`: phoneme and syllable mappings, 318,884 rows for 53,150 distinct words in six regions. `scripts/build_regional_dict.py` builds it from the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon) and keeps six of its [Portal da Língua Portuguesa](http://www.portaldalinguaportuguesa.org) regions. The scraped Portal data with all ten regional variants is the [`portuguese_phonetic_lexicon`](https://huggingface.co/datasets/TigreGotico/portuguese_phonetic_lexicon) dataset.
|
|
110
|
+
* `heterophonic_homographs.csv`: 27 words pronounced differently depending on POS, 55 rows.
|
|
105
111
|
* [`acordo_ortografico_pt_PT.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-PT): Portugal old orthographic spellings.
|
|
106
112
|
* [`acordo_ortografico_pt_BR.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-BR): Brazil old orthographic spellings.
|
|
107
113
|
* [`archaisms.csv`](https://huggingface.co/datasets/TigreGotico/archaisms_pt): normalized words from before the 20th century.
|
|
@@ -122,10 +128,10 @@ mislead, each with its evidence.
|
|
|
122
128
|
## Install
|
|
123
129
|
|
|
124
130
|
```bash
|
|
125
|
-
pip install
|
|
131
|
+
pip install --pre tugalex
|
|
126
132
|
```
|
|
127
133
|
|
|
128
|
-
TugaLex has no third-party runtime dependencies. All datasets ship inside the package under `tugalex/data/`.
|
|
134
|
+
TugaLex publishes alpha releases from the `dev` branch. Use `--pre` to get the API that this README describes. TugaLex has no third-party runtime dependencies. All datasets ship inside the package under `tugalex/data/`.
|
|
129
135
|
|
|
130
136
|
---
|
|
131
137
|
|
|
@@ -133,13 +139,47 @@ TugaLex has no third-party runtime dependencies. All datasets ship inside the pa
|
|
|
133
139
|
|
|
134
140
|
TugaLex is one piece of the TigreGotico Portuguese NLP stack:
|
|
135
141
|
|
|
136
|
-
* [tugaphone](https://github.com/TigreGotico/tugaphone): phonemizes arbitrary Portuguese text across dialects, using TugaLex plus a rule-based fallback.
|
|
142
|
+
* [tugaphone](https://github.com/TigreGotico/tugaphone): phonemizes arbitrary Portuguese text across dialects, using TugaLex plus a rule-based fallback. tugaphone depends on TugaLex.
|
|
143
|
+
* [bifonia](https://github.com/TigreGotico/bifonia): picks the reading of a heterophonic homograph by meaning, including the same-POS pairs that the TugaLex homograph table cannot separate.
|
|
137
144
|
* [tugamorph](https://github.com/TigreGotico/tugamorph): rule-based morphological analyzer for Portuguese.
|
|
138
|
-
* [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese.
|
|
145
|
+
* [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese. Its `lexicon` extra installs TugaLex.
|
|
139
146
|
* [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform.
|
|
140
147
|
|
|
141
148
|
---
|
|
142
149
|
|
|
150
|
+
## Documentation
|
|
151
|
+
|
|
152
|
+
Read the pages in this order. Each page links to the next one.
|
|
153
|
+
|
|
154
|
+
1. [`docs/quickstart.md`](docs/quickstart.md): install, the first lookups, dialects and AO1990.
|
|
155
|
+
2. [`docs/api.md`](docs/api.md): every public method and property.
|
|
156
|
+
3. [`docs/advanced.md`](docs/advanced.md): recipes and gotchas.
|
|
157
|
+
|
|
158
|
+
Runnable scripts for each feature are in [`examples/`](examples).
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Development
|
|
163
|
+
|
|
164
|
+
| path | contents |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| `tugalex/__init__.py` | the `TugaLexicon` class and the noun-gender suffix rules |
|
|
167
|
+
| `tugalex/data/` | the packaged datasets |
|
|
168
|
+
| `scripts/` | the build scripts for `regional_dict.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
|
|
169
|
+
| `tests/` | the pytest suite |
|
|
170
|
+
| `examples/` | one runnable script per feature |
|
|
171
|
+
| `*.ipynb` | analysis notebooks for the phonetic lexicon and the AO1990 tables |
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
uv venv --python 3.12 .venv
|
|
175
|
+
uv pip install --python .venv/bin/python --prerelease=allow -e ".[test]"
|
|
176
|
+
.venv/bin/python -m pytest tests
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
CI runs the same suite on Python 3.11 to 3.14 (`.github/workflows/build-tests.yml`). The build scripts download their sources, so run them only to regenerate a dataset. Each row of `scripts/given_name_overrides.csv` carries its evidence in the `reason` column.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
143
183
|
## License
|
|
144
184
|
|
|
145
185
|
TugaLex is released under the [Apache License 2.0](LICENSE).
|
|
@@ -289,11 +289,16 @@ class TugaLexicon:
|
|
|
289
289
|
|
|
290
290
|
Parameters:
|
|
291
291
|
word: The word to look up; matching is case-insensitive because entries are normalized to lowercase.
|
|
292
|
-
pos:
|
|
292
|
+
pos: Uppercase part-of-speech tag (default: "NOUN"). It selects the
|
|
293
|
+
entry of a heterophonic homograph, whose pronunciation is
|
|
294
|
+
region-independent. The regional dictionary is POS-free, so for
|
|
295
|
+
every other word (and for a tag the homograph has no entry for)
|
|
296
|
+
the POS does not change the answer.
|
|
293
297
|
region: Region code identifying the dialect dataset (e.g., "lbx").
|
|
294
298
|
|
|
295
299
|
Returns:
|
|
296
|
-
The phoneme string
|
|
300
|
+
The phoneme string, or None if no entry exists. An archaic spelling
|
|
301
|
+
is rewritten to its modern form before the lookup.
|
|
297
302
|
|
|
298
303
|
Raises:
|
|
299
304
|
ValueError: If the region is not in the loaded dataset.
|
|
@@ -349,7 +354,7 @@ class TugaLexicon:
|
|
|
349
354
|
|
|
350
355
|
Returns:
|
|
351
356
|
dict: A mapping with keys:
|
|
352
|
-
- "syllables": list of syllable segments for the word in the region, or
|
|
357
|
+
- "syllables": list of syllable segments for the word in the region, or an empty list if not found.
|
|
353
358
|
- "phonemes": phoneme transcription for the given POS and region, or `None` if not found.
|
|
354
359
|
"""
|
|
355
360
|
return {
|
|
@@ -379,12 +384,19 @@ class TugaLexicon:
|
|
|
379
384
|
"""
|
|
380
385
|
Get a flat dictionary mapping words to phonemes for a specific POS and region.
|
|
381
386
|
|
|
387
|
+
Every word of the regional dictionary appears with its POS-free
|
|
388
|
+
pronunciation. *pos* only selects which homograph-table entries
|
|
389
|
+
replace those pronunciations.
|
|
390
|
+
|
|
382
391
|
Args:
|
|
383
|
-
pos (str):
|
|
392
|
+
pos (str): Uppercase part-of-speech tag for the homograph entries.
|
|
384
393
|
region (str): Region code.
|
|
385
394
|
|
|
386
395
|
Returns:
|
|
387
396
|
Dict[str, str]: Map of {word: phonemes}.
|
|
397
|
+
|
|
398
|
+
Raises:
|
|
399
|
+
ValueError: If the region is not in the loaded dataset.
|
|
388
400
|
"""
|
|
389
401
|
if region not in self.ipa:
|
|
390
402
|
raise ValueError(f"Unsupported dialect: {region}")
|
|
@@ -409,6 +421,9 @@ class TugaLexicon:
|
|
|
409
421
|
|
|
410
422
|
Returns:
|
|
411
423
|
Dict[str, List[str]]: Map of word -> list of available POS tags.
|
|
424
|
+
A heterophonic homograph lists its homograph-table tags. Every
|
|
425
|
+
other word of the ``lbx`` dictionary lists ``[""]``, the key
|
|
426
|
+
of its POS-free entry.
|
|
412
427
|
"""
|
|
413
428
|
homo = self.homographs
|
|
414
429
|
return {
|
|
@@ -489,11 +504,12 @@ class TugaLexicon:
|
|
|
489
504
|
@cached_property
|
|
490
505
|
def voiced_u_words(self) -> Set[str]:
|
|
491
506
|
"""
|
|
492
|
-
Set of words
|
|
493
|
-
|
|
507
|
+
Set of words with a voiced 'u' in 'gue'/'gui'/'que'/'qui': the modern
|
|
508
|
+
spellings of the words whose pre-AO1990 Brazilian spelling has the
|
|
509
|
+
trema 'ü', based on the Brazilian AO dictionary.
|
|
494
510
|
|
|
495
511
|
Returns:
|
|
496
|
-
Set[str]:
|
|
512
|
+
Set[str]: Modern spellings of words with voiced 'u'.
|
|
497
513
|
"""
|
|
498
514
|
# all words in acordo_ortografico_pt_BR.csv containing trema 'ü'
|
|
499
515
|
return set([new_word
|
|
@@ -505,6 +521,10 @@ class TugaLexicon:
|
|
|
505
521
|
"""
|
|
506
522
|
Normalize a sentence to AO1990 standards.
|
|
507
523
|
|
|
524
|
+
The sentence is split on whitespace and each word is looked up exactly
|
|
525
|
+
as written, so a word with attached punctuation or a capital letter is
|
|
526
|
+
not converted. The words are joined with single spaces.
|
|
527
|
+
|
|
508
528
|
Args:
|
|
509
529
|
sentence (str): Input sentence with potentially old spelling.
|
|
510
530
|
|
|
@@ -518,6 +538,10 @@ class TugaLexicon:
|
|
|
518
538
|
"""
|
|
519
539
|
Revert a sentence from AO1990 to pre-agreement PT-PT spelling.
|
|
520
540
|
|
|
541
|
+
The sentence is split on whitespace and each word is looked up exactly
|
|
542
|
+
as written, so a word with attached punctuation or a capital letter is
|
|
543
|
+
not converted. The words are joined with single spaces.
|
|
544
|
+
|
|
521
545
|
Args:
|
|
522
546
|
sentence (str): Input sentence in modern spelling.
|
|
523
547
|
|
|
@@ -536,6 +560,10 @@ class TugaLexicon:
|
|
|
536
560
|
"""
|
|
537
561
|
Revert a sentence from AO1990 to pre-agreement PT-BR spelling.
|
|
538
562
|
|
|
563
|
+
The sentence is split on whitespace and each word is looked up exactly
|
|
564
|
+
as written, so a word with attached punctuation or a capital letter is
|
|
565
|
+
not converted. The words are joined with single spaces.
|
|
566
|
+
|
|
539
567
|
Args:
|
|
540
568
|
sentence (str): Input sentence in modern spelling.
|
|
541
569
|
|
|
@@ -557,7 +585,7 @@ if __name__ == "__main__":
|
|
|
557
585
|
print(f"Regions available: {ph.regions}")
|
|
558
586
|
print(f"Silent P words count: {len(ph.silent_p_words)}")
|
|
559
587
|
print(f"Voiced U words count: {len(ph.voiced_u_words)}")
|
|
560
|
-
# Regions available: {'
|
|
588
|
+
# Regions available: {'dli', 'lbx', 'lda', 'mpx', 'rjx', 'spx'}
|
|
561
589
|
# Silent P words count: 15
|
|
562
590
|
# Voiced U words count: 324
|
|
563
591
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tugalex
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.2a3
|
|
4
4
|
Summary: A lexicon handler and linguistic utility for Portuguese dialects
|
|
5
5
|
Author-email: JarbasAi <jarbasai@mailfence.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -40,11 +40,14 @@ TugaLex maps standard ISO codes to internal regional datasets:
|
|
|
40
40
|
| `pt-MZ` | `mpx` | Mozambique (Maputo) |
|
|
41
41
|
| `pt-TL` | `dli` | Timor-Leste (Díli) |
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
`spx` has no ISO alias. Pass it as `region="spx"`.
|
|
44
|
+
|
|
45
|
+
The regional dictionary ships as a slim gzip extract (word, phones,
|
|
46
|
+
syllables, region) of the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon),
|
|
47
|
+
with 53,147 to 53,148 words in each region. Regenerate it with
|
|
48
|
+
`python scripts/build_regional_dict.py`. The regional dictionary has no
|
|
49
|
+
part of speech: each word has one pronunciation per region, and it answers
|
|
50
|
+
every POS query. Only the heterophonic homograph table is keyed by POS.
|
|
48
51
|
|
|
49
52
|
---
|
|
50
53
|
|
|
@@ -52,7 +55,7 @@ entry that answers every POS query.
|
|
|
52
55
|
|
|
53
56
|
### 1. Phonemes & Syllables
|
|
54
57
|
|
|
55
|
-
Retrieve IPA transcriptions and syllable breaks
|
|
58
|
+
Retrieve IPA transcriptions and syllable breaks for a word in a region. For the 27 heterophonic homographs, the part of speech (POS) selects the pronunciation.
|
|
56
59
|
|
|
57
60
|
```python
|
|
58
61
|
from tugalex import TugaLexicon
|
|
@@ -79,16 +82,19 @@ Convert text between pre-agreement and post-agreement (AO1990) spelling for Port
|
|
|
79
82
|
* **Reverse:** Modern spelling to old regional spelling (PT or BR).
|
|
80
83
|
|
|
81
84
|
```python
|
|
82
|
-
|
|
85
|
+
lex.normalize_ao1900("acção óptimo") # 'ação ótimo'
|
|
86
|
+
lex.reverse_ao1900_pt("ótimo") # 'óptimo'
|
|
83
87
|
```
|
|
84
88
|
|
|
89
|
+
The conversion splits on whitespace and matches each word exactly, so a word with attached punctuation or a capital letter is not converted ([#46](https://github.com/TigreGotico/tugalex/issues/46)).
|
|
90
|
+
|
|
85
91
|
### 3. Linguistic Insights
|
|
86
92
|
|
|
87
93
|
TugaLex identifies specific linguistic phenomena programmatically:
|
|
88
94
|
|
|
89
|
-
* **Homographs:** Words that change pronunciation
|
|
95
|
+
* **Homographs:** Words that change pronunciation with POS (e.g., *acordo* the noun `ɐˈkoɾdu` vs *acordo* the verb `ɐˈkɔɾdu`). Two readings with the same POS, such as *sede* thirst vs headquarters, need [bifonia](https://github.com/TigreGotico/bifonia).
|
|
90
96
|
* **Archaic Words:** Mapping 19th-century etymological spellings to modern ones.
|
|
91
|
-
* **Silent Letters:** Identifying words with silent 'p'
|
|
97
|
+
* **Silent Letters:** Identifying words with a silent 'p' in the `mpc`/`mpç`/`mpt` clusters of pre-1990 spelling. Silent 'c' detection does not exist ([#2](https://github.com/TigreGotico/tugalex/issues/2)).
|
|
92
98
|
* **Voiced 'u':** Detecting words where 'u' is pronounced in 'gue/gui/que/qui' clusters (formerly marked with a trema `ü`).
|
|
93
99
|
|
|
94
100
|
### 4. Noun Gender
|
|
@@ -119,10 +125,10 @@ TugaLexicon.get_given_name_gender("Raio") # None
|
|
|
119
125
|
|
|
120
126
|
## Datasets
|
|
121
127
|
|
|
122
|
-
TugaLex ships the following datasets
|
|
128
|
+
TugaLex ships the following datasets under `tugalex/data/`.
|
|
123
129
|
|
|
124
|
-
*
|
|
125
|
-
*
|
|
130
|
+
* `regional_dict.csv.gz`: phoneme and syllable mappings, 318,884 rows for 53,150 distinct words in six regions. `scripts/build_regional_dict.py` builds it from the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon) and keeps six of its [Portal da Língua Portuguesa](http://www.portaldalinguaportuguesa.org) regions. The scraped Portal data with all ten regional variants is the [`portuguese_phonetic_lexicon`](https://huggingface.co/datasets/TigreGotico/portuguese_phonetic_lexicon) dataset.
|
|
131
|
+
* `heterophonic_homographs.csv`: 27 words pronounced differently depending on POS, 55 rows.
|
|
126
132
|
* [`acordo_ortografico_pt_PT.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-PT): Portugal old orthographic spellings.
|
|
127
133
|
* [`acordo_ortografico_pt_BR.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-BR): Brazil old orthographic spellings.
|
|
128
134
|
* [`archaisms.csv`](https://huggingface.co/datasets/TigreGotico/archaisms_pt): normalized words from before the 20th century.
|
|
@@ -143,10 +149,10 @@ mislead, each with its evidence.
|
|
|
143
149
|
## Install
|
|
144
150
|
|
|
145
151
|
```bash
|
|
146
|
-
pip install
|
|
152
|
+
pip install --pre tugalex
|
|
147
153
|
```
|
|
148
154
|
|
|
149
|
-
TugaLex has no third-party runtime dependencies. All datasets ship inside the package under `tugalex/data/`.
|
|
155
|
+
TugaLex publishes alpha releases from the `dev` branch. Use `--pre` to get the API that this README describes. TugaLex has no third-party runtime dependencies. All datasets ship inside the package under `tugalex/data/`.
|
|
150
156
|
|
|
151
157
|
---
|
|
152
158
|
|
|
@@ -154,13 +160,47 @@ TugaLex has no third-party runtime dependencies. All datasets ship inside the pa
|
|
|
154
160
|
|
|
155
161
|
TugaLex is one piece of the TigreGotico Portuguese NLP stack:
|
|
156
162
|
|
|
157
|
-
* [tugaphone](https://github.com/TigreGotico/tugaphone): phonemizes arbitrary Portuguese text across dialects, using TugaLex plus a rule-based fallback.
|
|
163
|
+
* [tugaphone](https://github.com/TigreGotico/tugaphone): phonemizes arbitrary Portuguese text across dialects, using TugaLex plus a rule-based fallback. tugaphone depends on TugaLex.
|
|
164
|
+
* [bifonia](https://github.com/TigreGotico/bifonia): picks the reading of a heterophonic homograph by meaning, including the same-POS pairs that the TugaLex homograph table cannot separate.
|
|
158
165
|
* [tugamorph](https://github.com/TigreGotico/tugamorph): rule-based morphological analyzer for Portuguese.
|
|
159
|
-
* [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese.
|
|
166
|
+
* [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese. Its `lexicon` extra installs TugaLex.
|
|
160
167
|
* [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform.
|
|
161
168
|
|
|
162
169
|
---
|
|
163
170
|
|
|
171
|
+
## Documentation
|
|
172
|
+
|
|
173
|
+
Read the pages in this order. Each page links to the next one.
|
|
174
|
+
|
|
175
|
+
1. [`docs/quickstart.md`](docs/quickstart.md): install, the first lookups, dialects and AO1990.
|
|
176
|
+
2. [`docs/api.md`](docs/api.md): every public method and property.
|
|
177
|
+
3. [`docs/advanced.md`](docs/advanced.md): recipes and gotchas.
|
|
178
|
+
|
|
179
|
+
Runnable scripts for each feature are in [`examples/`](examples).
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Development
|
|
184
|
+
|
|
185
|
+
| path | contents |
|
|
186
|
+
| --- | --- |
|
|
187
|
+
| `tugalex/__init__.py` | the `TugaLexicon` class and the noun-gender suffix rules |
|
|
188
|
+
| `tugalex/data/` | the packaged datasets |
|
|
189
|
+
| `scripts/` | the build scripts for `regional_dict.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
|
|
190
|
+
| `tests/` | the pytest suite |
|
|
191
|
+
| `examples/` | one runnable script per feature |
|
|
192
|
+
| `*.ipynb` | analysis notebooks for the phonetic lexicon and the AO1990 tables |
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
uv venv --python 3.12 .venv
|
|
196
|
+
uv pip install --python .venv/bin/python --prerelease=allow -e ".[test]"
|
|
197
|
+
.venv/bin/python -m pytest tests
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
CI runs the same suite on Python 3.11 to 3.14 (`.github/workflows/build-tests.yml`). The build scripts download their sources, so run them only to regenerate a dataset. Each row of `scripts/given_name_overrides.csv` carries its evidence in the `reason` column.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
164
204
|
## License
|
|
165
205
|
|
|
166
206
|
TugaLex is released under the [Apache License 2.0](LICENSE).
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|