Skip to content

Commit

Permalink
Fixed pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
wannaphong committed Jan 1, 2024
1 parent dd2ddaa commit 3d324e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pythainlp/morpheme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"""
PyThaiNLP morpheme
"""
from pythainlp.morpheme.word_formation import nighit
from pythainlp.morpheme.word_formation import nighit
17 changes: 8 additions & 9 deletions pythainlp/morpheme/word_formation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: Copyright 2016-2024 PyThaiNLP Project
# SPDX-License-Identifier: Apache-2.0
from pythainlp.transliterate import pronunciate
from pythainlp import thai_consonants


def nighit(w1: str,w2: str)->str:
def nighit(w1: str, w2: str) -> str:
"""
Nighit (นิคหิต or ํ ) is the niggahita in Thai language for create new \
words from Pali language in Thai.
Expand All @@ -29,25 +28,25 @@ def nighit(w1: str,w2: str)->str:
assert nighit("สํ","ปทา")=="สัมปทา"
assert nighit("สํ","โยค")=="สังโยค"
"""
if not str(w1).endswith('ํ') and len(w1)!=2:
if not str(w1).endswith('ํ') and len(w1) != 2:
raise NotImplementedError(f"The function doesn't support {w1}.")
list_w1 = list(w1)
list_w2 = list(w2)
newword = list()
newword.append(list_w1[0])
newword.append("ั")
consonant_start = [i for i in list_w2 if i in set(thai_consonants)][0]
if consonant_start in ["ก","ช","ค","ข","ง"]:
if consonant_start in ["ก", "ช", "ค", "ข", "ง"]:
newword.append("ง")
elif consonant_start in ["จ","ฉ","ช","ฌ"]:
elif consonant_start in ["จ", "ฉ", "ช", "ฌ"]:
newword.append("ญ")
elif consonant_start in ["ฎ","ฐ","ฑ","ณ"]:
elif consonant_start in ["ฎ", "ฐ", "ฑ", "ณ"]:
newword.append("ณ")
elif consonant_start in ["ด","ถ","ท","ธ","น"]:
elif consonant_start in ["ด", "ถ", "ท", "ธ", "น"]:
newword.append("น")
elif consonant_start in ["ป","ผ","พ","ภ"]:
elif consonant_start in ["ป", "ผ", "พ", "ภ"]:
newword.append("ม")
elif consonant_start in ["ย","ร","ล","ฬ","ว","ศ","ษ","ส","ห"]:
elif consonant_start in ["ย", "ร", "ล", "ฬ", "ว", "ศ", "ษ", "ส", "ห"]:
newword.append("ง")
else:
raise NotImplementedError(f"""
Expand Down
12 changes: 6 additions & 6 deletions tests/test_morpheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class TestMorphemePackage(unittest.TestCase):
def test_nighit(self):
self.assertEqual(nighit("สํ","คีต"), "สังคีต")
self.assertEqual(nighit("สํ","จร"), "สัญจร")
self.assertEqual(nighit("สํ","ฐาน"), "สัณฐาน")
self.assertEqual(nighit("สํ","นิษฐาน"), "สันนิษฐาน")
self.assertEqual(nighit("สํ","ปทา"), "สัมปทา")
self.assertEqual(nighit("สํ","โยค"), "สังโยค")
self.assertEqual(nighit("สํ", "คีต"), "สังคีต")
self.assertEqual(nighit("สํ", "จร"), "สัญจร")
self.assertEqual(nighit("สํ", "ฐาน"), "สัณฐาน")
self.assertEqual(nighit("สํ", "นิษฐาน"), "สันนิษฐาน")
self.assertEqual(nighit("สํ", "ปทา"), "สัมปทา")
self.assertEqual(nighit("สํ", "โยค"), "สังโยค")

0 comments on commit 3d324e3

Please sign in to comment.