Skip to content

Commit

Permalink
Make return values of laonlp.translate.word_dictionary consistent wit…
Browse files Browse the repository at this point in the history
…h type hint
  • Loading branch information
BLKSerene committed Oct 16, 2023
1 parent cf5cf85 commit dca6f6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions laonlp/translate/mopt_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def dictionary(word: str, src: str, target: str) -> list:
if src == "lao" and target == "eng":
_temp = mopt_dict.get_lao_eng()
if word not in list(_temp.keys()):
return None
return []
return _temp[word]
elif src == "eng" and target == "lao":
_temp = mopt_dict.get_eng_lao()
if word not in list(_temp.keys()):
return None
return []
return _temp[word]
else:
return word
return [word]
6 changes: 5 additions & 1 deletion tests/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

class TestTagPackage(unittest.TestCase):
def test_word_dictionary(self):
self.assertIsNotNone(word_dictionary("cat", "en", "lao"))
self.assertNotEqual(word_dictionary("cat", "eng", "lao"), ["cat"])
self.assertNotEqual(word_dictionary("ມັດ້າຣະ", "lao", "eng"), ["ມັດ້າຣະ"])
self.assertEqual(word_dictionary("nonexistent_word", "eng", "lao"), [])
self.assertEqual(word_dictionary("nonexistent_word", "lao", "eng"), [])
self.assertEqual(word_dictionary("nonexistent_word", "test", "test"), ["nonexistent_word"])

0 comments on commit dca6f6f

Please sign in to comment.