Skip to content

Commit

Permalink
Update 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 a5aa12c commit cf6647e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pythainlp/corpus/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ def find_synonyms(word: str) -> List[str]:
# output: ['จรุก', 'วราห์', 'วราหะ', 'ศูกร', 'สุกร']
"""
synonyms = thai_synonyms() # get a dictionary of {word, synonym}
list_synonym = []

if word in synonyms["word"]:
# returns the position of the first occurrence of the word
idx = synonyms["word"].index(word)
return synonyms["synonym"][idx]
for idx, words in enumerate(synonyms["word"]):
if word in words:
list_synonym.extend(synonyms["synonym"][idx])

return []
return sorted(list(set(list_synonym)))
2 changes: 1 addition & 1 deletion tests/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ def test_zip(self):
def test_find_synonyms(self):
self.assertEqual(
find_synonyms("หมู"),
['จรุก', 'วราห์', 'วราหะ', 'ศูกร', 'สุกร']
['จรุก', 'วราหะ', 'วราห์', 'ศูกร', 'สุกร']
)
self.assertEqual(find_synonyms("1"), [])

0 comments on commit cf6647e

Please sign in to comment.