Skip to content

Commit 20fc24b

Browse files
authored
Merge pull request #1175 from PyThaiNLP/copilot/add-complete-soundex-thai
Add Complete Soundex for Thai Words Similarity Analysis with Similarity Function
2 parents a26562a + 570b498 commit 20fc24b

5 files changed

Lines changed: 864 additions & 1 deletion

File tree

docs/api/soundex.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,36 @@ prayut_and_somchaip
3737

3838
The `prayut_and_somchaip` module is designed for Thai-English cross-language transliterated word retrieval using the Soundex technique. It is particularly useful for matching transliterated words in both languages.
3939

40+
complete_soundex
41+
~~~~~~~~~~~~~~~~
42+
.. autofunction:: complete_soundex
43+
44+
The `complete_soundex` function implements the Complete Soundex algorithm for Thai word phonetic encoding based on Tapsai et al. (2020). Unlike traditional Soundex methods, it generates variable-length codes representing every syllable in a word.
45+
46+
Each syllable is encoded using a 7-character block structure:
47+
48+
* Initial Consonant (2 chars) - Phonetic grouping
49+
* Vowel (2 chars) - Including length markers
50+
* Final Consonant (1 char) - Sonorant clustering
51+
* Tone (1 char) - Tone mark encoding
52+
* Cluster Symbol (1 char) - Second consonant in clusters
53+
54+
The algorithm handles complex Thai phonetic patterns including ทร transformation, รร special rules, cluster detection, and implicit vowels. Multi-syllable words are automatically tokenized and encoded. This soundex is particularly effective for handling misspelled words, character variations, and similar pronunciations.
55+
56+
complete_soundex_similarity
57+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
58+
.. autofunction:: complete_soundex_similarity
59+
60+
The `complete_soundex_similarity` function calculates the similarity between two Complete Soundex codes using character-wise comparison.
61+
62+
The similarity is computed using the formula:
63+
64+
S(X,Y) = Σ(sim(c_xi, c_yi)) / max(len(X), len(Y))
65+
66+
where sim = 1 if characters match at position i, else 0.
67+
68+
The result is normalized by the maximum length of the two codes, returning a float between 0.0 (no match) and 1.0 (perfect match). This function is useful for finding phonetically similar Thai words and handling spelling variations.
69+
4070
pythainlp.soundex.sound.word_approximation
4171
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4272
.. autofunction:: pythainlp.soundex.sound.word_approximation
@@ -66,4 +96,6 @@ References
6696
6797
.. [#prayut_and_somchaip] Prayut Suwanvisat, Somchai Prasitjutrakul. Thai-English Cross-Language Transliterated Word Retrieval using Soundex Technique. In 1998 [cited 2022 Sep 8]. Available from: https://www.cp.eng.chula.ac.th/~somchai/spj/papers/ThaiText/ncsec98-clir.pdf.
6898
99+
.. [#complete_soundex] Chalermpol Tapsai, Phayung Meesad, and Choochart Haruechaiyasak. 2020. `Complete Soundex for Thai Words Similarity Analysis <https://ph01.tci-thaijo.org/index.php/IT_Journal/article/view/241562/164358>`_. Information Technology Journal KMUTNB. 2020 June 30;16(1):46–59.
100+
69101
.. This enhanced documentation provides clear descriptions of all the modules within the `pythainlp.soundex` module, including their purposes and functionalities. Users can now better understand how to leverage these soundex algorithms for various phonetic matching tasks in the Thai language.

pythainlp/soundex/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77
"""
88

99
__all__ = [
10+
"complete_soundex",
11+
"complete_soundex_similarity",
1012
"lk82",
1113
"metasound",
1214
"prayut_and_somchaip",
1315
"soundex",
1416
"udom83",
1517
]
1618

19+
from pythainlp.soundex.complete_soundex import (
20+
complete_soundex,
21+
complete_soundex_similarity,
22+
)
1723
from pythainlp.soundex.lk82 import lk82
1824
from pythainlp.soundex.metasound import metasound
1925
from pythainlp.soundex.prayut_and_somchaip import prayut_and_somchaip

0 commit comments

Comments
 (0)