diff --git a/README.md b/README.md index 4b97c02..180308e 100644 --- a/README.md +++ b/README.md @@ -57,35 +57,48 @@ $ pip install avnie ## 🔖 Usage Guide -### 1. `parse()` -This is the most basic use case for avro.py, which includes parsing English Roman script to unicode Bengali: +This small tour guide will describe how you can use avro.py back and forth to operate (cutlery! lame joke?) on Bengali text: + +#### 1. `parse()` +Let's assume I want to parse some English text to Bengali, which is "ami banglay gan gai.", so in this case to convert it to Bengali, we can use this snippet: ```python -# Imports. +# Import the package. import avro -# Parsing some text. -output = avro.parse('ami banglay gan gai.') -print(output) +# Our dummy text. +dummy = 'ami banglay gan gai.' + +# Parsing the text. +avro_output = avro.parse(dummy) +print(output) # Output: আমি বাংলায় গান গাই। +``` + +#### 2. `parse(bijoy=True)` +Alternatively, I can also do it in Bijoy Keyboard format: + +```python +# Parsing in Bijoy. +bijoy_output = avro.parse(dummy, bijoy=True) # Output: Avwg evsjvh় Mvb MvB। ``` -### 2. `parse(bijoy=True)` -Alternatively, we can generate the same output, but in compliance with the Bijoy Keyboard format: +#### 3. `to_bijoy()` +Or, we can take the previous `avro_output` and convert it to Bijoy if we want to, like this: ```python -# Parsing some text in Bijoy! -output = avro.parse('tumi emon keno?', bijoy=True) +# Converting... +bijoy_output = avro.to_bijoy(avro_output) # Output: Avwg evsjvh় Mvb MvB। ``` -### 3. `to_bijoy()` -We can also use avro.py to convert existing unicode Bengali to its Bijoy Keyboard equivalent: +#### 4. `to_unicode()` +Conversely, we can convert Bijoy Keyboard text to unicode Bengali: ```python -# Converting some text. -bijoy_text = avro.to_bijoy('আমি বাংলায় গান গাই।') +# Converting back! +unicode_text = avro.to_unicode('Avwg evsjvh় Mvb MvB।') # Output: আমি বাংলায় গান গাই। ``` -### 4. `reverse()` +#### 5. `reverse()` Finally, you can reverse unicode Bengali to English as well (newly added). ```python diff --git a/avro/utils/processor.py b/avro/utils/processor.py index 0444f81..fe7ab6b 100644 --- a/avro/utils/processor.py +++ b/avro/utils/processor.py @@ -323,23 +323,22 @@ def rearrange_bijoy_text(text: str) -> str: j += 1 else: break - temp = text[: i - j] + text[i] + text[i + 1] + text[i - j : i] + text[i + 2 :] - text = temp + text = text[: i - j] + text[i] + text[i + 1] + text[i - j : i] + text[i + 2 :] i += 1 continue if i < len(text) - 1 and validate.is_bangla_prekar(text[i]) and text[i + 1] != " ": j = 1 while validate.is_bangla_banjonborno(text[i + j]): - if validate.is_bangla_halant(text[i + j + 1]): + if validate.is_bangla_halant((part := text[i + j + 1])): j += 2 else: break temp = text[:i] + text[i + 1 : i + j + 1] - if text[i] == "ে" and text[i + j + 1] == "া": + if text[i] == "ে" and part == "া": temp += "ো" l = 1 - elif text[i] == "ে" and text[i + j + 1] == "ৗ": + elif text[i] == "ে" and part == "ৗ": temp += "ৌ" l = 1 else: