Code Monkey home page Code Monkey logo

pybangla's Introduction

PYBANGLA is a python3 package for Bangla Number, DateTime and Text Normalizer and Date Extraction. This package can be used to Normalize the text number and date (ex: number to text vice versa). This framework also can be used Django, Flask, FastAPI, and others. PYBANGLA module supported operating systems Linux/Unix, Mac OS and Windows. Available Features

Features available in PYBANGLA:

  1. Text Normalization
  2. Number Conversion
  3. Date Format
  4. Emoji Removal
  5. Months, Weekdays, Seasons

[N.B: Here listed Every Feature has implemented Text Normalization as well as Isolated Uses feature]

Installation

The easiest way to install pybangla is to use pip:

pip install pybangla

Usage

It supports converting Bangla abbreviations, symbols, and currencies to Bangla textual format.

Example:

import pybangla
nrml = pybangla.Normalizer()
text = "রাহিম ক্লাস ওয়ান এ ১ম, এন্ড বাসার ক্লাস এ ৩৩ তম, সে জন্য ২০৩০ শতাব্দীতে ¥২০৩০.১২৩৪ দিতে হয়েছে"
text = nrml.text_normalizer(text)

print(text)

# output:
'রাহিম ক্লাস ওয়ান এ প্রথম, এন্ড বাসার ক্লাস এ তেত্রিশতম, সে জন্য দুই হাজার ত্রিশ শতাব্দীতে দুই হাজার ত্রিশ দশমিক এক দুই তিন চার ইয়েন দিতে হয়েছে'

Normalizer more information or example check the link

Example:

import pybangla
nrml = pybangla.Normalizer()
text = "আমাকে এক লক্ষ দুই হাজার এক টাকা দেয় এন্ড তুমি বিশ হাজার টাকা নিও এন্ড এক লক্ষ চার হাজার দুইশ এক টাকা এক ডবল দুই"
text = nrml.word2number(text)
print(text)
#output:
'আমাকে 102001 টাকা দেয় এন্ড তুমি 20000 টাকা নিও এন্ড 104201 টাকা 122 '

Number conversion more information or examples check the link

Example:

import pybangla
nrml = pybangla.Normalizer()
date = "০১-এপ্রিল/২০২৩"
date = nrml.date_format(date, language="bn")
print(date)
#output:


{'date': '০১', 'month': '৪', 'year': '২০২৩', 'txt_date': 'এক', 'txt_month': 'এপ্রিল', 'txt_year': 'দুই হাজার তেইশ', 'weekday': 'শনিবার', 'ls_month': 'শ্রাবণ', 'seasons': 'বর্ষা'}

Date Format for more information or example check the link

text = 'দয়া করে পবিত্র কুরআনুল কারিম বলেন,,,,পবিত্র কথাটা অবশ্যই বলবেন,,, প্লিজ 😢😥🙏🙏🙏'
text = nrml.remove_emoji(text)
print(f"{text}")

#output:
দয়া করে পবিত্র কুরআনুল কারিম বলেন,,,,পবিত্র কথাটা অবশ্যই বলবেন,,, প্লিজ

For Emoji Removal more information or example check the link

import pybangla
nrml = pybangla.Normalizer()
today = nrml.today()
print(today)

# Output: 
{'date': '৩০', 'month': 'এপ্রিল', 'year': '২০২৪', 'txt_date': 'ত্রিশ', 'txt_year': 'দুই হাজার চব্বিশ', 'weekday': 'মঙ্গলবার', 'ls_month': 'শ্রাবণ', 'seasons': 'বর্ষা'}

Today, Months, Weekdays, Seasons more information or examples check the link

New Feature

(UPDATE TEXT NORMALIZATION) It supports year conversion like

  • "১৯৮৭-র" to "উনিশশো সাতাশি এর"
  • "১৯৯৫ সালে" to "উনিশশো পঁচানব্বই সালে"
  • "২০২৬-২৭" to "দুই হাজার ছাব্বিশ সাতাশ"

Now it also has the abbreviation for units of temperature

  • "৪৪°F" to "চুয়াল্লিশ ডিগ্রী ফারেনহাইট"
  • "৪৪°C" to "চুয়াল্লিশ ডিগ্রী সেলসিয়াস"

Phone Number Processing

  • "01790-540211" to "জিরো ওয়ান সেভেন নাইন জিরো ফাইভ ফোর জিরো টু ডাবল ওয়ান"
import pybangla
nrml = pybangla.Normalizer()
number_string = nrml.process_phone_number("01790-540211")
Output:
জিরো ওয়ান সেভেন নাইন জিরো ফাইভ ফোর জিরো টু ডাবল ওয়ান

Compare Two String Changes

import pybangla
nrml = pybangla.Normalizer()

input1 = "১৯৯৬সালের ৬ সেপ্টেম্বররণ ভ্রমণ পরিকল্পনা করছি ২০৩০সালের ৬সেপ্টেম্বর"

input2 = "উনিশশো ছিয়ানব্বই সালের ছয় সেপ্টেম্বর রণ ভ্রমণ পরিকল্পনা করছি দুই হাজার ত্রিশ সালের ছয় সেপ্টেম্বর"

print(nrml.text_diff(input1, input2))

#Output: 

(
    ['১৯৯৬সালের ৬', 'সেপ্টেম্বররণ', '২০৩০সালের', '৬সেপ্টেম্বর'], 
    ['উনিশশো ছিয়ানব্বই সালের ছয়', 'সেপ্টেম্বর রণ', 'দুই হাজার ত্রিশ সালের ছয়', 'সেপ্টেম্বর']
)

Next Upcoming Features

  1. Bangla lemmatization and stemming algorithm
  2. Bangla Tokenizer

Contact

If you have any suggestions: Email: [email protected]

Contributor

@misc{pybangla,
  title={PYBANGLA module used for normalize textual format like text to number and number to text},
  author={Md Saiful Islam, Hassan Ali Emon,  HM-badhon, Sagor Sarker, ud0y},
  howpublished={},
  year={2024}
}

If you face any problems feel free to open an issue.

pybangla's People

Contributors

hassanaliemon avatar hm-badhon avatar saiful9379 avatar ud0y avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pybangla's Issues

Not giving desired normalized text as output

My Code

import pybangla
nrml = pybangla.Normalizer()
text = "৫ বছরে নন-ক্যাডার পদে ৭৪৪৭ জনকে নিয়োগের সুপারিশ করা হয়েছে"
text = nrml.text_normalizer(text)

print(text)

Output

পাঁচ বছরে নন-ক্যাডার পদে সাত হাজার চার শত সাতচল্লিশ৪৪সাত হাজার চার শত সাতচল্লিশ জনকে নিয়োগের সুপারিশ করা হয়েছে

Typo error "soved date format issue" and requesting code modification on my main.py with pybangla

First, thanks for building the pybangla package.

A typo error on 05f9e89 "soved date format issue"

And a request, not a python coder. Can you please modify the code below so it recognizes the Bengali years?



import torch
from TTS.api import TTS
import gradio as gr

device = "cuda" if torch.cuda.is_available() else "cpu"

def generate_audio(text="তুমি কেমন আছো?"):
    tts = TTS(model_name='tts_models/bn/custom/vits-male').to(device)
    tts.tts_to_file(text=text, file_path="outputs/output.wav")
    return "outputs/output.wav"

demo = gr.Interface(
    fn=generate_audio,
    inputs=[gr.Text(label="Text"),],
    outputs=[gr.Audio(label="Audio"),],
    )


demo.launch()

coqui-ai / TTS did provide me some code with mine but it don't prounice bengali year as "১৯৮৭-র" to "উনিশশো সাতাশি এর" rather just plain number in bengali.

Here is th link

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.