PyThaiNLP / PyThaiNLP/pythainlp
bug: metasound missing 4 consonants from _C2 per paper; truncation before space removal
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 304
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 14
Description
Description
Two algorithmic bugs in metasound() verified against the original paper:
Snae & Brückner. (2009). Issues in Informing Science and Information Technology, Vol. 6, pp. 497–515.
http://iisit.org/Vol6/IISITv6p497-515Snae620.pdf
Bug 1: Truncation before space removal (line 82)
After removing karan (์) by replacing characters with spaces, the algorithm truncates to the requested length BEFORE filtering those spaces. Spaces occupy slots in the length limit, pushing real consonants out.
Bug 2: 4 consonants missing from _C2 (line 19)
The paper's Table on page 507 defines group 2 (D sound) with 18 consonants: จ ฉ ช ซ ฌ ฎ ฏ ฐ ฑ ฒ ด ต ถ ท ธ ศ ษ ส. The implementation has only 14 — missing ฏ, ฑ, ถ, ธ. The paper's PHP source code in the Appendix (pp. 513–514) confirms all 18.
Also: duplicate ข in prayut_and_somchaip._C2 (line 21). No functional impact.
Note on ห, อ, ฮ: These mapping to code 0 is correct per the paper — the 8-group scheme has no /h/ or glottal class (only 41 of 44 consonants classified). However, Complete Soundex (Tapsai et al., 2020) addresses this limitation with 27 initial consonant groups. For users needing more precise matching, complete_soundex is the better choice.
Steps to reproduce
from pythainlp.soundex import metasound
# Bug 1: truncation order
metasound("สรรค์พล", 4) # 'ส550' — wrong, should be 'ส553'
metasound("รักษ์นา", 4) # 'ร100' — wrong, should be 'ร150'
# Bug 2: missing consonants
metasound("กถน", 4) # 'ก050' — ถ maps to '0', should be '2'
metasound("กธน", 4) # 'ก050' — ธ maps to '0', should be '2'
PyThaiNLP version
5.3.3
References
- MetaSound paper Table p.507, PHP Appendix pp.513–514: http://iisit.org/Vol6/IISITv6p497-515Snae620.pdf
- Complete Soundex: https://ph01.tci-thaijo.org/index.php/IT_Journal/article/view/241562
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at metasound(), inspecting _C2 around line 19 and the truncation logic around line 82; run the four reported examples to reproduce both bugs. Done means the examples produce the expected codes, all 18 consonants from the paper’s group 2 are mapped, and the duplicate ข entry is addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100