Skip to main content

Articulatory Moment Transform — language-agnostic phonetic name matching

Project description

AMT (Python)

Articulatory Moment Transform — language-agnostic phonetic name matching.

Install

pip install amt-phonetic

Or from source:

git clone https://github.com/KhaledSMQ/amt-phonetic
cd amt-phonetic/python
pip install -e .

No runtime dependencies (just the Python standard library, 3.10+).

Quick start

import amt

# Encode any name to a pair (32-bit spectral key, 64-bit bloom signature)
sp, bl, classes = amt.encode_token("Khaled")

# Test whether two names match
assert amt.matches("Khaled", "Khalid")       # transliteration variants
assert amt.matches("Khaled", "خالد")         # Latin ↔ Arabic script
assert amt.matches("Gamal", "Jamal")         # Egyptian ↔ Standard Arabic G↔J
assert not amt.matches("Khaled", "Robert")

# Graded similarity in [0, 1]
amt.similarity("Khaled Sameer", "khaled samir")   # → ≈ 1.0
amt.similarity("Khaled", "Ahmed")                 # → low

# Build a fuzzy-searchable index (BK-tree, O(log N) typical)
index = amt.BKTree[str]()
for name in customer_names:
    sp, _, _ = amt.encode_token(name)
    for key in sp:
        index.add(key, name)

# Query: radius-4 returns near-matches on Hamming distance
query_sp, _, _ = amt.encode_token("Khaleed")
hits = index.query(query_sp[0], radius=4)
# hits = [(distance, name), ...] sorted by distance

Extending to new scripts

AMT ships with Latin and Arabic. Add other scripts by registering character → sonority-class mappings:

amt.register_character("ц", 3)   # Cyrillic tse → fricative
amt.register_character("ж", 3)   # Cyrillic zhe → fricative
amt.register_character("ш", 3)   # Cyrillic sha → fricative

See amt/sonority.py for the 8-class scheme used by the algorithm.

API

Function Purpose
encode_token(token) Encode single token → (spectrals, blooms, classes)
encode(name) Encode multi-token name → list[Code]
encode_batch(names) Encode an iterable of names
matches(a, b) Fast boolean match test
similarity(a, b) Graded similarity score in [0, 1]
token_distance(code_a, code_b) Token-level distance
BKTree() Metric tree for fuzzy search
LSHIndex(bands=4) Banded LSH index for very large corpora
register_character(char, cls) Extend the sonority map

Benchmarks

On a single CPython 3.12 thread:

Encoded 200,000 tokens in 3,200 ms
Throughput: 62,000 tokens/sec
Latency:    16 µs/token

Testing

pip install -e ".[dev]"
pytest tests/

Algorithm

See the whitepaper for the full mathematical treatment, benchmark methodology, and comparisons against Soundex, Metaphone, Double Metaphone, NYSIIS, and Beider-Morse.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amt_phonetic-1.0.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

amt_phonetic-1.0.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file amt_phonetic-1.0.0.tar.gz.

File metadata

  • Download URL: amt_phonetic-1.0.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for amt_phonetic-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9bd73f9903837a0402f81741f4bc86e4ae85541acd0764286eeb347e6d7c8c35
MD5 d0b629ee9215dd74c46e68837d26cf22
BLAKE2b-256 b93310d9accc67efc6ae02eb955bd562e0017f974fe4325b1bc4ae8760f819ca

See more details on using hashes here.

File details

Details for the file amt_phonetic-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: amt_phonetic-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for amt_phonetic-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92a4c631a976a052e2faef9406924c497d4173a3d90a939d86ae6e8650801389
MD5 d15c815377b3f1f55c2b46004cd090fb
BLAKE2b-256 eda34dec9fdaf5056f1d7ec05f567ad84164ea847bb43bfe454f10df0ed39da8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page