From 3d324e3de50db16b14aafeed267080722cef87b3 Mon Sep 17 00:00:00 2001 From: Wannaphong Phatthiyaphaibun Date: Mon, 1 Jan 2024 17:43:22 +0700 Subject: [PATCH] Fixed pep8 --- pythainlp/morpheme/__init__.py | 2 +- pythainlp/morpheme/word_formation.py | 17 ++++++++--------- tests/test_morpheme.py | 12 ++++++------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pythainlp/morpheme/__init__.py b/pythainlp/morpheme/__init__.py index cfd74284d..df4e690af 100644 --- a/pythainlp/morpheme/__init__.py +++ b/pythainlp/morpheme/__init__.py @@ -5,4 +5,4 @@ """ PyThaiNLP morpheme """ -from pythainlp.morpheme.word_formation import nighit \ No newline at end of file +from pythainlp.morpheme.word_formation import nighit diff --git a/pythainlp/morpheme/word_formation.py b/pythainlp/morpheme/word_formation.py index b98c58dd7..ec9d4c38b 100644 --- a/pythainlp/morpheme/word_formation.py +++ b/pythainlp/morpheme/word_formation.py @@ -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. @@ -29,7 +28,7 @@ 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) @@ -37,17 +36,17 @@ def nighit(w1: str,w2: str)->str: 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""" diff --git a/tests/test_morpheme.py b/tests/test_morpheme.py index 0bc609e49..604137367 100644 --- a/tests/test_morpheme.py +++ b/tests/test_morpheme.py @@ -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("สํ","โยค"), "สังโยค") \ No newline at end of file + self.assertEqual(nighit("สํ", "คีต"), "สังคีต") + self.assertEqual(nighit("สํ", "จร"), "สัญจร") + self.assertEqual(nighit("สํ", "ฐาน"), "สัณฐาน") + self.assertEqual(nighit("สํ", "นิษฐาน"), "สันนิษฐาน") + self.assertEqual(nighit("สํ", "ปทา"), "สัมปทา") + self.assertEqual(nighit("สํ", "โยค"), "สังโยค")