Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ and this project adheres to
- Full release notes: <https://github.com/PyThaiNLP/pythainlp/releases>
- Commit history: <https://github.com/PyThaiNLP/pythainlp/compare/v5.3.3...v5.3.4>

## [Unreleased]

## Changed

- Improve guardrails in `check_sara()` and `nighit()`

## [5.3.4] - 2026-04-02

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pythainlp/khavee/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def check_sara(self, word: str) -> str:
sara.append("เอือ")

if not sara:
return "Can't find Sara in this word"
return ""

return sara[0]

Expand Down
11 changes: 11 additions & 0 deletions tests/core/test_khavee.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,14 @@ def test_เอือ_sara(self):

def test_returns_string(self):
self.assertIsInstance(self.kv.check_sara("เริง"), str)

def test_empty_string_returns_empty(self):
self.assertEqual(self.kv.check_sara(""), "")

def test_empty_string_after_removing_karun_returns_empty(self):
self.assertEqual(self.kv.check_sara("ก์"), "")

def test_empty_string_after_removing_tone_marks_returns_empty(self):
self.assertEqual(
self.kv.check_sara("\u0e48"), ""
) # The string contains only Thai Mai Ek tone mark
11 changes: 11 additions & 0 deletions tests/core/test_morpheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@
class MorphemeTestCase(unittest.TestCase):
def test_nighit(self):
self.assertEqual(nighit("สํ", "คีต"), "สังคีต")
self.assertEqual(
nighit("สํ", "คีต "), "สังคีต"
) # w2 has trailing space, should still work
self.assertEqual(
nighit("สํ ", "คีต"), "สังคีต"
) # w1 has trailing space, should still work
self.assertEqual(nighit("สํ", "จร"), "สัญจร")
self.assertEqual(nighit("สํ", "ฐาน"), "สัณฐาน")
self.assertEqual(nighit("สํ", "นิษฐาน"), "สันนิษฐาน")
self.assertEqual(nighit("สํ", "ปทา"), "สัมปทา")
self.assertEqual(nighit("สํ", "โยค"), "สังโยค")
self.assertEqual(nighit("", "คีต"), "คีต") # w1 is empty, should return w2
self.assertEqual(nighit("สํ", ""), "สํ") # w2 is empty, should return w1

with self.assertRaises(NotImplementedError):
nighit("abc", "คีต") # w1 does not end with ํ and len > 2
with self.assertRaises(NotImplementedError):
nighit("สํ", "มาร") # consonant ม is not in any supported group
with self.assertRaises(ValueError):
nighit("สํ", "123") # w2 does not contain any Thai consonant

def test_is_native_thai(self):
self.assertFalse(is_native_thai(None)) # type: ignore[arg-type]
Expand Down
Loading