Metadata-Version: 2.4
Name: phonematcher
Version: 3.1.6a10
Summary: Distinctive-feature distances between IPA phones, and phonetic fuzzy search over IPA
Author-email: JarbasAi <jarbasai@mailfence.com>
License-Expression: MIT
Project-URL: Source, https://github.com/TigreGotico/phonematcher
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Requires-Dist: orthography2ipa; extra == "test"
Provides-Extra: build
Requires-Dist: panphon==0.22.2; extra == "build"
Requires-Dist: pyyaml; extra == "build"
Provides-Extra: bench
Requires-Dist: panphon==0.22.2; extra == "bench"
Requires-Dist: nltk>=3.10; extra == "bench"
Requires-Dist: soundvectors>=1.0; extra == "bench"
Requires-Dist: pyclts>=4.0; extra == "bench"
Requires-Dist: scipy; extra == "bench"
Requires-Dist: numpy; extra == "bench"
Requires-Dist: scikit-learn; extra == "bench"
Requires-Dist: pyreadr; extra == "bench"
Requires-Dist: orthography2ipa; extra == "bench"
Provides-Extra: bench-copyleft
Requires-Dist: lingpy>=2.6.14; extra == "bench-copyleft"
Dynamic: license-file

# phonematcher
<!-- agent-hint
covers: what phonematcher is, how to install it, and one distance and one search example
source: phonematcher/__init__.py, phonematcher/features.py, phonematcher/distance.py, phonematcher/clustering.py
generated: no
verify: pytest --import-mode=importlib tests/test_docs.py -k README.md
see: docs/index.md, docs/quickstart.md
-->

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](https://github.com/TigreGotico/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.

## Install

```
uv pip install phonematcher
```

The library has no runtime dependencies.

## Distance between sounds

```python
from phonematcher import feature_distance, ipa_distance, segments

feature_distance("ʁ", "χ")       # 0.013: uvular fricatives that differ only in voice
segments("ˈt͡ʃɐ̃w̃")              # ['t͡ʃ', 'ɐ̃', 'w̃']
ipa_distance("ˈpojʃ", "ˈpojs")   # 0.199: one near substitution
```

[Quickstart](docs/quickstart.md) adds the search by sound. A segment that phonematcher cannot read is at distance 1 from every other segment, with one warning ([Design choices and limits](docs/design.md#an-unread-segment-is-at-distance-1)).

## How it compares

<!-- benchmark-table:start -->
Test split, run once under [`benchmarks/prereg-2.md`](https://github.com/TigreGotico/phonematcher/blob/dev/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. Its test numbers describe the tested library at commit `f092f20`, with 36 features and a tone as a segment of its own, and no test has scored the released tone model. [docs/benchmarks.md](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]** |
<!-- benchmark-table:end -->

## Documentation

[docs/index.md](docs/index.md) lists every page in reading order: [quickstart](docs/quickstart.md), [feature table](docs/features.md), [API](docs/api.md), [design choices](docs/design.md). The [whitepaper](whitepaper.md) gives the method and the evidence as one paper.

## 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](CITATION.cff).
