ipakit 0.1.0__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.
- ipakit-0.1.0/LICENSE +21 -0
- ipakit-0.1.0/PKG-INFO +202 -0
- ipakit-0.1.0/README.md +167 -0
- ipakit-0.1.0/ipakit/__init__.py +522 -0
- ipakit-0.1.0/ipakit/_base.py +65 -0
- ipakit-0.1.0/ipakit/_convert.py +95 -0
- ipakit-0.1.0/ipakit/analysis.py +373 -0
- ipakit-0.1.0/ipakit/cli/__init__.py +156 -0
- ipakit-0.1.0/ipakit/cli/__main__.py +8 -0
- ipakit-0.1.0/ipakit/cli/analysis_cmds.py +327 -0
- ipakit-0.1.0/ipakit/cli/analyze.py +380 -0
- ipakit-0.1.0/ipakit/cli/base.py +276 -0
- ipakit-0.1.0/ipakit/cli/convert.py +442 -0
- ipakit-0.1.0/ipakit/cli/distance.py +368 -0
- ipakit-0.1.0/ipakit/cli/features.py +155 -0
- ipakit-0.1.0/ipakit/cli/hierarchy.py +190 -0
- ipakit-0.1.0/ipakit/cli/info.py +73 -0
- ipakit-0.1.0/ipakit/cli/query.py +387 -0
- ipakit-0.1.0/ipakit/constants.py +34 -0
- ipakit-0.1.0/ipakit/data/confusion.json +1 -0
- ipakit-0.1.0/ipakit/data/ipa.xml +412 -0
- ipakit-0.1.0/ipakit/data/phonemaps/cmu.xml +99 -0
- ipakit-0.1.0/ipakit/data/phonemaps/kirshenbaum.xml +167 -0
- ipakit-0.1.0/ipakit/data/phonemaps/lookalikes.xml +15 -0
- ipakit-0.1.0/ipakit/data/phonemaps/timit.xml +96 -0
- ipakit-0.1.0/ipakit/data/phonemaps/xsampa.xml +208 -0
- ipakit-0.1.0/ipakit/distance.py +249 -0
- ipakit-0.1.0/ipakit/distance_model.py +436 -0
- ipakit-0.1.0/ipakit/features.py +686 -0
- ipakit-0.1.0/ipakit/hierarchy.py +139 -0
- ipakit-0.1.0/ipakit/mapper.py +212 -0
- ipakit-0.1.0/ipakit/models.py +135 -0
- ipakit-0.1.0/ipakit/phonemaps.py +177 -0
- ipakit-0.1.0/ipakit/py.typed +0 -0
- ipakit-0.1.0/ipakit/validation.py +76 -0
- ipakit-0.1.0/ipakit/xsampa.py +55 -0
- ipakit-0.1.0/ipakit.egg-info/PKG-INFO +202 -0
- ipakit-0.1.0/ipakit.egg-info/SOURCES.txt +60 -0
- ipakit-0.1.0/ipakit.egg-info/dependency_links.txt +1 -0
- ipakit-0.1.0/ipakit.egg-info/entry_points.txt +2 -0
- ipakit-0.1.0/ipakit.egg-info/requires.txt +14 -0
- ipakit-0.1.0/ipakit.egg-info/top_level.txt +1 -0
- ipakit-0.1.0/pyproject.toml +93 -0
- ipakit-0.1.0/setup.cfg +4 -0
- ipakit-0.1.0/tests/test_analysis.py +273 -0
- ipakit-0.1.0/tests/test_api.py +138 -0
- ipakit-0.1.0/tests/test_cli.py +175 -0
- ipakit-0.1.0/tests/test_cmu.py +96 -0
- ipakit-0.1.0/tests/test_confusion.py +37 -0
- ipakit-0.1.0/tests/test_distance.py +110 -0
- ipakit-0.1.0/tests/test_distance_model.py +232 -0
- ipakit-0.1.0/tests/test_features.py +157 -0
- ipakit-0.1.0/tests/test_hierarchy.py +67 -0
- ipakit-0.1.0/tests/test_models.py +97 -0
- ipakit-0.1.0/tests/test_phonemaps.py +128 -0
- ipakit-0.1.0/tests/test_query.py +124 -0
- ipakit-0.1.0/tests/test_stress.py +59 -0
- ipakit-0.1.0/tests/test_strict.py +75 -0
- ipakit-0.1.0/tests/test_tokenization.py +213 -0
- ipakit-0.1.0/tests/test_validation.py +93 -0
- ipakit-0.1.0/tests/test_wiki.py +159 -0
- ipakit-0.1.0/tests/test_xsampa.py +121 -0
ipakit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kevin Lenzo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ipakit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ipakit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: IPA phonetic toolkit
|
|
5
|
+
Author: Kevin Lenzo
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/lenzo-ka/ipakit
|
|
8
|
+
Project-URL: Repository, https://github.com/lenzo-ka/ipakit
|
|
9
|
+
Project-URL: Issues, https://github.com/lenzo-ka/ipakit/issues
|
|
10
|
+
Keywords: ipa,phonetics,phonology,linguistics,speech,cmu,arpabet,timit
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Human Machine Interfaces
|
|
19
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "test"
|
|
26
|
+
Provides-Extra: lint
|
|
27
|
+
Requires-Dist: ruff>=0.15; extra == "lint"
|
|
28
|
+
Requires-Dist: mypy>=2.1; extra == "lint"
|
|
29
|
+
Requires-Dist: black<27,>=26.5; extra == "lint"
|
|
30
|
+
Provides-Extra: icu
|
|
31
|
+
Requires-Dist: icukit-pyicu>=78.3.0; extra == "icu"
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: ipakit[icu,lint,test]; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# ipakit
|
|
37
|
+
|
|
38
|
+
[](https://github.com/lenzo-ka/ipakit/actions/workflows/ci.yml)
|
|
39
|
+
[](https://pypi.org/project/ipakit/)
|
|
40
|
+
[](https://pypi.org/project/ipakit/)
|
|
41
|
+
[](LICENSE)
|
|
42
|
+
|
|
43
|
+
A pure-Python IPA (International Phonetic Alphabet) phonetic toolkit:
|
|
44
|
+
phonetic features, distances, natural classes, and conversion between IPA and
|
|
45
|
+
CMU ARPABET, X-SAMPA, Kirshenbaum, and TIMIT notations.
|
|
46
|
+
|
|
47
|
+
- **Zero runtime dependencies** — all phonetic data ships as XML in the package.
|
|
48
|
+
- **Typed** (`py.typed`, mypy-strict clean).
|
|
49
|
+
- **Both a library and a CLI** (`ipakit`).
|
|
50
|
+
|
|
51
|
+
## Install
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install ipakit
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For development (tests, linters, and the X-SAMPA table tooling):
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install -e ".[dev]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Quick start (Python)
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import ipakit
|
|
67
|
+
|
|
68
|
+
# Phonetic features and descriptions
|
|
69
|
+
ipakit.describe("p") # 'voiceless bilabial plosive'
|
|
70
|
+
ipakit.features("p") # {'manner': 'plosive', 'place': 'bilabial', ...}
|
|
71
|
+
|
|
72
|
+
# Phonetic distance (0.0 identical … 1.0 maximally different)
|
|
73
|
+
ipakit.distance("p", "b") # 0.043 (differ only in voicing)
|
|
74
|
+
ipakit.nearest_phones("p", n=3) # [('ɸ', 0.005), ('f', 0.008), ('p͡f', 0.008)]
|
|
75
|
+
ipakit.word_similarity("kæt", "kæd") # 0.986
|
|
76
|
+
|
|
77
|
+
# Tokenize / normalize (tie-bar affricates, diphthongs)
|
|
78
|
+
ipakit.tokenize("t͡ʃe͡ɪnd͡ʒ") # ['t͡ʃ', 'e͡ɪ', 'n', 'd͡ʒ']
|
|
79
|
+
|
|
80
|
+
# Validate
|
|
81
|
+
ipakit.validate_ipa("kæt") # [] (valid)
|
|
82
|
+
ipakit.validate_ipa("k4t") # [{'type': 'error', 'code': 'unknown_symbol', ...}]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Conversions
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# CMU ARPABET
|
|
89
|
+
ipakit.to_cmu("ˈkæt") # ['K', 'AE1', 'T']
|
|
90
|
+
ipakit.to_ipa(["K", "AE1", "T"]) # 'kˈæt'
|
|
91
|
+
|
|
92
|
+
# X-SAMPA (ASCII)
|
|
93
|
+
ipakit.ipa_to_xsampa("t͡ʃ") # 't_S'
|
|
94
|
+
ipakit.xsampa_to_ipa("t_S") # 't͡ʃ'
|
|
95
|
+
|
|
96
|
+
# Kirshenbaum / TIMIT
|
|
97
|
+
ipakit.to_kirshenbaum("kæt") # 'k&t'
|
|
98
|
+
ipakit.to_timit("kæt") # ['k', 'ae', 't']
|
|
99
|
+
|
|
100
|
+
# Features straight from a non-IPA symbol (list of per-segment dicts)
|
|
101
|
+
ipakit.features_from_xsampa("t_S") # [{'manner': 'affricate', 'place': 'postalveolar', ...}]
|
|
102
|
+
ipakit.features_from_cmu("K") # [{'manner': 'plosive', 'place': 'velar', ...}]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
By default converters skip symbols they can't map. Pass `strict=True` to any of
|
|
106
|
+
them to raise `ValueError` on unconvertible input instead:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
ipakit.to_cmu("k4t") # ['K', 'T'] (the '4' is skipped)
|
|
110
|
+
ipakit.to_cmu("k4t", strict=True) # ValueError: Cannot convert to CMU ARPABET: ...
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Distribution-aware distance
|
|
114
|
+
|
|
115
|
+
`distance()` is the **raw feature metric** — an absolute, inventory-independent
|
|
116
|
+
mean over phonetic features (so `distance("p", "b")` is always `0.043`). Raw
|
|
117
|
+
distances bunch up in a narrow band, which makes fixed thresholds hard to pick.
|
|
118
|
+
`normalized_distance()` renormalizes a raw distance to its **percentile** within
|
|
119
|
+
the bundled IPA inventory's pairwise distribution, spreading values across
|
|
120
|
+
`[0, 1]`:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
ipakit.distance("p", "b") # 0.043 raw feature distance
|
|
124
|
+
ipakit.normalized_distance("p", "b") # 0.155 percentile within bundled IPA
|
|
125
|
+
ipakit.normalized_distance("p", "a") # 0.602
|
|
126
|
+
ipakit.confusability("p", "b") # 0.845 complement of normalized_distance
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
For a model over a chosen reference inventory — percentiles are **relative** to
|
|
130
|
+
it and not comparable across inventories — use `distance_model()`:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from ipakit import Phoneset
|
|
134
|
+
|
|
135
|
+
eng = ipakit.distance_model(
|
|
136
|
+
Phoneset.from_list(
|
|
137
|
+
["p", "b", "t", "d", "k", "ɡ", "s", "z", "m", "n", "l", "ɹ", "a", "i", "u"],
|
|
138
|
+
name="english",
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
eng.distance("p", "b") # 0.267 percentile within this 15-phone set
|
|
142
|
+
eng.nearest("p", n=3) # [('t', 0.048), ('s', 0.086), ('k', 0.21)]
|
|
143
|
+
eng.word_similarity("kæt", "kæd") # 0.956
|
|
144
|
+
eng.is_similar("kæt", "kæd", threshold=0.8) # True
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`distance_model()` also accepts `gamma` (power transform to push dissimilar
|
|
148
|
+
pairs apart), `sub_mode="di"` (delete+insert substitution cost for word
|
|
149
|
+
alignment), and `threshold` / `max_length_ratio` defaults for `is_similar`. The
|
|
150
|
+
raw pairwise matrix ships as `ipakit/data/confusion.json`; per-inventory models
|
|
151
|
+
reuse it and only re-slice the percentile distribution.
|
|
152
|
+
|
|
153
|
+
## Conventions
|
|
154
|
+
|
|
155
|
+
- **Stress is placed on the vowel** (the syllable nucleus), not the syllable
|
|
156
|
+
onset: `to_ipa(["K", "AE1", "T"])` → `kˈæt`. Syllabification is preserved
|
|
157
|
+
across round trips (`W AO1 T ER0` ↔ `wˈɔtɚ`).
|
|
158
|
+
- **Affricates and diphthongs use the tie bar** (`t͡ʃ`, `e͡ɪ`).
|
|
159
|
+
- **Round-trip guarantee (X-SAMPA only):** IPA written in these conventions
|
|
160
|
+
round-trips through X-SAMPA (`ipa → xsampa → ipa`). The only exceptions are
|
|
161
|
+
`b͡v` and `t͡θ`, where the X-SAMPA tie encoding `_` collides with a
|
|
162
|
+
diacritic/tone encoding (`_v`, `_T`) — an inherent X-SAMPA ambiguity that ICU
|
|
163
|
+
shares. The CMU, TIMIT, and Kirshenbaum mappings are lossy (they collapse IPA
|
|
164
|
+
distinctions) and carry no round-trip guarantee.
|
|
165
|
+
|
|
166
|
+
## CLI
|
|
167
|
+
|
|
168
|
+
```text
|
|
169
|
+
ipakit features p # Get features for 'p'
|
|
170
|
+
ipakit describe p # "voiceless bilabial plosive"
|
|
171
|
+
ipakit convert to-cmu "kˈæt" # IPA to CMU: K AE1 T (stress on the vowel)
|
|
172
|
+
ipakit convert to-ipa K AE1 T # CMU to IPA: kˈæt
|
|
173
|
+
ipakit convert to-xsampa "t͡ʃ" # IPA to X-SAMPA: t_S
|
|
174
|
+
ipakit query match plosive bilabial # Find phones by feature
|
|
175
|
+
ipakit analysis natural-class p t k # Shared features of a set
|
|
176
|
+
ipakit analysis minimal-pairs p # Find similar phones
|
|
177
|
+
ipakit distance pair p b # Raw feature distance: ~0.04
|
|
178
|
+
ipakit distance confusability p b # Inventory-relative: 0.8454
|
|
179
|
+
ipakit distance word kæt kæd # Word similarity: 0.9742
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The `distance confusability`/`word` commands use the distribution-aware model;
|
|
183
|
+
scope them to a reference inventory with `--phoneset FILE` (one phone per line).
|
|
184
|
+
|
|
185
|
+
Most commands accept `--format json` (or `-j`) for machine-readable output.
|
|
186
|
+
Run `ipakit`, `ipakit <group>`, or append `help`/`-h` anywhere for usage.
|
|
187
|
+
|
|
188
|
+
## Development
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
pip install -e ".[dev]" # or ".[test]" / ".[lint]" for a lean subset
|
|
192
|
+
pre-commit install # black, ruff, mypy --strict, hygiene hooks
|
|
193
|
+
pytest # unit tests + docstring examples
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
CI (`.github/workflows/ci.yml`) mirrors these on every push/PR across Python
|
|
197
|
+
3.11–3.13, and validates the committed derived artifacts (the IPA ↔ X-SAMPA
|
|
198
|
+
table and the phone-distance matrix) against their generators in `scripts/`.
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT — see [LICENSE](LICENSE).
|
ipakit-0.1.0/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# ipakit
|
|
2
|
+
|
|
3
|
+
[](https://github.com/lenzo-ka/ipakit/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/ipakit/)
|
|
5
|
+
[](https://pypi.org/project/ipakit/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
A pure-Python IPA (International Phonetic Alphabet) phonetic toolkit:
|
|
9
|
+
phonetic features, distances, natural classes, and conversion between IPA and
|
|
10
|
+
CMU ARPABET, X-SAMPA, Kirshenbaum, and TIMIT notations.
|
|
11
|
+
|
|
12
|
+
- **Zero runtime dependencies** — all phonetic data ships as XML in the package.
|
|
13
|
+
- **Typed** (`py.typed`, mypy-strict clean).
|
|
14
|
+
- **Both a library and a CLI** (`ipakit`).
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install ipakit
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For development (tests, linters, and the X-SAMPA table tooling):
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e ".[dev]"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick start (Python)
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import ipakit
|
|
32
|
+
|
|
33
|
+
# Phonetic features and descriptions
|
|
34
|
+
ipakit.describe("p") # 'voiceless bilabial plosive'
|
|
35
|
+
ipakit.features("p") # {'manner': 'plosive', 'place': 'bilabial', ...}
|
|
36
|
+
|
|
37
|
+
# Phonetic distance (0.0 identical … 1.0 maximally different)
|
|
38
|
+
ipakit.distance("p", "b") # 0.043 (differ only in voicing)
|
|
39
|
+
ipakit.nearest_phones("p", n=3) # [('ɸ', 0.005), ('f', 0.008), ('p͡f', 0.008)]
|
|
40
|
+
ipakit.word_similarity("kæt", "kæd") # 0.986
|
|
41
|
+
|
|
42
|
+
# Tokenize / normalize (tie-bar affricates, diphthongs)
|
|
43
|
+
ipakit.tokenize("t͡ʃe͡ɪnd͡ʒ") # ['t͡ʃ', 'e͡ɪ', 'n', 'd͡ʒ']
|
|
44
|
+
|
|
45
|
+
# Validate
|
|
46
|
+
ipakit.validate_ipa("kæt") # [] (valid)
|
|
47
|
+
ipakit.validate_ipa("k4t") # [{'type': 'error', 'code': 'unknown_symbol', ...}]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Conversions
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
# CMU ARPABET
|
|
54
|
+
ipakit.to_cmu("ˈkæt") # ['K', 'AE1', 'T']
|
|
55
|
+
ipakit.to_ipa(["K", "AE1", "T"]) # 'kˈæt'
|
|
56
|
+
|
|
57
|
+
# X-SAMPA (ASCII)
|
|
58
|
+
ipakit.ipa_to_xsampa("t͡ʃ") # 't_S'
|
|
59
|
+
ipakit.xsampa_to_ipa("t_S") # 't͡ʃ'
|
|
60
|
+
|
|
61
|
+
# Kirshenbaum / TIMIT
|
|
62
|
+
ipakit.to_kirshenbaum("kæt") # 'k&t'
|
|
63
|
+
ipakit.to_timit("kæt") # ['k', 'ae', 't']
|
|
64
|
+
|
|
65
|
+
# Features straight from a non-IPA symbol (list of per-segment dicts)
|
|
66
|
+
ipakit.features_from_xsampa("t_S") # [{'manner': 'affricate', 'place': 'postalveolar', ...}]
|
|
67
|
+
ipakit.features_from_cmu("K") # [{'manner': 'plosive', 'place': 'velar', ...}]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
By default converters skip symbols they can't map. Pass `strict=True` to any of
|
|
71
|
+
them to raise `ValueError` on unconvertible input instead:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
ipakit.to_cmu("k4t") # ['K', 'T'] (the '4' is skipped)
|
|
75
|
+
ipakit.to_cmu("k4t", strict=True) # ValueError: Cannot convert to CMU ARPABET: ...
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Distribution-aware distance
|
|
79
|
+
|
|
80
|
+
`distance()` is the **raw feature metric** — an absolute, inventory-independent
|
|
81
|
+
mean over phonetic features (so `distance("p", "b")` is always `0.043`). Raw
|
|
82
|
+
distances bunch up in a narrow band, which makes fixed thresholds hard to pick.
|
|
83
|
+
`normalized_distance()` renormalizes a raw distance to its **percentile** within
|
|
84
|
+
the bundled IPA inventory's pairwise distribution, spreading values across
|
|
85
|
+
`[0, 1]`:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
ipakit.distance("p", "b") # 0.043 raw feature distance
|
|
89
|
+
ipakit.normalized_distance("p", "b") # 0.155 percentile within bundled IPA
|
|
90
|
+
ipakit.normalized_distance("p", "a") # 0.602
|
|
91
|
+
ipakit.confusability("p", "b") # 0.845 complement of normalized_distance
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
For a model over a chosen reference inventory — percentiles are **relative** to
|
|
95
|
+
it and not comparable across inventories — use `distance_model()`:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from ipakit import Phoneset
|
|
99
|
+
|
|
100
|
+
eng = ipakit.distance_model(
|
|
101
|
+
Phoneset.from_list(
|
|
102
|
+
["p", "b", "t", "d", "k", "ɡ", "s", "z", "m", "n", "l", "ɹ", "a", "i", "u"],
|
|
103
|
+
name="english",
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
eng.distance("p", "b") # 0.267 percentile within this 15-phone set
|
|
107
|
+
eng.nearest("p", n=3) # [('t', 0.048), ('s', 0.086), ('k', 0.21)]
|
|
108
|
+
eng.word_similarity("kæt", "kæd") # 0.956
|
|
109
|
+
eng.is_similar("kæt", "kæd", threshold=0.8) # True
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`distance_model()` also accepts `gamma` (power transform to push dissimilar
|
|
113
|
+
pairs apart), `sub_mode="di"` (delete+insert substitution cost for word
|
|
114
|
+
alignment), and `threshold` / `max_length_ratio` defaults for `is_similar`. The
|
|
115
|
+
raw pairwise matrix ships as `ipakit/data/confusion.json`; per-inventory models
|
|
116
|
+
reuse it and only re-slice the percentile distribution.
|
|
117
|
+
|
|
118
|
+
## Conventions
|
|
119
|
+
|
|
120
|
+
- **Stress is placed on the vowel** (the syllable nucleus), not the syllable
|
|
121
|
+
onset: `to_ipa(["K", "AE1", "T"])` → `kˈæt`. Syllabification is preserved
|
|
122
|
+
across round trips (`W AO1 T ER0` ↔ `wˈɔtɚ`).
|
|
123
|
+
- **Affricates and diphthongs use the tie bar** (`t͡ʃ`, `e͡ɪ`).
|
|
124
|
+
- **Round-trip guarantee (X-SAMPA only):** IPA written in these conventions
|
|
125
|
+
round-trips through X-SAMPA (`ipa → xsampa → ipa`). The only exceptions are
|
|
126
|
+
`b͡v` and `t͡θ`, where the X-SAMPA tie encoding `_` collides with a
|
|
127
|
+
diacritic/tone encoding (`_v`, `_T`) — an inherent X-SAMPA ambiguity that ICU
|
|
128
|
+
shares. The CMU, TIMIT, and Kirshenbaum mappings are lossy (they collapse IPA
|
|
129
|
+
distinctions) and carry no round-trip guarantee.
|
|
130
|
+
|
|
131
|
+
## CLI
|
|
132
|
+
|
|
133
|
+
```text
|
|
134
|
+
ipakit features p # Get features for 'p'
|
|
135
|
+
ipakit describe p # "voiceless bilabial plosive"
|
|
136
|
+
ipakit convert to-cmu "kˈæt" # IPA to CMU: K AE1 T (stress on the vowel)
|
|
137
|
+
ipakit convert to-ipa K AE1 T # CMU to IPA: kˈæt
|
|
138
|
+
ipakit convert to-xsampa "t͡ʃ" # IPA to X-SAMPA: t_S
|
|
139
|
+
ipakit query match plosive bilabial # Find phones by feature
|
|
140
|
+
ipakit analysis natural-class p t k # Shared features of a set
|
|
141
|
+
ipakit analysis minimal-pairs p # Find similar phones
|
|
142
|
+
ipakit distance pair p b # Raw feature distance: ~0.04
|
|
143
|
+
ipakit distance confusability p b # Inventory-relative: 0.8454
|
|
144
|
+
ipakit distance word kæt kæd # Word similarity: 0.9742
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The `distance confusability`/`word` commands use the distribution-aware model;
|
|
148
|
+
scope them to a reference inventory with `--phoneset FILE` (one phone per line).
|
|
149
|
+
|
|
150
|
+
Most commands accept `--format json` (or `-j`) for machine-readable output.
|
|
151
|
+
Run `ipakit`, `ipakit <group>`, or append `help`/`-h` anywhere for usage.
|
|
152
|
+
|
|
153
|
+
## Development
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
pip install -e ".[dev]" # or ".[test]" / ".[lint]" for a lean subset
|
|
157
|
+
pre-commit install # black, ruff, mypy --strict, hygiene hooks
|
|
158
|
+
pytest # unit tests + docstring examples
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
CI (`.github/workflows/ci.yml`) mirrors these on every push/PR across Python
|
|
162
|
+
3.11–3.13, and validates the committed derived artifacts (the IPA ↔ X-SAMPA
|
|
163
|
+
table and the phone-distance matrix) against their generators in `scripts/`.
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
MIT — see [LICENSE](LICENSE).
|