tugalex 2.4.8a2__tar.gz → 2.4.9__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.
Files changed (28) hide show
  1. {tugalex-2.4.8a2 → tugalex-2.4.9}/PKG-INFO +20 -10
  2. {tugalex-2.4.8a2 → tugalex-2.4.9}/README.md +19 -9
  3. {tugalex-2.4.8a2 → tugalex-2.4.9}/tests/test_deprecation.py +5 -3
  4. tugalex-2.4.9/tests/test_wordlist.py +114 -0
  5. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/__init__.py +35 -14
  6. tugalex-2.4.9/tugalex/data/words.csv.gz +0 -0
  7. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/version.py +2 -2
  8. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex.egg-info/PKG-INFO +20 -10
  9. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex.egg-info/SOURCES.txt +3 -1
  10. {tugalex-2.4.8a2 → tugalex-2.4.9}/LICENSE +0 -0
  11. {tugalex-2.4.8a2 → tugalex-2.4.9}/pyproject.toml +0 -0
  12. {tugalex-2.4.8a2 → tugalex-2.4.9}/setup.cfg +0 -0
  13. {tugalex-2.4.8a2 → tugalex-2.4.9}/tests/test_given_names.py +0 -0
  14. {tugalex-2.4.8a2 → tugalex-2.4.9}/tests/test_ipa_velar_stop.py +0 -0
  15. {tugalex-2.4.8a2 → tugalex-2.4.9}/tests/test_lexicon.py +0 -0
  16. {tugalex-2.4.8a2 → tugalex-2.4.9}/tests/test_noun_gender.py +0 -0
  17. {tugalex-2.4.8a2 → tugalex-2.4.9}/tests/test_regional_dict.py +0 -0
  18. {tugalex-2.4.8a2 → tugalex-2.4.9}/tests/test_stress_marks.py +0 -0
  19. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/data/acordo_ortografico_pt_BR.csv +0 -0
  20. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/data/acordo_ortografico_pt_PT.csv +0 -0
  21. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/data/archaisms.csv +0 -0
  22. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/data/given_names.csv.gz +0 -0
  23. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/data/heterophonic_homographs.csv +0 -0
  24. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/data/noun_gender_exceptions.csv.gz +0 -0
  25. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex/data/regional_dict.csv.gz +0 -0
  26. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex.egg-info/dependency_links.txt +0 -0
  27. {tugalex-2.4.8a2 → tugalex-2.4.9}/tugalex.egg-info/requires.txt +0 -0
  28. {tugalex-2.4.8a2 → tugalex-2.4.9}/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.4.8a2
3
+ Version: 2.4.9
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
@@ -26,14 +26,15 @@ Dynamic: license-file
26
26
  It gives NLP pipelines and linguistics research a single API for the differences between Portuguese regions and historical spelling agreements.
27
27
 
28
28
  > **Deprecated: the regional pronunciation dictionary.** The phoneme and
29
- > syllable API (`get`, `get_phonemes`, `get_syllables`, `get_wordlist`,
30
- > `get_ipa_map`, `lang_to_region`, `ipa`, `syllables`, `regions` and
31
- > `possible_postags`) emits a `DeprecationWarning`. The next major release
29
+ > syllable API (`get`, `get_phonemes`, `get_syllables`, `get_ipa_map`,
30
+ > `lang_to_region`, `ipa`, `syllables`, `regions` and `possible_postags`)
31
+ > emits a `DeprecationWarning`. The next major release
32
32
  > removes it, together with the legacy `tugaphone.dialects` inventories
33
33
  > that read it. For Portuguese pronunciation, use
34
34
  > [orthography2ipa](https://github.com/TigreGotico/orthography2ipa) with the
35
35
  > pt-PT lexicon of `o2i-lexicons` (`orthography2ipa.use_packaged_lexicons`).
36
- > The noun gender, given-name gender and AO1990 tools stay.
36
+ > The word list (`get_wordlist`), the noun gender, given-name gender and
37
+ > AO1990 tools stay.
37
38
 
38
39
  ---
39
40
 
@@ -54,7 +55,7 @@ TugaLex maps standard ISO codes to internal regional datasets:
54
55
 
55
56
  The regional dictionary ships as a slim gzip extract (word, phones,
56
57
  syllables, region) of the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon),
57
- with 53,142 to 53,145 words in each region. Regenerate it with
58
+ with 53,144 to 53,147 words in each region. Regenerate it with
58
59
  `python scripts/build_regional_dict.py`, which reads the lexicon revision
59
60
  pinned in the script. The regional dictionary has no
60
61
  part of speech: each word has one pronunciation per region, and it answers
@@ -99,6 +100,14 @@ lex.reverse_ao1900_pt("ótimo") # 'óptimo'
99
100
 
100
101
  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)).
101
102
 
103
+ `modern_spelling` rewrites one word to its modern spelling in one variety. It applies the archaism table and then the AO1990 table, and keeps the case of the word:
104
+
105
+ ```python
106
+ lex.modern_spelling("Pharmacia", "pt-BR") # 'Farmácia'
107
+ lex.modern_spelling("chronico", "pt-PT") # 'crónico'
108
+ lex.modern_spelling("chronico", "pt-BR") # 'crônico'
109
+ ```
110
+
102
111
  ### 3. Linguistic Insights
103
112
 
104
113
  TugaLex identifies specific linguistic phenomena programmatically:
@@ -138,7 +147,8 @@ TugaLexicon.get_given_name_gender("Raio") # None
138
147
 
139
148
  TugaLex ships the following datasets under `tugalex/data/`.
140
149
 
141
- * `regional_dict.csv.gz`: phoneme and syllable mappings, 318,860 rows for 53,146 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.
150
+ * `regional_dict.csv.gz`: phoneme and syllable mappings, 318,872 rows for 53,148 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.
151
+ * `words.csv.gz`: the word forms of `regional_dict.csv.gz` with the regions that list each one, and no pronunciations. `get_wordlist` reads it, and it stays when the regional dictionary goes. `scripts/build_wordlist.py` builds it from the regional dictionary.
142
152
  * `heterophonic_homographs.csv`: 27 words pronounced differently depending on POS, 55 rows.
143
153
  * [`acordo_ortografico_pt_PT.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-PT): Portugal old orthographic spellings.
144
154
  * [`acordo_ortografico_pt_BR.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-BR): Brazil old orthographic spellings.
@@ -175,7 +185,7 @@ TugaLex is one piece of the TigreGotico Portuguese NLP stack:
175
185
  * [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.
176
186
  * [tugamorph](https://github.com/TigreGotico/tugamorph): rule-based morphological analyzer for Portuguese.
177
187
  * [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese. Its `lexicon` extra installs TugaLex.
178
- * [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform.
188
+ * [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform. It reads the TugaLex word list, and its spelling table holds the rows of the TugaLex AO1990 and archaism lists.
179
189
 
180
190
  ---
181
191
 
@@ -197,7 +207,7 @@ Runnable scripts for each feature are in [`examples/`](examples).
197
207
  | --- | --- |
198
208
  | `tugalex/__init__.py` | the `TugaLexicon` class and the noun-gender suffix rules |
199
209
  | `tugalex/data/` | the packaged datasets |
200
- | `scripts/` | the build scripts for `regional_dict.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
210
+ | `scripts/` | the build scripts for `regional_dict.csv.gz`, `words.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
201
211
  | `tests/` | the pytest suite |
202
212
  | `examples/` | one runnable script per feature |
203
213
  | `*.ipynb` | analysis notebooks for the phonetic lexicon and the AO1990 tables |
@@ -208,7 +218,7 @@ uv pip install --python .venv/bin/python --prerelease=allow -e ".[test]"
208
218
  .venv/bin/python -m pytest tests
209
219
  ```
210
220
 
211
- 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.
221
+ CI runs the same suite on Python 3.11 to 3.14 (`.github/workflows/build-tests.yml`). On each pull request, `.github/workflows/downstream-tests.yml` installs the TugaLex of the pull request with desacordo_ortografico from its `dev` branch and runs the desacordo_ortografico suite on the same Python versions. A `DeprecationWarning` fails that job. 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.
212
222
 
213
223
  ---
214
224
 
@@ -5,14 +5,15 @@
5
5
  It gives NLP pipelines and linguistics research a single API for the differences between Portuguese regions and historical spelling agreements.
6
6
 
7
7
  > **Deprecated: the regional pronunciation dictionary.** The phoneme and
8
- > syllable API (`get`, `get_phonemes`, `get_syllables`, `get_wordlist`,
9
- > `get_ipa_map`, `lang_to_region`, `ipa`, `syllables`, `regions` and
10
- > `possible_postags`) emits a `DeprecationWarning`. The next major release
8
+ > syllable API (`get`, `get_phonemes`, `get_syllables`, `get_ipa_map`,
9
+ > `lang_to_region`, `ipa`, `syllables`, `regions` and `possible_postags`)
10
+ > emits a `DeprecationWarning`. The next major release
11
11
  > removes it, together with the legacy `tugaphone.dialects` inventories
12
12
  > that read it. For Portuguese pronunciation, use
13
13
  > [orthography2ipa](https://github.com/TigreGotico/orthography2ipa) with the
14
14
  > pt-PT lexicon of `o2i-lexicons` (`orthography2ipa.use_packaged_lexicons`).
15
- > The noun gender, given-name gender and AO1990 tools stay.
15
+ > The word list (`get_wordlist`), the noun gender, given-name gender and
16
+ > AO1990 tools stay.
16
17
 
17
18
  ---
18
19
 
@@ -33,7 +34,7 @@ TugaLex maps standard ISO codes to internal regional datasets:
33
34
 
34
35
  The regional dictionary ships as a slim gzip extract (word, phones,
35
36
  syllables, region) of the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon),
36
- with 53,142 to 53,145 words in each region. Regenerate it with
37
+ with 53,144 to 53,147 words in each region. Regenerate it with
37
38
  `python scripts/build_regional_dict.py`, which reads the lexicon revision
38
39
  pinned in the script. The regional dictionary has no
39
40
  part of speech: each word has one pronunciation per region, and it answers
@@ -78,6 +79,14 @@ lex.reverse_ao1900_pt("ótimo") # 'óptimo'
78
79
 
79
80
  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)).
80
81
 
82
+ `modern_spelling` rewrites one word to its modern spelling in one variety. It applies the archaism table and then the AO1990 table, and keeps the case of the word:
83
+
84
+ ```python
85
+ lex.modern_spelling("Pharmacia", "pt-BR") # 'Farmácia'
86
+ lex.modern_spelling("chronico", "pt-PT") # 'crónico'
87
+ lex.modern_spelling("chronico", "pt-BR") # 'crônico'
88
+ ```
89
+
81
90
  ### 3. Linguistic Insights
82
91
 
83
92
  TugaLex identifies specific linguistic phenomena programmatically:
@@ -117,7 +126,8 @@ TugaLexicon.get_given_name_gender("Raio") # None
117
126
 
118
127
  TugaLex ships the following datasets under `tugalex/data/`.
119
128
 
120
- * `regional_dict.csv.gz`: phoneme and syllable mappings, 318,860 rows for 53,146 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.
129
+ * `regional_dict.csv.gz`: phoneme and syllable mappings, 318,872 rows for 53,148 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.
130
+ * `words.csv.gz`: the word forms of `regional_dict.csv.gz` with the regions that list each one, and no pronunciations. `get_wordlist` reads it, and it stays when the regional dictionary goes. `scripts/build_wordlist.py` builds it from the regional dictionary.
121
131
  * `heterophonic_homographs.csv`: 27 words pronounced differently depending on POS, 55 rows.
122
132
  * [`acordo_ortografico_pt_PT.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-PT): Portugal old orthographic spellings.
123
133
  * [`acordo_ortografico_pt_BR.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-BR): Brazil old orthographic spellings.
@@ -154,7 +164,7 @@ TugaLex is one piece of the TigreGotico Portuguese NLP stack:
154
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.
155
165
  * [tugamorph](https://github.com/TigreGotico/tugamorph): rule-based morphological analyzer for Portuguese.
156
166
  * [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese. Its `lexicon` extra installs TugaLex.
157
- * [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform.
167
+ * [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform. It reads the TugaLex word list, and its spelling table holds the rows of the TugaLex AO1990 and archaism lists.
158
168
 
159
169
  ---
160
170
 
@@ -176,7 +186,7 @@ Runnable scripts for each feature are in [`examples/`](examples).
176
186
  | --- | --- |
177
187
  | `tugalex/__init__.py` | the `TugaLexicon` class and the noun-gender suffix rules |
178
188
  | `tugalex/data/` | the packaged datasets |
179
- | `scripts/` | the build scripts for `regional_dict.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
189
+ | `scripts/` | the build scripts for `regional_dict.csv.gz`, `words.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
180
190
  | `tests/` | the pytest suite |
181
191
  | `examples/` | one runnable script per feature |
182
192
  | `*.ipynb` | analysis notebooks for the phonetic lexicon and the AO1990 tables |
@@ -187,7 +197,7 @@ uv pip install --python .venv/bin/python --prerelease=allow -e ".[test]"
187
197
  .venv/bin/python -m pytest tests
188
198
  ```
189
199
 
190
- 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.
200
+ CI runs the same suite on Python 3.11 to 3.14 (`.github/workflows/build-tests.yml`). On each pull request, `.github/workflows/downstream-tests.yml` installs the TugaLex of the pull request with desacordo_ortografico from its `dev` branch and runs the desacordo_ortografico suite on the same Python versions. A `DeprecationWarning` fails that job. 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.
191
201
 
192
202
  ---
193
203
 
@@ -1,7 +1,9 @@
1
1
  """The regional dictionary and its phoneme API warn before their removal.
2
2
 
3
- The gender lookups and the AO1990 spelling tools are not deprecated, and
4
- tugaphone calls them on every text it normalises, so they must stay silent.
3
+ The word list, the gender lookups and the AO1990 spelling tools are not
4
+ deprecated. tugaphone calls the gender and AO1990 tools on every text it
5
+ normalises, and desacordo_ortografico reads the word list, so they must stay
6
+ silent.
5
7
  """
6
8
  import warnings
7
9
 
@@ -34,7 +36,6 @@ DEPRECATED = {
34
36
  "get_phonemes": lambda lex: lex.get_phonemes("casa"),
35
37
  "get_syllables": lambda lex: lex.get_syllables("casa"),
36
38
  "get": lambda lex: lex.get("casa"),
37
- "get_wordlist": lambda lex: lex.get_wordlist(),
38
39
  "get_ipa_map": lambda lex: lex.get_ipa_map(),
39
40
  }
40
41
 
@@ -63,6 +64,7 @@ KEPT = {
63
64
  "constructor": lambda lex: TugaLexicon(),
64
65
  "get_noun_gender": lambda lex: TugaLexicon.get_noun_gender("casa"),
65
66
  "get_given_name_gender": lambda lex: TugaLexicon.get_given_name_gender("Isabel"),
67
+ "get_wordlist": lambda lex: lex.get_wordlist(),
66
68
  "AO1990": lambda lex: lex.AO1990,
67
69
  "silent_p_words": lambda lex: lex.silent_p_words,
68
70
  "voiced_u_words": lambda lex: lex.voiced_u_words,
@@ -0,0 +1,114 @@
1
+ """The word list reads its own words-only file and is not deprecated."""
2
+ import gzip
3
+ import importlib.util
4
+ import os
5
+ import warnings
6
+
7
+ import pytest
8
+
9
+ from tugalex import TugaLexicon
10
+
11
+ REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
12
+ DICTIONARY = os.path.join(REPO_ROOT, "tugalex", "data", "regional_dict.csv.gz")
13
+ WORDS = os.path.join(REPO_ROOT, "tugalex", "data", "words.csv.gz")
14
+ REGIONS = ["dli", "lbx", "lda", "mpx", "rjx", "spx"]
15
+
16
+
17
+ @pytest.fixture(scope="module")
18
+ def build():
19
+ spec = importlib.util.spec_from_file_location(
20
+ "build_wordlist", os.path.join(REPO_ROOT, "scripts", "build_wordlist.py"))
21
+ module = importlib.util.module_from_spec(spec)
22
+ spec.loader.exec_module(module)
23
+ return module
24
+
25
+
26
+ @pytest.mark.parametrize("region", REGIONS)
27
+ def test_wordlist_emits_no_deprecation_warning(region):
28
+ with warnings.catch_warnings():
29
+ warnings.simplefilter("error")
30
+ words = TugaLexicon().get_wordlist(region)
31
+ assert "casa" in words
32
+
33
+
34
+ def test_wordlist_does_not_read_the_regional_dictionary(monkeypatch):
35
+ def refuse(path):
36
+ raise AssertionError(f"get_wordlist read the regional dictionary {path}")
37
+
38
+ monkeypatch.setattr(TugaLexicon, "_load_lang_map", staticmethod(refuse))
39
+ lex = TugaLexicon()
40
+ lisbon, luanda = lex.get_wordlist("lbx"), lex.get_wordlist("lda")
41
+ assert len(lisbon) == 53147
42
+ assert len(luanda) == 53146
43
+ # the regional dictionary lists aminoácido and arabescar for Lisbon and
44
+ # not for Luanda, and reda for Luanda and not for Lisbon
45
+ assert {"aminoácido", "arabescar"} <= set(lisbon)
46
+ assert not {"aminoácido", "arabescar"} & set(luanda)
47
+ assert "reda" in luanda and "reda" not in lisbon
48
+ assert lex._ipa == {}
49
+
50
+
51
+ @pytest.fixture
52
+ def custom_dictionary(tmp_path):
53
+ path = tmp_path / "custom.csv"
54
+ path.write_text("word,phones,syllables,region_code\n"
55
+ "Zebra,zˈe|bɾɐ,ze|bra,lbx\n"
56
+ "abelha,ɐ|bˈɐ|ʎɐ,a|be|lha,lbx\n"
57
+ "xícara,ʃˈi|ka|ɾɐ,xí|ca|ra,rjx\n", encoding="utf-8")
58
+ return str(path)
59
+
60
+
61
+ def _deprecations(call):
62
+ with warnings.catch_warnings(record=True) as caught:
63
+ warnings.simplefilter("always")
64
+ result = call()
65
+ return result, [w for w in caught if issubclass(w.category, DeprecationWarning)]
66
+
67
+
68
+ def test_custom_dictionary_gives_its_own_words_with_one_warning(custom_dictionary):
69
+ lex = TugaLexicon(dictionary_path=custom_dictionary)
70
+ words, deprecations = _deprecations(lambda: lex.get_wordlist("lbx"))
71
+ assert words == ["abelha", "zebra"]
72
+ assert len(deprecations) == 1
73
+ assert str(deprecations[0].message).startswith("TugaLexicon.dictionary_path is deprecated")
74
+ assert deprecations[0].filename == __file__
75
+ assert _deprecations(lambda: lex.get_wordlist("rjx"))[0] == ["xícara"]
76
+
77
+
78
+ def test_custom_dictionary_without_the_region_raises(custom_dictionary):
79
+ lex = TugaLexicon(dictionary_path=custom_dictionary)
80
+ with pytest.warns(DeprecationWarning), \
81
+ pytest.raises(ValueError, match="Unsupported dialect: dli"):
82
+ lex.get_wordlist("dli")
83
+
84
+
85
+ def test_missing_custom_dictionary_raises(tmp_path):
86
+ lex = TugaLexicon(dictionary_path=str(tmp_path / "missing.csv.gz"))
87
+ with pytest.warns(DeprecationWarning), pytest.raises(FileNotFoundError):
88
+ lex.get_wordlist("lbx")
89
+
90
+
91
+ @pytest.mark.parametrize("region", REGIONS)
92
+ def test_wordlist_holds_the_words_of_the_regional_dictionary(region):
93
+ _, syllables, _ = TugaLexicon._load_lang_map(DICTIONARY)
94
+ assert TugaLexicon().get_wordlist(region) == sorted(syllables[region])
95
+
96
+
97
+ def test_words_file_is_the_build_output(build, tmp_path):
98
+ # compare the CSV, not the gzip bytes: the gzip header's OS byte
99
+ # differs between Python versions
100
+ out = tmp_path / "words.csv.gz"
101
+ build.main(["--dictionary", DICTIONARY, "--out", str(out)])
102
+ with gzip.open(out) as built, gzip.open(WORDS) as shipped:
103
+ assert built.read() == shipped.read()
104
+
105
+
106
+ def test_wordlist_returns_a_copy():
107
+ lex = TugaLexicon()
108
+ lex.get_wordlist("lbx").clear()
109
+ assert len(lex.get_wordlist("lbx")) == 53147
110
+
111
+
112
+ def test_unknown_region_raises():
113
+ with pytest.raises(ValueError, match="Unsupported dialect: xxx"):
114
+ TugaLexicon().get_wordlist("xxx")
@@ -4,6 +4,7 @@ import json
4
4
  import os
5
5
  import re
6
6
  import warnings
7
+ from collections import defaultdict
7
8
  from difflib import SequenceMatcher
8
9
  from functools import cached_property, lru_cache
9
10
  from typing import Dict, List, Tuple, Optional, Set, Union
@@ -38,6 +39,8 @@ def _warn_dictionary(name: str, stacklevel: int = 3) -> None:
38
39
 
39
40
  NOUN_GENDER_PATH = os.path.join(os.path.dirname(__file__), "data", "noun_gender_exceptions.csv.gz")
40
41
  GIVEN_NAMES_PATH = os.path.join(os.path.dirname(__file__), "data", "given_names.csv.gz")
42
+ WORDLIST_PATH = os.path.join(os.path.dirname(__file__), "data", "words.csv.gz")
43
+ REGIONAL_DICT_PATH = os.path.join(os.path.dirname(__file__), "data", "regional_dict.csv.gz")
41
44
 
42
45
  # Suffix rules for the gender of a Portuguese noun, singular or plural. The
43
46
  # first match wins. Each rule is right for at least 80% of the nouns it
@@ -76,6 +79,17 @@ def _given_names() -> Dict[str, str]:
76
79
  return {row["name"]: row["gender"] for row in csv.DictReader(f)}
77
80
 
78
81
 
82
+ @lru_cache(maxsize=1)
83
+ def _wordlists() -> Dict[str, List[str]]:
84
+ """Region code -> sorted word forms, read from words.csv.gz."""
85
+ wordlists: Dict[str, List[str]] = defaultdict(list)
86
+ with gzip.open(WORDLIST_PATH, "rt", encoding="utf-8", newline="") as f:
87
+ for row in csv.DictReader(f):
88
+ for region in row["regions"].split():
89
+ wordlists[region].append(row["word"])
90
+ return dict(wordlists)
91
+
92
+
79
93
  class TugaLexicon:
80
94
  """
81
95
  A lexicon handler for Portuguese dialects, supporting phoneme transcription,
@@ -90,10 +104,10 @@ class TugaLexicon:
90
104
 
91
105
  The regional pronunciation dictionary and its phoneme API (``ipa``,
92
106
  ``syllables``, ``regions``, ``possible_postags``, ``lang_to_region``,
93
- ``get_phonemes``, ``get_syllables``, ``get``, ``get_wordlist`` and
94
- ``get_ipa_map``) are deprecated and emit a ``DeprecationWarning``. They are
95
- removed in ``DICTIONARY_REMOVAL_VERSION``. The noun and given-name gender
96
- lookups and the AO1990 spelling tools stay.
107
+ ``get_phonemes``, ``get_syllables``, ``get`` and ``get_ipa_map``) are
108
+ deprecated and emit a ``DeprecationWarning``. They are removed in
109
+ ``DICTIONARY_REMOVAL_VERSION``. The word list (``get_wordlist``), the noun
110
+ and given-name gender lookups and the AO1990 spelling tools stay.
97
111
  """
98
112
 
99
113
  _DIALECT_REGIONS: Dict[str, str] = {
@@ -117,9 +131,7 @@ class TugaLexicon:
117
131
  lexicon (TigreGotico/portuguese-unified-pronunciation-lexicon),
118
132
  regenerated by scripts/build_regional_dict.py.
119
133
  """
120
- self.dictionary_path: str = dictionary_path or os.path.join(
121
- os.path.dirname(__file__), "data", "regional_dict.csv.gz"
122
- )
134
+ self.dictionary_path: str = dictionary_path or REGIONAL_DICT_PATH
123
135
  self.ao_pt_path: str = os.path.join(
124
136
  os.path.dirname(__file__), "data", "acordo_ortografico_pt_PT.csv"
125
137
  )
@@ -415,23 +427,32 @@ class TugaLexicon:
415
427
 
416
428
  def get_wordlist(self, region: str = "lbx") -> List[str]:
417
429
  """
418
- Return a sorted list of words available for the given region.
430
+ Return a sorted list of the word forms known for the given region.
431
+
432
+ With the packaged dictionary, the list comes from
433
+ ``data/words.csv.gz``, the word forms of the Portal da Língua
434
+ Portuguesa regional dictionary with no pronunciations, and the call
435
+ does not warn. With a custom ``dictionary_path``, the list holds the
436
+ words of that dictionary, and the call emits the dictionary
437
+ ``DeprecationWarning``: custom dictionaries go in
438
+ ``DICTIONARY_REMOVAL_VERSION``.
419
439
 
420
440
  Parameters:
421
441
  region (str): Region code (e.g., "lbx") identifying the dataset to query.
422
442
 
423
443
  Returns:
424
- List[str]: Words available in the lexicon, sorted alphabetically.
444
+ List[str]: Lowercase word forms of the region, sorted alphabetically.
425
445
 
426
446
  Raises:
427
447
  ValueError: If the dialect is unsupported.
428
-
429
- Deprecated: removed in ``DICTIONARY_REMOVAL_VERSION``.
448
+ FileNotFoundError: If a custom ``dictionary_path`` does not exist.
430
449
  """
431
- _warn_dictionary("get_wordlist")
432
- self._load_dictionary()
433
450
  try:
434
- return sorted(self._syllables[region].keys())
451
+ if self.dictionary_path != REGIONAL_DICT_PATH:
452
+ _warn_dictionary("dictionary_path")
453
+ self._load_dictionary()
454
+ return sorted(self._syllables[region])
455
+ return list(_wordlists()[region])
435
456
  except KeyError as e:
436
457
  raise ValueError(f"Unsupported dialect: {region}") from e
437
458
 
Binary file
@@ -1,8 +1,8 @@
1
1
  # START_VERSION_BLOCK
2
2
  VERSION_MAJOR = 2
3
3
  VERSION_MINOR = 4
4
- VERSION_BUILD = 8
5
- VERSION_ALPHA = 2
4
+ VERSION_BUILD = 9
5
+ VERSION_ALPHA = 0
6
6
  # END_VERSION_BLOCK
7
7
 
8
8
  VERSION_STR = f"{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_BUILD}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tugalex
3
- Version: 2.4.8a2
3
+ Version: 2.4.9
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
@@ -26,14 +26,15 @@ Dynamic: license-file
26
26
  It gives NLP pipelines and linguistics research a single API for the differences between Portuguese regions and historical spelling agreements.
27
27
 
28
28
  > **Deprecated: the regional pronunciation dictionary.** The phoneme and
29
- > syllable API (`get`, `get_phonemes`, `get_syllables`, `get_wordlist`,
30
- > `get_ipa_map`, `lang_to_region`, `ipa`, `syllables`, `regions` and
31
- > `possible_postags`) emits a `DeprecationWarning`. The next major release
29
+ > syllable API (`get`, `get_phonemes`, `get_syllables`, `get_ipa_map`,
30
+ > `lang_to_region`, `ipa`, `syllables`, `regions` and `possible_postags`)
31
+ > emits a `DeprecationWarning`. The next major release
32
32
  > removes it, together with the legacy `tugaphone.dialects` inventories
33
33
  > that read it. For Portuguese pronunciation, use
34
34
  > [orthography2ipa](https://github.com/TigreGotico/orthography2ipa) with the
35
35
  > pt-PT lexicon of `o2i-lexicons` (`orthography2ipa.use_packaged_lexicons`).
36
- > The noun gender, given-name gender and AO1990 tools stay.
36
+ > The word list (`get_wordlist`), the noun gender, given-name gender and
37
+ > AO1990 tools stay.
37
38
 
38
39
  ---
39
40
 
@@ -54,7 +55,7 @@ TugaLex maps standard ISO codes to internal regional datasets:
54
55
 
55
56
  The regional dictionary ships as a slim gzip extract (word, phones,
56
57
  syllables, region) of the [unified Portuguese pronunciation lexicon](https://huggingface.co/datasets/TigreGotico/portuguese-unified-pronunciation-lexicon),
57
- with 53,142 to 53,145 words in each region. Regenerate it with
58
+ with 53,144 to 53,147 words in each region. Regenerate it with
58
59
  `python scripts/build_regional_dict.py`, which reads the lexicon revision
59
60
  pinned in the script. The regional dictionary has no
60
61
  part of speech: each word has one pronunciation per region, and it answers
@@ -99,6 +100,14 @@ lex.reverse_ao1900_pt("ótimo") # 'óptimo'
99
100
 
100
101
  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)).
101
102
 
103
+ `modern_spelling` rewrites one word to its modern spelling in one variety. It applies the archaism table and then the AO1990 table, and keeps the case of the word:
104
+
105
+ ```python
106
+ lex.modern_spelling("Pharmacia", "pt-BR") # 'Farmácia'
107
+ lex.modern_spelling("chronico", "pt-PT") # 'crónico'
108
+ lex.modern_spelling("chronico", "pt-BR") # 'crônico'
109
+ ```
110
+
102
111
  ### 3. Linguistic Insights
103
112
 
104
113
  TugaLex identifies specific linguistic phenomena programmatically:
@@ -138,7 +147,8 @@ TugaLexicon.get_given_name_gender("Raio") # None
138
147
 
139
148
  TugaLex ships the following datasets under `tugalex/data/`.
140
149
 
141
- * `regional_dict.csv.gz`: phoneme and syllable mappings, 318,860 rows for 53,146 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.
150
+ * `regional_dict.csv.gz`: phoneme and syllable mappings, 318,872 rows for 53,148 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.
151
+ * `words.csv.gz`: the word forms of `regional_dict.csv.gz` with the regions that list each one, and no pronunciations. `get_wordlist` reads it, and it stays when the regional dictionary goes. `scripts/build_wordlist.py` builds it from the regional dictionary.
142
152
  * `heterophonic_homographs.csv`: 27 words pronounced differently depending on POS, 55 rows.
143
153
  * [`acordo_ortografico_pt_PT.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-PT): Portugal old orthographic spellings.
144
154
  * [`acordo_ortografico_pt_BR.csv`](https://huggingface.co/datasets/TigreGotico/AO1990_pt-BR): Brazil old orthographic spellings.
@@ -175,7 +185,7 @@ TugaLex is one piece of the TigreGotico Portuguese NLP stack:
175
185
  * [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.
176
186
  * [tugamorph](https://github.com/TigreGotico/tugamorph): rule-based morphological analyzer for Portuguese.
177
187
  * [tugatagger](https://github.com/TigreGotico/tugatagger): Part-of-Speech tagging wrapper for Portuguese. Its `lexicon` extra installs TugaLex.
178
- * [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform.
188
+ * [desacordo_ortografico](https://github.com/TigreGotico/desacordo_ortografico): detects and converts between Portuguese orthographies, including the AO1990 reform. It reads the TugaLex word list, and its spelling table holds the rows of the TugaLex AO1990 and archaism lists.
179
189
 
180
190
  ---
181
191
 
@@ -197,7 +207,7 @@ Runnable scripts for each feature are in [`examples/`](examples).
197
207
  | --- | --- |
198
208
  | `tugalex/__init__.py` | the `TugaLexicon` class and the noun-gender suffix rules |
199
209
  | `tugalex/data/` | the packaged datasets |
200
- | `scripts/` | the build scripts for `regional_dict.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
210
+ | `scripts/` | the build scripts for `regional_dict.csv.gz`, `words.csv.gz`, `noun_gender_exceptions.csv.gz` and `given_names.csv.gz`, and their override files |
201
211
  | `tests/` | the pytest suite |
202
212
  | `examples/` | one runnable script per feature |
203
213
  | `*.ipynb` | analysis notebooks for the phonetic lexicon and the AO1990 tables |
@@ -208,7 +218,7 @@ uv pip install --python .venv/bin/python --prerelease=allow -e ".[test]"
208
218
  .venv/bin/python -m pytest tests
209
219
  ```
210
220
 
211
- 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.
221
+ CI runs the same suite on Python 3.11 to 3.14 (`.github/workflows/build-tests.yml`). On each pull request, `.github/workflows/downstream-tests.yml` installs the TugaLex of the pull request with desacordo_ortografico from its `dev` branch and runs the desacordo_ortografico suite on the same Python versions. A `DeprecationWarning` fails that job. 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.
212
222
 
213
223
  ---
214
224
 
@@ -8,6 +8,7 @@ tests/test_lexicon.py
8
8
  tests/test_noun_gender.py
9
9
  tests/test_regional_dict.py
10
10
  tests/test_stress_marks.py
11
+ tests/test_wordlist.py
11
12
  tugalex/__init__.py
12
13
  tugalex/version.py
13
14
  tugalex.egg-info/PKG-INFO
@@ -21,4 +22,5 @@ tugalex/data/archaisms.csv
21
22
  tugalex/data/given_names.csv.gz
22
23
  tugalex/data/heterophonic_homographs.csv
23
24
  tugalex/data/noun_gender_exceptions.csv.gz
24
- tugalex/data/regional_dict.csv.gz
25
+ tugalex/data/regional_dict.csv.gz
26
+ tugalex/data/words.csv.gz
File without changes
File without changes
File without changes
File without changes