homophones¶
Exact and near-homophone discovery using the CMU Pronouncing Dictionary.
phonemenal.homophones
¶
Exact and near-homophone discovery via CMU pronunciation dictionary inversion.
- find(): exact homophones (identical pronunciation)
- find_similar(): near-homophones above a similarity threshold
find(word: str, *, include_self: bool = False) -> list[str]
¶
Find exact homophones — words with identical pronunciation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
word
|
str
|
Word to look up (case-insensitive). |
required |
include_self
|
bool
|
If True, include the input word in results. |
False
|
Returns list of homophones sorted alphabetically.
Source code in phonemenal/homophones.py
find_similar(word: str, *, candidates: list[str] | None = None, min_score: float = 0.75, weights: tuple[float, float, float] = (1.0, 1.0, 1.0), max_results: int = 20) -> list[dict]
¶
Find near-homophones above a similarity threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
word
|
str
|
Word to compare against. |
required |
candidates
|
list[str] | None
|
List of words to check. If None, checks exact homophones only (use with a candidate list for broader scanning). |
None
|
min_score
|
float
|
Minimum composite similarity score (0.0–1.0). |
0.75
|
weights
|
tuple[float, float, float]
|
(ppc_weight, pld_weight, lcs_weight) for composite scoring. |
(1.0, 1.0, 1.0)
|
max_results
|
int
|
Maximum results to return. |
20
|
Returns list of dicts with 'word', 'score', and 'is_exact_homophone' keys, sorted by score descending.