From 4cb07f236aa071966d6eae98eb28238596cbffa8 Mon Sep 17 00:00:00 2001 From: HitBlast Date: Sun, 11 Aug 2024 22:22:53 +0600 Subject: [PATCH] new from_bijoy flag allows direct reversal from bijoy to english --- avro/main.py | 8 +++++++- tests/test_main.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/avro/main.py b/avro/main.py index 67c61c0..b9ad9c8 100755 --- a/avro/main.py +++ b/avro/main.py @@ -223,7 +223,7 @@ def to_unicode(*texts): # The reverse() function. # Used to parse from Bengali in Unicode to English Roman script. -def reverse(*texts: str, remap_words: bool = True) -> Union[str, List[str]]: +def reverse(*texts: str, from_bijoy: bool = False, remap_words: bool = True) -> Union[str, List[str]]: """ #### Reverses input text to Roman script typed in English. @@ -244,5 +244,11 @@ def reverse(*texts: str, remap_words: bool = True) -> Union[str, List[str]]: ``` """ + # Convert from Bijoy to Unicode if from_bijoy is True + if from_bijoy: + texts = to_unicode(*texts) + if isinstance(texts, str): + texts = (texts,) + output = _concurrency_helper(lambda text: _reverse_backend_ext(text, remap_words), texts) return output[0] if len(output) == 1 else output diff --git a/tests/test_main.py b/tests/test_main.py index f860b6d..3a6782c 100755 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -206,3 +206,6 @@ def test_full_sentences() -> NoReturn: "rohim, tomake korim dakche. ekhon ki rowna debe?", "rowna dile amake bole zew.", ] == avro.reverse("রহিম, তোমাকে করিম ডাকছে। এখন কি রওনা দেবে?", "রওনা দিলে আমাকে বলে যেও।") + + # Reverse (Bijoy Settings). + assert "ami banglar gan gai." == avro.reverse("Avwg evsjvi Mvb MvB|", from_bijoy=True)