This release is a pre-release and may not be stable for production use.
phonematcher
phonematcher measures how far apart two IPA sounds are, and finds terms that sound like a query. It works on IPA only. To get IPA from text, use a grapheme-to-IPA library such as orthography2ipa.
Every distance comes from distinctive features. The feature table starts from PanPhon (Mortensen et al. 2016), takes the vowels from the IPA chart, and lists every other change with its source. docs/features.md explains the table.
Install
uv pip install phonematcher
The library has no runtime dependencies. The "Search by sound" example below also needs orthography2ipa: uv pip install phonematcher orthography2ipa.
Pass strict=True to raise on a character that IPA does not define. It cannot catch the ASCII letters c, y, j and r, which are also IPA letters, so a spelling that holds one is read as IPA and gives a wrong score with no error.
Distance between sounds
from phonematcher import feature_distance, ipa_distance, segments, substitution_cost
feature_distance("ʁ", "χ") # 0.013: uvular fricatives that differ only in voice
feature_distance("ʁ", "k") # 0.118: a different manner, place and voice
substitution_cost("ʁ", "χ") # 0.115: the square root of the feature distance
segments("ˈt͡ʃɐ̃w̃") # ['t͡ʃ', 'ɐ̃', 'w̃']
ipa_distance("ˈpojʃ", "ˈpojs") # 0.199: one near substitution
feature_distance compares two segments, from 0 to 1. substitution_cost is the one cost of replacing a segment by another. It is the square root of the feature distance. ipa_distance compares two IPA strings: an edit distance where a substitution costs substitution_cost and an insertion or deletion costs 0.5. A substitution costs at most 1, so it never costs more than a deletion plus an insertion. The search groups sounds with the same cost. The costs are the ones that the pre-registered test in benchmarks/prereg-2.md selected.
Search by sound
from orthography2ipa import transcribe
from phonematcher import PhoneticFuzzySearch
search = PhoneticFuzzySearch()
for word in ["pois", "retirada", "carro", "caro", "casa", "dia"]:
search.add_term(transcribe(word, "pt-PT"), word)
query = transcribe("carro", "pt-BR-x-rj") # 'ˈkaχu'
best = search.search(query)[0]
best.id, best.term, round(best.score, 3) # ('carro', ('ˈkaʁu',), 0.115)
A term may have several readings: search.add_term(["ˈpojʃ", "ˈpojs"], "pois").
How it compares
Test split, run once under benchmarks/prereg-2.md. Each cell is the estimate with its 95% interval. The best value in each column is in bold. A dash means that the system does not run the task. SCA ran retrieval on a sample of 500 queries per pair and ALINE on the first 100 of those, so these two retrieval cells are not on the same queries as the other rows. The shipped library is the P5 candidate, with its test numbers. The later changes of the library (one segment cost, a relative sensitivity and strict input) were made on dev only and did not change any word distance. docs/benchmarks.md holds every result.
| System | Cognates, mean AP | Alignment, PAS on common pairs | Retrieval, mean recall@1 |
|---|---|---|---|
| plain edit distance | 0.8234 [0.8108, 0.8363] | 0.6154 [0.5487, 0.6872] | 0.6861 [0.6763, 0.6956] |
| PanPhon, weighted | 0.6361 [0.6151, 0.6565] | — | 0.7765 [0.7675, 0.7856] |
| PanPhon, Hamming | 0.6462 [0.6242, 0.6663] | — | 0.7623 [0.7531, 0.7719] |
| ALINE | 0.6130 [0.5903, 0.6359] | 0.8923 [0.8513, 0.9333] | 0.4150 [0.3742, 0.4550] |
| CLTS sound vectors | 0.7399 [0.7224, 0.7561] | — | 0.7929 [0.7844, 0.8017] |
| SCA | 0.8835 [0.8718, 0.8949] | 0.8974 [0.8564, 0.9385] | 0.7925 [0.7773, 0.8086] |
| phonematcher, starting weights (C0) | 0.7326 [0.7140, 0.7500] | 0.7949 [0.7436, 0.8513] | 0.8082 [0.7999, 0.8168] |
| phonematcher, shipped library (P5) | 0.8035 [0.7874, 0.8186] | 0.8513 [0.8051, 0.8974] | 0.8777 [0.8706, 0.8851] |
Documentation
- docs/index.md: every page, in reading order.
- docs/quickstart.md: first steps.
- docs/features.md: the feature table, its sources and the distance.
- docs/api.md: every public name.
Licence
MIT. The feature table derives from PanPhon (MIT) and from Hayes (2009) through the CSV conversion by Kyle Gorman (Apache-2.0).
To cite phonematcher, use CITATION.cff.
Metadata
Release files for phonematcher 2.2.1a2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| phonematcher-2.2.1a2.tar.gz | 125.0 kB | Without provenance | Details for phonematcher-2.2.1a2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| phonematcher-2.2.1a2-py3-none-any.whl | Python 3 | none | any | Details for phonematcher-2.2.1a2-py3-none-any.whl |
Total release size: 191.4 kB
Release files / phonematcher-2.2.1a2.tar.gz
| Download URL | phonematcher-2.2.1a2.tar.gz |
|---|---|
| Size | 125.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6fb7a0717790c3200455ead3ddcd4cd71728b1cb09ca56ca079bc668b9e6f17
|
|
BLAKE2b-256 checksum How to use checksums |
988d2db0ca361640785128f8eaceef7744dd8c0c6b32f0ed114e56ffeb7b76bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / phonematcher-2.2.1a2-py3-none-any.whl
| Download URL | phonematcher-2.2.1a2-py3-none-any.whl |
|---|---|
| Size | 66.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b24a3f48df92a256a080c4d29689d434e2612ee434fb135d79684560353cab02
|
|
BLAKE2b-256 checksum How to use checksums |
43ffb9231bd1dadc78e8d42aa628dbffddac73ca5a7ac054536e2adc426fe616
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for phonematcher 2.2.1a2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.