Double Metaphone for Python

1.2 · active · verified Wed Apr 15

The `doublemetaphone` library provides a Python wrapper for the C++ implementation of the Double Metaphone phonetic algorithm. This algorithm generates approximate phonetic representations (codes) for words, useful for matching names or words with similar pronunciations despite different spellings. The current version is 1.2. Releases appear to be infrequent, with significant gaps between updates.

Warnings

Install

Imports

Quickstart

Generate Double Metaphone codes for a word and compare them. The function returns a tuple of (primary_code, secondary_code).

from doublemetaphone import doublemetaphone

word1 = "Smith"
word2 = "Schmidt"

primary1, secondary1 = doublemetaphone(word1)
primary2, secondary2 = doublemetaphone(word2)

print(f"'{word1}': Primary='{primary1}', Secondary='{secondary1}'")
print(f"'{word2}': Primary='{primary2}', Secondary='{secondary2}'")

# Double Metaphone often returns two codes to account for phonetic ambiguities.
# For example, 'Smith' and 'Schmidt' share a secondary code.
if primary1 == primary2 or secondary1 == secondary2 or primary1 == secondary2 or primary2 == secondary1:
    print(f"'{word1}' and '{word2}' are phonetically similar.")

view raw JSON →