PyThaiNLP / PyThaiNLP/pythainlp

bug: metasound missing 4 consonants from _C2 per paper; truncation before space removal

Open
#1,383 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.