Skip to content

Commit

Permalink
added examples directory for demos
Browse files Browse the repository at this point in the history
  • Loading branch information
hitblast committed Aug 8, 2024
1 parent 20f7630 commit a1a9b63
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ $ pip install avnie

## 🔖 Usage Guide

This small tour guide will describe how you can use avro.py back and forth to operate (cutlery!) on Bengali text:
This small tour guide will describe how you can use avro.py back and forth to operate (cutlery!) on Bengali text. You can also check the [examples](https://github.com/hitblast/avro.py/tree/main/examples) directory for checking [this whole snippet](https://github.com/hitblast/avro.py/blob/main/examples/simple.py) in action, as well as other use cases.

### 1. `parse()`
#### 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
Expand All @@ -74,31 +74,31 @@ avro_output = avro.parse(dummy)
print(output) # Output: আমি বাংলায় গান গাই।
```

### 2. `parse(bijoy=True)`
#### 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।
```

### 3. `to_bijoy()`
#### 3. `to_bijoy()`
Or, we can take the previous `avro_output` and convert it to Bijoy if we want to, like this:

```python
# Converting to Bijoy.
bijoy_text = avro.to_bijoy(avro_output)
bijoy_text = avro.to_bijoy(avro_output) # Output: Avwg evsjvh় Mvb MvB।
```

### 4. `to_unicode()`
#### 4. `to_unicode()`
Conversely, we can convert the Bijoy text we got just now and convert it back to Unicode Bengali:

```python
# Converting back!
unicode_text = avro.to_unicode(bijoy_text)
unicode_text = avro.to_unicode(bijoy_text) # Output: আমি বাংলায় গান গাই।
```

### 4. `reverse()`
#### 4. `reverse()`
Finally, we can just reverse back to the original text we passed as input in the first place:

```python
Expand Down
28 changes: 28 additions & 0 deletions examples/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Import the package.
import avro

# Let's assume we'd like to convert "amar sOnar bangla" to Unicode.
dummy_text = "amar sOnar bangla"
print("Original English Text:", dummy_text)

# Parse the text to Avro.
parsed_text = avro.parse(dummy_text)
print("Parsed Unicode Output:", parsed_text)

# We can parse it directly to Bijoy, or use the to_bijoy function to convert it.
# Both should return the same result.
bijoy_text_direct = avro.parse(dummy_text, bijoy=True)
bijoy_text_function = avro.to_bijoy(parsed_text)

# Print the Bijoy text.
if bijoy_text_direct == bijoy_text_function:
print(f"Bijoy Output: {bijoy_text_direct}")

# Now, we can return the Bijoy text to Unicode since we'd like the original output (assuming).
# This should be the same as the old parsed_text variable.
unicode_text = avro.to_unicode(bijoy_text_direct)
print("Reversed Unicode Output:", unicode_text)

# Finally, we can reverse the Bengali text, back to English!
reversed = avro.reverse(unicode_text)
print("Reversed English Output:", reversed)

0 comments on commit a1a9b63

Please sign in to comment.