Skip to content

Commit

Permalink
Change None to List in pythainlp.corpus.find_synonyms
Browse files Browse the repository at this point in the history
  • Loading branch information
wannaphong committed Dec 12, 2023
1 parent e9a4862 commit 7f5251c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pythainlp/corpus/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ def thai_synonym() -> dict:
return thai_synonyms()


def find_synonyms(word) -> Union[List[str], None]:
def find_synonyms(word) -> List[str]:
"""
Find synonyms
:param str word: Thai word
:return: List synonyms of word or None if it isn't exist.
:rtype: Union[List[str], None]
:rtype: List[str]
:Example:
::
Expand All @@ -359,4 +359,4 @@ def find_synonyms(word) -> Union[List[str], None]:
if word in _temp["word"]:
_idx = _temp["word"].index(word)
return _temp["synonym"][_idx]
return None
return []
7 changes: 5 additions & 2 deletions tests/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,8 @@ def test_zip(self):
self.assertEqual(remove("test_zip"), True)

def test_find_synonyms(self):
self.assertIsInstance(find_synonyms("หมู"), list)
self.assertIsInstance(find_synonyms("1"), None)
self.assertEqual(
find_synonyms("หมู"),
['จรุก', 'วราห์', 'วราหะ', 'ศูกร', 'สุกร']
)
self.assertEqual(find_synonyms("1"), [])

0 comments on commit 7f5251c

Please sign in to comment.