Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make return values of laonlp.translate.word_dictionary consistent with type hint #15

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"])
Loading