def test_sentence(self): self.assertEqual( avro.parse("ami banglay gan gai"), utf("আমি বাংলায় গান গাই")) self.assertEqual( avro.parse( "amader valObasa hoye gel ghas, kheye gel goru ar diye gelo ba^sh"), utf("আমাদের ভালোবাসা হয়ে গেল ঘাস, খেয়ে গেল গরু আর দিয়ে গেল বাঁশ"))
def test_sentence(self): self.assertEqual(avro.parse("ami banglay gan gai"), utf("আমি বাংলায় গান গাই")) self.assertEqual( avro.parse( "amader valObasa hoye gel ghas, kheye gel goru ar diye gelo ba^sh" ), utf("আমাদের ভালোবাসা হয়ে গেল ঘাস, খেয়ে গেল গরু আর দিয়ে গেল বাঁশ"))
def test_non_ascii(self): """Test parser response for non ascii characters Parser should return any non-ascii characters passed to it """ self.assertEquals(utf('ব'), avro.parse('ব')) self.assertEquals(utf('অভ্র'), avro.parse('অভ্র')) # mixed string self.assertEquals(utf('বআবা গো'), avro.parse('বaba gO')) self.assertEquals(utf('আমি বাংলায় গান গাই'), avro.parse('aমি বাংলায় gaন গাi'))
def test_non_ascii(self): """Test parser response for non ascii characters Parser should return any non-ascii characters passed to it """ self.assertEqual(utf('ব'), avro.parse('ব')) self.assertEqual(utf('অভ্র'), avro.parse('অভ্র')) # mixed string self.assertEqual(utf('বআবা গো'), avro.parse('বaba gO')) self.assertEqual(utf('আমি বাংলায় গান গাই'), avro.parse('aমি বাংলায় gaন গাi'))
def test_patterns_without_rules_not_from_config(self): """Tests all patterns not from config that don't have rules This test is done in addition to test_patterns_without_rules_from_config() to ensure that text passed manually to avro.parse are properly parsed when they don't exact match a pattern that has no rules specified. """ # Test some conjunctions self.assertEquals(utf("ভ্ল"), avro.parse("bhl")) self.assertEquals(utf("ব্ধ"), avro.parse("bdh")) self.assertEquals(utf("ব্ধ"), avro.parse("bdh")) self.assertEquals(utf("ড্ড"), avro.parse("DD")) # stunned stork! self.assertEquals(utf("স্তব্ধ বক"), avro.parse("stbdh bk"))
def onPressHotkey(self, event) -> None: self.bengali = parse(self.current) #parsed value will be stored in # fire backspace to delete previous word # then place the bengali word followed by triggered key replace: str = '\b' * (len(self.current) + 1) + self.bengali + CODE_DICT[event.name] self.previous = self.current # store the current value to previous for `smart backspace` self.current = "" write(replace) # write the string
def get_book_info(query, method, price_from=0, price_to=50000, rating_from=0, rating_to=5, sort="TOTAL_SOLD DESC", book_name="", author_name=""): if method == "UPDATE": quercmd = "SELECT B.BOOK_ID,B.BOOK_NAME,A.AUTHOR_NAME,B.PRICE,B.RATINGS,C.PUBLISHER_NAME, B.DISCOUNT, B.BOOK_EDITION, B.PAGES, B.BOOK_GENRE, B.SUMMARY FROM BOOK B JOIN AUTHOR A USING(AUTHOR_ID) JOIN PUBLISHER C USING(PUBLISHER_ID) WHERE B.BOOK_ID = " + str( query) elif is_banglish(query): # print(avro.parse(query)) query = avro.parse(query) # print(sort) if method == "GET": quercmd = "SELECT B.BOOK_ID,B.BOOK_NAME,A.AUTHOR_NAME,B.PRICE, B.BOOK_GENRE, B.BOOK_EDITION, B.RATINGS, B.NO_OF_RATINGS, C.PUBLISHER_NAME, B.DISCOUNT, B.COUNTRY, B.LANGUAGE, B.SUMMARY, B.ISBN, B.PAGES, B.TOTAL_SOLD FROM BOOK B JOIN AUTHOR A USING(AUTHOR_ID) JOIN PUBLISHER C USING(PUBLISHER_ID) ORDER BY B.BOOK_ID" elif method == "POST": quercmd = "SELECT B.BOOK_ID,B.BOOK_NAME,A.AUTHOR_NAME,B.PRICE, B.BOOK_GENRE, B.BOOK_EDITION, B.RATINGS, B.NO_OF_RATINGS, C.PUBLISHER_NAME, B.DISCOUNT, B.COUNTRY, B.LANGUAGE, B.SUMMARY, B.ISBN, B.PAGES, B.TOTAL_SOLD FROM BOOK B JOIN AUTHOR A USING(AUTHOR_ID) JOIN PUBLISHER C USING(PUBLISHER_ID) WHERE ((B.PRICE >= " + str( price_from ) + " AND B.PRICE <= " + str(price_to) + " AND B.RATINGS >= " + str( rating_from ) + " AND B.RATINGS <= " + str( rating_to ) + ") AND (B.BOOK_NAME LIKE '%" + book_name + "%') AND (A.AUTHOR_NAME LIKE '%" + author_name + "%') AND (C.PUBLISHER_NAME LIKE '%" + query + "%') AND (B.BOOK_GENRE LIKE '%" + query + "%')) ORDER BY B." + sort db_cursor = conn.cursor() db_cursor.execute(quercmd) search_results = db_cursor.fetchall() li = [] for row in search_results: l2 = [] for item in row: if item == None: item = "" l2.append(item) l2[1] = slice_name(l2[1]) if check_if_image_exists(l2[0]): l2.append(l2[0]) # print(l2) else: l2.append("book_image") # print(l2) li.append(l2) return li
def getSenti(self, input, models): sentence, phase = input if phase is PHASE.BANGLISH: print("Banglish is :", sentence) sentence = avro.parse(sentence) phase = PHASE.BANGLA print("Bangla is :", sentence) if phase is PHASE.BANGLA: # 1 : TextBlob # 2 : googletrans # 3 : translate use_api = self.language.currentIndex() if use_api == 2: print("Using Textblob translator") sentence = str(TextBlob(sentence).translate(to='en')) elif use_api == 1: print("Using googletrans translator") from googletrans import Translator translator = Translator() sentence = str(translator.translate(sentence)) elif use_api == 0: print("Using translate translator") from translate import Translator translator = Translator(to_lang="en", from_lang="bn") sentence = translator.translate(sentence) phase = PHASE.ENGLISH print("English is :", sentence) results = [] for uniModel in models: model = uniModel(sentence) result = { 'name': model.name, 'result': model.result(), 'conclusion': model.conclusion() } results.append(result) return results
def get_book_info(query, method, price_from=0, price_to=50000, rating_from=0, rating_to=5, sort="TOTAL_SOLD DESC"): if is_banglish(query): # print(avro.parse(query)) query = avro.parse(query) # print(sort) if method == "GET": quercmd = "SELECT B.BOOK_ID,B.BOOK_NAME,A.AUTHOR_NAME,B.PRICE,B.RATINGS,C.PUBLISHER_NAME, B.DISCOUNT FROM BOOK B JOIN AUTHOR A USING(AUTHOR_ID) JOIN PUBLISHER C USING(PUBLISHER_ID) WHERE ((B.BOOK_NAME LIKE '%" + query + "%') OR (A.AUTHOR_NAME LIKE '%" + query + "%') OR (C.PUBLISHER_NAME LIKE '%" + query + "%') OR (B.BOOK_GENRE LIKE '%" + query + "%')) ORDER BY B.TOTAL_SOLD DESC" elif method == "POST": quercmd = "SELECT B.BOOK_ID,B.BOOK_NAME,A.AUTHOR_NAME,B.PRICE,B.RATINGS,C.PUBLISHER_NAME, B.DISCOUNT FROM BOOK B JOIN AUTHOR A USING(AUTHOR_ID) JOIN PUBLISHER C USING(PUBLISHER_ID) WHERE ((B.PRICE >= " + str( price_from ) + " AND B.PRICE <= " + str(price_to) + " AND B.RATINGS >= " + str( rating_from ) + " AND B.RATINGS <= " + str( rating_to ) + ") AND ((B.BOOK_NAME LIKE '%" + query + "%') OR (A.AUTHOR_NAME LIKE '%" + query + "%') OR (C.PUBLISHER_NAME LIKE '%" + query + "%')OR (B.BOOK_GENRE LIKE '%" + query + "%'))) ORDER BY B." + sort # print(quercmd) # print(query) db_cursor = conn.cursor() db_cursor.execute(quercmd) search_results = db_cursor.fetchall() li = [] for row in search_results: l2 = [] for item in row: l2.append(item) l2[1] = slice_name(l2[1]) if check_if_image_exists(l2[0]): l2.append(l2[0]) # print(l2) else: l2.append("book_image") # print(l2) li.append(l2) return li
def test_words_with_punctuations(self): """Test parsing of words with punctuations""" self.assertEqual(utf('আয়রে,'), avro.parse('ayre,')) self.assertEqual(utf('ভোলা'), avro.parse('bhOla')) self.assertEqual(utf('খেয়াল'), avro.parse('kheyal')) self.assertEqual(utf('খোলা'), avro.parse('khOla'))
def test_sentences(self): """Test parsing of sentences""" self.assertEquals(utf('আমি বাংলায় গান গাই'), avro.parse('ami banglay gan gai'))
def test_patterns_without_rules_from_config(self): """Tests all patterns from config that don't have rules""" for pattern in AVRO_DICT['data']['patterns']: if 'rules' not in pattern: self.assertEquals(pattern['replace'], avro.parse(pattern['find']))
def test_patterns_punctuations(self): """Tests patterns - punctuations""" # Test some punctuations self.assertEqual(utf("।"), avro.parse(".")) self.assertEqual(utf("।।"), avro.parse("..")) self.assertEqual(utf("..."), avro.parse("..."))
def test_words_with_punctuations(self): """Test parsing of words with punctuations""" self.assertEquals(utf('আয়রে,'), avro.parse('ayre,')) self.assertEquals(utf('ভোলা'), avro.parse('bhOla')) self.assertEquals(utf('খেয়াল'), avro.parse('kheyal')) self.assertEquals(utf('খোলা'), avro.parse('khOla'))
def test_patterns_with_rules_svaravarna(self): """Test patterns - with rules - svaravarna""" # Test some numbers self.assertEquals(utf("অ"), avro.parse("o")) self.assertEquals(utf("আ"), avro.parse("a")) self.assertEquals(utf("ই"), avro.parse("i")) self.assertEquals(utf("ঈ"), avro.parse("I")) self.assertEquals(utf("উ"), avro.parse("u")) self.assertEquals(utf("উ"), avro.parse("oo")) self.assertEquals(utf("ঊ"), avro.parse("U")) self.assertEquals(utf("এ"), avro.parse("e")) self.assertEquals(utf("ঐ"), avro.parse("OI")) self.assertEquals(utf("ও"), avro.parse("O")) self.assertEquals(utf("ঔ"), avro.parse("OU"))
import wget wget.download('http://0xhosts.com/words.txt') wget.download('http://0xhosts.com/translate.txt') my_input=str(raw_input("Enter Your Sentence:")) from pyavrophonetic import avro import codecs spit_it=my_input.split() check=spit_it print check print "Total Words",len(check) if len(check)==4: if check[0] and check[1] and check[2] and check[3] in open("words.txt").read().split(): print ("False") else: s1=avro.parse(check[0]) s2=avro.parse(check[1]) s3=avro.parse(check[2]) s4=avro.parse(check[3]) p=codecs.open('translate.txt','r+','utf-8') p.write("Translation : %s %s %s %s" %(s1,s2,s3,s4)) p.close() print("Translation Completed.Saved to translate.txt") if s1 and s2 and s3 and s4 in codecs.open('words.txt','r','utf-8').read().split(): print "Banglish Style" else: print "Murad Takla Style" else: print ("Sorry max/min 4 words")
def test_basic(self): self.assertEqual(avro.parse("bhl"), utf("ভ্ল")) self.assertEqual(avro.parse("bj"), utf("ব্জ")) self.assertEqual(avro.parse("bd"), utf("ব্দ")) self.assertEqual(avro.parse("bb"), utf("ব্ব")) self.assertEqual(avro.parse("bl"), utf("ব্ল")) self.assertEqual(avro.parse("bh"), utf("ভ")) self.assertEqual(avro.parse("vl"), utf("ভ্ল")) self.assertEqual(avro.parse("b"), utf("ব")) self.assertEqual(avro.parse("v"), utf("ভ")) self.assertEqual(avro.parse("cNG"), utf("চ্ঞ")) self.assertEqual(avro.parse("cch"), utf("চ্ছ")) self.assertEqual(avro.parse("cc"), utf("চ্চ")) self.assertEqual(avro.parse("ch"), utf("ছ")) self.assertEqual(avro.parse("c"), utf("চ")) self.assertEqual(avro.parse("dhn"), utf("ধ্ন")) self.assertEqual(avro.parse("dhm"), utf("ধ্ম")) self.assertEqual(avro.parse("dgh"), utf("দ্ঘ")) self.assertEqual(avro.parse("ddh"), utf("দ্ধ")) self.assertEqual(avro.parse("dbh"), utf("দ্ভ")) self.assertEqual(avro.parse("dv"), utf("দ্ভ")) self.assertEqual(avro.parse("dm"), utf("দ্ম")) self.assertEqual(avro.parse("DD"), utf("ড্ড")) self.assertEqual(avro.parse("Dh"), utf("ঢ")) self.assertEqual(avro.parse("dh"), utf("ধ")) self.assertEqual(avro.parse("dg"), utf("দ্গ")) self.assertEqual(avro.parse("dd"), utf("দ্দ")) self.assertEqual(avro.parse("D"), utf("ড")) self.assertEqual(avro.parse("d"), utf("দ")) self.assertEqual(avro.parse("..."), utf("...")) self.assertEqual(avro.parse(".`"), utf(".")) self.assertEqual(avro.parse(".."), utf("।।")) self.assertEqual(avro.parse("."), utf("।")) self.assertEqual(avro.parse("ghn"), utf("ঘ্ন")) self.assertEqual(avro.parse("Ghn"), utf("ঘ্ন")) self.assertEqual(avro.parse("gdh"), utf("গ্ধ")) self.assertEqual(avro.parse("gN"), utf("গ্ণ")) self.assertEqual(avro.parse("GN"), utf("গ্ণ")) self.assertEqual(avro.parse("gn"), utf("গ্ন")) self.assertEqual(avro.parse("gm"), utf("গ্ম")) self.assertEqual(avro.parse("Gm"), utf("গ্ম")) self.assertEqual(avro.parse("gl"), utf("গ্ল")) self.assertEqual(avro.parse("Gl"), utf("গ্ল")) self.assertEqual(avro.parse("gg"), utf("জ্ঞ")) self.assertEqual(avro.parse("GG"), utf("জ্ঞ")) self.assertEqual(avro.parse("Gg"), utf("জ্ঞ")) self.assertEqual(avro.parse("gG"), utf("জ্ঞ")) self.assertEqual(avro.parse("gh"), utf("ঘ")) self.assertEqual(avro.parse("Gh"), utf("ঘ")) self.assertEqual(avro.parse("g"), utf("গ")) self.assertEqual(avro.parse("hN"), utf("হ্ণ")) self.assertEqual(avro.parse("hn"), utf("হ্ন")) self.assertEqual(avro.parse("hm"), utf("হ্ম")) self.assertEqual(avro.parse("hl"), utf("হ্ল")) self.assertEqual(avro.parse("h"), utf("হ")) self.assertEqual(avro.parse("jjh"), utf("জ্ঝ")) self.assertEqual(avro.parse("jNG"), utf("জ্ঞ")) self.assertEqual(avro.parse("jh"), utf("ঝ")) self.assertEqual(avro.parse("jj"), utf("জ্জ")) self.assertEqual(avro.parse("j"), utf("জ")) self.assertEqual(avro.parse("J"), utf("জ")) self.assertEqual(avro.parse("kkhN"), utf("ক্ষ্ণ")) self.assertEqual(avro.parse("kShN"), utf("ক্ষ্ণ")) self.assertEqual(avro.parse("kkhm"), utf("ক্ষ্ম")) self.assertEqual(avro.parse("kShm"), utf("ক্ষ্ম")) self.assertEqual(avro.parse("kxN"), utf("ক্ষ্ণ")) self.assertEqual(avro.parse("kxm"), utf("ক্ষ্ম")) self.assertEqual(avro.parse("kkh"), utf("ক্ষ")) self.assertEqual(avro.parse("kSh"), utf("ক্ষ")) self.assertEqual(avro.parse("ksh"), utf("কশ")) self.assertEqual(avro.parse("kx"), utf("ক্ষ")) self.assertEqual(avro.parse("kk"), utf("ক্ক")) self.assertEqual(avro.parse("kT"), utf("ক্ট")) self.assertEqual(avro.parse("kt"), utf("ক্ত")) self.assertEqual(avro.parse("kl"), utf("ক্ল")) self.assertEqual(avro.parse("ks"), utf("ক্স")) self.assertEqual(avro.parse("kh"), utf("খ")) self.assertEqual(avro.parse("k"), utf("ক")) self.assertEqual(avro.parse("lbh"), utf("ল্ভ")) self.assertEqual(avro.parse("ldh"), utf("ল্ধ")) self.assertEqual(avro.parse("lkh"), utf("লখ")) self.assertEqual(avro.parse("lgh"), utf("লঘ")) self.assertEqual(avro.parse("lph"), utf("লফ")) self.assertEqual(avro.parse("lk"), utf("ল্ক")) self.assertEqual(avro.parse("lg"), utf("ল্গ")) self.assertEqual(avro.parse("lT"), utf("ল্ট")) self.assertEqual(avro.parse("lD"), utf("ল্ড")) self.assertEqual(avro.parse("lp"), utf("ল্প")) self.assertEqual(avro.parse("lv"), utf("ল্ভ")) self.assertEqual(avro.parse("lm"), utf("ল্ম")) self.assertEqual(avro.parse("ll"), utf("ল্ল")) self.assertEqual(avro.parse("lb"), utf("ল্ব")) self.assertEqual(avro.parse("l"), utf("ল")) self.assertEqual(avro.parse("mth"), utf("ম্থ")) self.assertEqual(avro.parse("mph"), utf("ম্ফ")) self.assertEqual(avro.parse("mbh"), utf("ম্ভ")) self.assertEqual(avro.parse("mpl"), utf("মপ্ল")) self.assertEqual(avro.parse("mn"), utf("ম্ন")) self.assertEqual(avro.parse("mp"), utf("ম্প")) self.assertEqual(avro.parse("mv"), utf("ম্ভ")) self.assertEqual(avro.parse("mm"), utf("ম্ম")) self.assertEqual(avro.parse("ml"), utf("ম্ল")) self.assertEqual(avro.parse("mb"), utf("ম্ব")) self.assertEqual(avro.parse("mf"), utf("ম্ফ")) self.assertEqual(avro.parse("m"), utf("ম")) self.assertEqual(avro.parse("0"), utf("০")) self.assertEqual(avro.parse("1"), utf("১")) self.assertEqual(avro.parse("2"), utf("২")) self.assertEqual(avro.parse("3"), utf("৩")) self.assertEqual(avro.parse("4"), utf("৪")) self.assertEqual(avro.parse("5"), utf("৫")) self.assertEqual(avro.parse("6"), utf("৬")) self.assertEqual(avro.parse("7"), utf("৭")) self.assertEqual(avro.parse("8"), utf("৮")) self.assertEqual(avro.parse("9"), utf("৯")) self.assertEqual(avro.parse("NgkSh"), utf("ঙ্ক্ষ")) self.assertEqual(avro.parse("Ngkkh"), utf("ঙ্ক্ষ")) self.assertEqual(avro.parse("NGch"), utf("ঞ্ছ")) self.assertEqual(avro.parse("Nggh"), utf("ঙ্ঘ")) self.assertEqual(avro.parse("Ngkh"), utf("ঙ্খ")) self.assertEqual(avro.parse("NGjh"), utf("ঞ্ঝ")) self.assertEqual(avro.parse("ngOU"), utf("ঙ্গৌ")) self.assertEqual(avro.parse("ngOI"), utf("ঙ্গৈ")) self.assertEqual(avro.parse("Ngkx"), utf("ঙ্ক্ষ")) self.assertEqual(avro.parse("NGc"), utf("ঞ্চ")) self.assertEqual(avro.parse("nch"), utf("ঞ্ছ")) self.assertEqual(avro.parse("njh"), utf("ঞ্ঝ")) self.assertEqual(avro.parse("ngh"), utf("ঙ্ঘ")) self.assertEqual(avro.parse("Ngk"), utf("ঙ্ক")) self.assertEqual(avro.parse("Ngx"), utf("ঙ্ষ")) self.assertEqual(avro.parse("Ngg"), utf("ঙ্গ")) self.assertEqual(avro.parse("Ngm"), utf("ঙ্ম")) self.assertEqual(avro.parse("NGj"), utf("ঞ্জ")) self.assertEqual(avro.parse("ndh"), utf("ন্ধ")) self.assertEqual(avro.parse("nTh"), utf("ন্ঠ")) self.assertEqual(avro.parse("NTh"), utf("ণ্ঠ")) self.assertEqual(avro.parse("nth"), utf("ন্থ")) self.assertEqual(avro.parse("nkh"), utf("ঙ্খ")) self.assertEqual(avro.parse("ngo"), utf("ঙ্গ")) self.assertEqual(avro.parse("nga"), utf("ঙ্গা")) self.assertEqual(avro.parse("ngi"), utf("ঙ্গি")) self.assertEqual(avro.parse("ngI"), utf("ঙ্গী")) self.assertEqual(avro.parse("ngu"), utf("ঙ্গু")) self.assertEqual(avro.parse("ngU"), utf("ঙ্গূ")) self.assertEqual(avro.parse("nge"), utf("ঙ্গে")) self.assertEqual(avro.parse("ngO"), utf("ঙ্গো")) self.assertEqual(avro.parse("NDh"), utf("ণ্ঢ")) self.assertEqual(avro.parse("nsh"), utf("নশ")) self.assertEqual(avro.parse("Ngr"), utf("ঙর")) self.assertEqual(avro.parse("NGr"), utf("ঞর")) self.assertEqual(avro.parse("ngr"), utf("ংর")) self.assertEqual(avro.parse("nj"), utf("ঞ্জ")) self.assertEqual(avro.parse("Ng"), utf("ঙ")) self.assertEqual(avro.parse("NG"), utf("ঞ")) self.assertEqual(avro.parse("nk"), utf("ঙ্ক")) self.assertEqual(avro.parse("ng"), utf("ং")) self.assertEqual(avro.parse("nn"), utf("ন্ন")) self.assertEqual(avro.parse("NN"), utf("ণ্ণ")) self.assertEqual(avro.parse("Nn"), utf("ণ্ন")) self.assertEqual(avro.parse("nm"), utf("ন্ম")) self.assertEqual(avro.parse("Nm"), utf("ণ্ম")) self.assertEqual(avro.parse("nd"), utf("ন্দ")) self.assertEqual(avro.parse("nT"), utf("ন্ট")) self.assertEqual(avro.parse("NT"), utf("ণ্ট")) self.assertEqual(avro.parse("nD"), utf("ন্ড")) self.assertEqual(avro.parse("ND"), utf("ণ্ড")) self.assertEqual(avro.parse("nt"), utf("ন্ত")) self.assertEqual(avro.parse("ns"), utf("ন্স")) self.assertEqual(avro.parse("nc"), utf("ঞ্চ")) self.assertEqual(avro.parse("n"), utf("ন")) self.assertEqual(avro.parse("N"), utf("ণ")) self.assertEqual(avro.parse("OI`"), utf("ৈ")) self.assertEqual(avro.parse("OU`"), utf("ৌ")) self.assertEqual(avro.parse("O`"), utf("ো")) self.assertEqual(avro.parse("OI"), utf("ঐ")) self.assertEqual(avro.parse("kOI"), utf("কৈ")) self.assertEqual(avro.parse(" OI"), utf(" ঐ")) self.assertEqual(avro.parse("(OI"), utf("(ঐ")) self.assertEqual(avro.parse(".OI"), utf("।ঐ")) self.assertEqual(avro.parse("OU"), utf("ঔ")) self.assertEqual(avro.parse("kOU"), utf("কৌ")) self.assertEqual(avro.parse(" OU"), utf(" ঔ")) self.assertEqual(avro.parse("-OU"), utf("-ঔ")) self.assertEqual(avro.parse(",,OU"), utf("্ঔ")) self.assertEqual(avro.parse("O"), utf("ও")) self.assertEqual(avro.parse("pO"), utf("পো")) self.assertEqual(avro.parse(" O"), utf(" ও")) self.assertEqual(avro.parse("iO"), utf("ইও")) self.assertEqual(avro.parse("`O"), utf("ও")) self.assertEqual(avro.parse("phl"), utf("ফ্ল")) self.assertEqual(avro.parse("pT"), utf("প্ট")) self.assertEqual(avro.parse("pt"), utf("প্ত")) self.assertEqual(avro.parse("pn"), utf("প্ন")) self.assertEqual(avro.parse("pp"), utf("প্প")) self.assertEqual(avro.parse("pl"), utf("প্ল")) self.assertEqual(avro.parse("ps"), utf("প্স")) self.assertEqual(avro.parse("ph"), utf("ফ")) self.assertEqual(avro.parse("fl"), utf("ফ্ল")) self.assertEqual(avro.parse("f"), utf("ফ")) self.assertEqual(avro.parse("p"), utf("প")) self.assertEqual(avro.parse("rri`"), utf("ৃ")) self.assertEqual(avro.parse("rri"), utf("ঋ")) self.assertEqual(avro.parse("krri"), utf("কৃ")) self.assertEqual(avro.parse("Irri"), utf("ঈঋ")) self.assertEqual(avro.parse("^rri"), utf("ঁঋ")) self.assertEqual(avro.parse(":rri"), utf("ঃঋ")) self.assertEqual(avro.parse("rZ"), utf("র্য")) self.assertEqual(avro.parse("krZ"), utf("ক্র্য")) self.assertEqual(avro.parse("rrZ"), utf("রর্য")) self.assertEqual(avro.parse("yrZ"), utf("ইয়র্য")) self.assertEqual(avro.parse("wrZ"), utf("ওর্য")) self.assertEqual(avro.parse("xrZ"), utf("এক্সর্য")) self.assertEqual(avro.parse("irZ"), utf("ইর্য")) self.assertEqual(avro.parse("-rZ"), utf("-র্য")) self.assertEqual(avro.parse("rrrZ"), utf("ররর্য")) self.assertEqual(avro.parse("ry"), utf("র্য")) self.assertEqual(avro.parse("qry"), utf("ক্র্য")) self.assertEqual(avro.parse("rry"), utf("রর্য")) self.assertEqual(avro.parse("yry"), utf("ইয়র্য")) self.assertEqual(avro.parse("wry"), utf("ওর্য")) self.assertEqual(avro.parse("xry"), utf("এক্সর্য")) self.assertEqual(avro.parse("0ry"), utf("০র্য")) self.assertEqual(avro.parse("rrrry"), utf("রররর্য")) self.assertEqual(avro.parse("Rry"), utf("ড়্র্য")) self.assertEqual(avro.parse("rr"), utf("রর")) self.assertEqual(avro.parse("arr"), utf("আরর")) self.assertEqual(avro.parse("arrk"), utf("আর্ক")) self.assertEqual(avro.parse("arra"), utf("আররা")) self.assertEqual(avro.parse("arr"), utf("আরর")) self.assertEqual(avro.parse("arr!"), utf("আরর!")) self.assertEqual(avro.parse("krr"), utf("ক্রর")) self.assertEqual(avro.parse("krra"), utf("ক্ররা")) self.assertEqual(avro.parse("Rg"), utf("ড়্গ")) self.assertEqual(avro.parse("Rh"), utf("ঢ়")) self.assertEqual(avro.parse("R"), utf("ড়")) self.assertEqual(avro.parse("r"), utf("র")) self.assertEqual(avro.parse("or"), utf("অর")) self.assertEqual(avro.parse("mr"), utf("ম্র")) self.assertEqual(avro.parse("1r"), utf("১র")) self.assertEqual(avro.parse("+r"), utf("+র")) self.assertEqual(avro.parse("rr"), utf("রর")) self.assertEqual(avro.parse("yr"), utf("ইয়র")) self.assertEqual(avro.parse("wr"), utf("ওর")) self.assertEqual(avro.parse("xr"), utf("এক্সর")) self.assertEqual(avro.parse("zr"), utf("য্র")) self.assertEqual(avro.parse("mri"), utf("ম্রি")) self.assertEqual(avro.parse("shch"), utf("শ্ছ")) self.assertEqual(avro.parse("ShTh"), utf("ষ্ঠ")) self.assertEqual(avro.parse("Shph"), utf("ষ্ফ")) self.assertEqual(avro.parse("Sch"), utf("শ্ছ")) self.assertEqual(avro.parse("skl"), utf("স্ক্ল")) self.assertEqual(avro.parse("skh"), utf("স্খ")) self.assertEqual(avro.parse("sth"), utf("স্থ")) self.assertEqual(avro.parse("sph"), utf("স্ফ")) self.assertEqual(avro.parse("shc"), utf("শ্চ")) self.assertEqual(avro.parse("sht"), utf("শ্ত")) self.assertEqual(avro.parse("shn"), utf("শ্ন")) self.assertEqual(avro.parse("shm"), utf("শ্ম")) self.assertEqual(avro.parse("shl"), utf("শ্ল")) self.assertEqual(avro.parse("Shk"), utf("ষ্ক")) self.assertEqual(avro.parse("ShT"), utf("ষ্ট")) self.assertEqual(avro.parse("ShN"), utf("ষ্ণ")) self.assertEqual(avro.parse("Shp"), utf("ষ্প")) self.assertEqual(avro.parse("Shf"), utf("ষ্ফ")) self.assertEqual(avro.parse("Shm"), utf("ষ্ম")) self.assertEqual(avro.parse("spl"), utf("স্প্ল")) self.assertEqual(avro.parse("sk"), utf("স্ক")) self.assertEqual(avro.parse("Sc"), utf("শ্চ")) self.assertEqual(avro.parse("sT"), utf("স্ট")) self.assertEqual(avro.parse("st"), utf("স্ত")) self.assertEqual(avro.parse("sn"), utf("স্ন")) self.assertEqual(avro.parse("sp"), utf("স্প")) self.assertEqual(avro.parse("sf"), utf("স্ফ")) self.assertEqual(avro.parse("sm"), utf("স্ম")) self.assertEqual(avro.parse("sl"), utf("স্ল")) self.assertEqual(avro.parse("sh"), utf("শ")) self.assertEqual(avro.parse("Sc"), utf("শ্চ")) self.assertEqual(avro.parse("St"), utf("শ্ত")) self.assertEqual(avro.parse("Sn"), utf("শ্ন")) self.assertEqual(avro.parse("Sm"), utf("শ্ম")) self.assertEqual(avro.parse("Sl"), utf("শ্ল")) self.assertEqual(avro.parse("Sh"), utf("ষ")) self.assertEqual(avro.parse("s"), utf("স")) self.assertEqual(avro.parse("S"), utf("শ")) self.assertEqual(avro.parse("oo"), utf("উ")) self.assertEqual(avro.parse("OO"), utf("ওও")) self.assertEqual(avro.parse("oo`"), utf("ু")) self.assertEqual(avro.parse("koo"), utf("কু")) self.assertEqual(avro.parse("ooo"), utf("উঅ")) self.assertEqual(avro.parse("!oo"), utf("!উ")) self.assertEqual(avro.parse("!ooo"), utf("!উঅ")) self.assertEqual(avro.parse("aoo"), utf("আউ")) self.assertEqual(avro.parse("oop"), utf("উপ")) self.assertEqual(avro.parse("ooo`"), utf("উ")) self.assertEqual("", avro.parse("o`")) self.assertEqual(avro.parse("oZ"), utf("অ্য")) self.assertEqual(avro.parse("oY"), utf("অয়")) self.assertEqual(avro.parse("o"), utf("অ")) self.assertEqual(avro.parse("!o"), utf("!অ")) self.assertEqual(avro.parse("^o"), utf("ঁঅ")) self.assertEqual(avro.parse("*o"), utf("*অ")) self.assertEqual(avro.parse("io"), utf("ইও")) self.assertEqual(avro.parse("yo"), utf("ইয়")) self.assertEqual(avro.parse("no"), utf("ন")) self.assertEqual(avro.parse("tth"), utf("ত্থ")) self.assertEqual(avro.parse("t``"), utf("ৎ")) self.assertEqual(avro.parse("`t``"), utf("ৎ")) self.assertEqual(avro.parse("t``t``"), utf("ৎৎ")) self.assertEqual(avro.parse("t```"), utf("ৎ")) self.assertEqual(avro.parse("TT"), utf("ট্ট")) self.assertEqual(avro.parse("Tm"), utf("ট্ম")) self.assertEqual(avro.parse("Th"), utf("ঠ")) self.assertEqual(avro.parse("tn"), utf("ত্ন")) self.assertEqual(avro.parse("tm"), utf("ত্ম")) self.assertEqual(avro.parse("th"), utf("থ")) self.assertEqual(avro.parse("tt"), utf("ত্ত")) self.assertEqual(avro.parse("T"), utf("ট")) self.assertEqual(avro.parse("t"), utf("ত")) self.assertEqual(avro.parse("aZ"), utf("অ্যা")) self.assertEqual(avro.parse("aaZ"), utf("আঅ্যা")) self.assertEqual(avro.parse("AZ"), utf("অ্যা")) self.assertEqual(avro.parse("a`"), utf("া")) self.assertEqual(avro.parse("a``"), utf("া")) self.assertEqual(avro.parse("ka`"), utf("কা")) self.assertEqual(avro.parse("A`"), utf("া")) self.assertEqual(avro.parse("a"), utf("আ")) self.assertEqual(avro.parse("`a"), utf("আ")) self.assertEqual(avro.parse("k`a"), utf("কআ")) self.assertEqual(avro.parse("ia"), utf("ইয়া")) self.assertEqual(avro.parse("aaaa`"), utf("আআআা")) self.assertEqual(avro.parse("i`"), utf("ি")) self.assertEqual(avro.parse("i"), utf("ই")) self.assertEqual(avro.parse("`i"), utf("ই")) self.assertEqual(avro.parse("hi"), utf("হি")) self.assertEqual(avro.parse("ih"), utf("ইহ")) self.assertEqual(avro.parse("i`h"), utf("িহ")) self.assertEqual(avro.parse("I`"), utf("ী")) self.assertEqual(avro.parse("I"), utf("ঈ")) self.assertEqual(avro.parse("cI"), utf("চী")) self.assertEqual(avro.parse("Ix"), utf("ঈক্স")) self.assertEqual(avro.parse("II"), utf("ঈঈ")) self.assertEqual(avro.parse("0I"), utf("০ঈ")) self.assertEqual(avro.parse("oI"), utf("অঈ")) self.assertEqual(avro.parse("u`"), utf("ু")) self.assertEqual(avro.parse("u"), utf("উ")) self.assertEqual(avro.parse("ku"), utf("কু")) self.assertEqual(avro.parse("uk"), utf("উক")) self.assertEqual(avro.parse("uu"), utf("উউ")) self.assertEqual(avro.parse("iu"), utf("ইউ")) self.assertEqual(avro.parse("&u"), utf("&উ")) self.assertEqual(avro.parse("u&"), utf("উ&")) self.assertEqual(avro.parse("U`"), utf("ূ")) self.assertEqual(avro.parse("U"), utf("ঊ")) self.assertEqual(avro.parse("yU"), utf("ইয়ূ")) self.assertEqual(avro.parse("Uy"), utf("ঊয়")) self.assertEqual(avro.parse("^U"), utf("ঁঊ")) self.assertEqual(avro.parse("U^"), utf("ঊঁ")) self.assertEqual(avro.parse("EE"), utf("ঈ")) self.assertEqual(avro.parse("ee"), utf("ঈ")) self.assertEqual(avro.parse("Ee"), utf("ঈ")) self.assertEqual(avro.parse("eE"), utf("ঈ")) self.assertEqual(avro.parse("ee`"), utf("ী")) self.assertEqual(avro.parse("kee"), utf("কী")) self.assertEqual(avro.parse("eek"), utf("ঈক")) self.assertEqual(avro.parse("0ee"), utf("০ঈ")) self.assertEqual(avro.parse("ee8"), utf("ঈ৮")) self.assertEqual(avro.parse("(ee)"), utf("(ঈ)")) self.assertEqual(avro.parse("e`"), utf("ে")) self.assertEqual(avro.parse("e"), utf("এ")) self.assertEqual(avro.parse("ke"), utf("কে")) self.assertEqual(avro.parse("we"), utf("ওয়ে")) self.assertEqual(avro.parse("#e#"), utf("#এ#")) self.assertEqual(avro.parse("`e`"), utf("ে")) self.assertEqual(avro.parse("z"), utf("য")) self.assertEqual(avro.parse("Z"), utf("্য")) self.assertEqual(avro.parse("rZ"), utf("র্য")) self.assertEqual(avro.parse("kZS"), utf("ক্যশ")) self.assertEqual(avro.parse("y"), utf("ইয়")) self.assertEqual(avro.parse("oy"), utf("অয়")) self.assertEqual(avro.parse("ky"), utf("ক্য")) self.assertEqual(avro.parse("ya"), utf("ইয়া")) self.assertEqual(avro.parse("yaa"), utf("ইয়াআ")) self.assertEqual(avro.parse("Y"), utf("য়")) self.assertEqual(avro.parse("YY"), utf("য়য়")) self.assertEqual(avro.parse("iY"), utf("ইয়")) self.assertEqual(avro.parse("kY"), utf("কয়")) self.assertEqual(avro.parse("q"), utf("ক")) self.assertEqual(avro.parse("Q"), utf("ক")) self.assertEqual(avro.parse("w"), utf("ও")) self.assertEqual(avro.parse("wa"), utf("ওয়া")) self.assertEqual(avro.parse("-wa-"), utf("-ওয়া-")) self.assertEqual(avro.parse("woo"), utf("ওয়ু")) self.assertEqual(avro.parse("wre"), utf("ওরে")) self.assertEqual(avro.parse("kw"), utf("ক্ব")) self.assertEqual(avro.parse("x"), utf("এক্স")) self.assertEqual(avro.parse("ex"), utf("এক্স")) self.assertEqual(avro.parse("bx"), utf("বক্স")) self.assertEqual(avro.parse(":`"), utf(":")) self.assertEqual(avro.parse(":"), utf("ঃ")) self.assertEqual(avro.parse("^`"), utf("^")) self.assertEqual(avro.parse("^"), utf("ঁ")) self.assertEqual(avro.parse("k^"), utf("কঁ")) self.assertEqual(avro.parse("k^i"), utf("কঁই")) self.assertEqual(avro.parse("ki^"), utf("কিঁ")) self.assertEqual(avro.parse(",,"), utf("্")) self.assertEqual(avro.parse(",,,"), utf("্,")) self.assertEqual(avro.parse(",,`,"), utf("্,")) self.assertEqual(avro.parse("`,,"), utf("্")) self.assertEqual(avro.parse(",`,"), utf(",,")) self.assertEqual(avro.parse("$"), utf("৳")) self.assertEqual("", avro.parse("`")) self.assertEqual(avro.parse("bdh"), utf("ব্ধ"))
def test_other(self): self.assertEqual(avro.parse("!"), utf("!"))
def test_patterns_numbers(self): """Test patterns - numbers""" # Test some numbers self.assertEqual(utf("০"), avro.parse("0")) self.assertEqual(utf("১"), avro.parse("1")) self.assertEqual(utf("২"), avro.parse("2")) self.assertEqual(utf("৩"), avro.parse("3")) self.assertEqual(utf("৪"), avro.parse("4")) self.assertEqual(utf("৫"), avro.parse("5")) self.assertEqual(utf("৬"), avro.parse("6")) self.assertEqual(utf("৭"), avro.parse("7")) self.assertEqual(utf("৮"), avro.parse("8")) self.assertEqual(utf("৯"), avro.parse("9")) self.assertEqual(utf("১১২"), avro.parse("112"))
def conv(stre="", delim="!?.", n=0): '''convert bengali text written in english to bengali while keeping english ony text ''' import string #importing string from pyavrophonetic import avro import enchant d = enchant.DictWithPWL("en_GB", "data/bdict4.txt") strret = "" english = 0 bengali = 0 startendsign = "" global globstr try: while stre[n] != "." and stre[n] != "?" and stre[n] != "!": # Iterating from the back of the sentence strret += stre[n] n += 1 else: endendsign = stre[n] except: return "Done" strlst = strret.split() lenghty = len(strlst) for element in range(lenghty): flag1 = 0 flag2 = 0 if d.check(strlst[element]): flag1 += 1 elementben = avro.parse(strlst[element]) if d.check(elementben): flag2 += 1 if flag1 == 1 and flag2 == 0: english += 1 elif flag1 == 0 and flag2 == 1: bengali += 1 elif flag1 == 1 and flag2 == 1: english += 1 bengali += 1 else: pass if english > bengali: pass strret = " ".join(strlst) elif bengali > english: for element in range(lenghty): flag1 = 0 flag2 = 0 if d.check(strlst[element]): flag1 += 1 elementben = avro.parse(strlst[element]) if d.check(elementben): flag2 += 1 if flag1 == 1 and flag2 == 0: pass elif flag1 == 0 and flag2 == 1: strlst[element] = elementben elif flag1 == 1 and flag2 == 1: pass else: pass strret = " ".join(strlst) else: pass strret = startendsign + strret + avro.parse(endendsign) print(strret, ) globstr += strret conv(stre, n=n + 1)
#!/usr/local/bin/python from pyavrophonetic import avro from textblob import TextBlob from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer import sys b = input("Enter Banglish :") textBlobTrans = TextBlob(avro.parse(b)) c = str(textBlobTrans.translate(to='en')) print(c) analyze = TextBlob(c) print('By TextBlob Sentiment analysis') print(analyze.sentiment) print('By vaderSentiment analyzer') analyzer = SentimentIntensityAnalyzer() vs = analyzer.polarity_scores(c) print(str(vs))
def test_patterns_numbers(self): """Test patterns - numbers""" # Test some numbers self.assertEquals(utf("০"), avro.parse("0")) self.assertEquals(utf("১"), avro.parse("1")) self.assertEquals(utf("২"), avro.parse("2")) self.assertEquals(utf("৩"), avro.parse("3")) self.assertEquals(utf("৪"), avro.parse("4")) self.assertEquals(utf("৫"), avro.parse("5")) self.assertEquals(utf("৬"), avro.parse("6")) self.assertEquals(utf("৭"), avro.parse("7")) self.assertEquals(utf("৮"), avro.parse("8")) self.assertEquals(utf("৯"), avro.parse("9")) self.assertEquals(utf("১১২"), avro.parse("112"))
def test_patterns_without_rules_from_config(self): """Tests all patterns from config that don't have rules""" for pattern in AVRO_DICT['data']['patterns']: if 'rules' not in pattern: self.assertEqual(pattern['replace'], avro.parse(pattern['find']))
def test_patterns_punctuations(self): """Tests patterns - punctuations""" # Test some punctuations self.assertEquals(utf("।"), avro.parse(".")) self.assertEquals(utf("।।"), avro.parse("..")) self.assertEquals(utf("..."), avro.parse("..."))
def test_sentences(self): """Test parsing of sentences""" self.assertEqual(utf('আমি বাংলায় গান গাই'), avro.parse('ami banglay gan gai'))
def translateBanglishToBangla(banglishWord): return avro.parse(banglishWord)
def buttonClick(): speak = wincl.Dispatch("SAPI.SpVoice") recengine = "google" mixer.init() x = 0 y = 0 flag = False mode = 0 r = sr.Recognizer() global ok if ok: playSound("msg1.mp3") ok = 0 recognised = u"" with sr.Microphone() as source: r.adjust_for_ambient_noise(source) playSound("start.mp3") f1 = False print u"আপনার বাক্য বলুন" with sr.Microphone() as source: audio = r.listen(source) try: recognised = r.recognize_google(audio, language='bn-BD') f1 = True except sr.UnknownValueError: print(u"গুগল স্পিচ রিকগনিশন অডিও বুঝতে পারেনি(১)") except sr.RequestError as e: print(u"গুগল স্পিচ রিকগনিশন অডিও বুঝতে পারেনি(২)") #print("Could not request results from Google Speech Recognition service; {0}".format(e)) if f1: print u"সফল হয়েছে" entry1.focus() entry1.delete(0, END) entry1.insert(0, recognised) if findWholeWord('hello')(recognised) or findWholeWord('hi')( recognised) or findWholeWord('hey')( recognised) or findWholeWord("what's up")(recognised): speak.Speak("greetings to you too. I'm ready to do your bidding.") elif findWholeWord('good morning')(recognised) or findWholeWord( 'good afternoon')(recognised) or findWholeWord('good evening')( recognised): speak.Speak("greetings to you too. I'm ready to do your bidding.") elif findBanglaWord(recognised, u"সুপ্রভাত") or findBanglaWord( recognised, u"শুভ সকাল"): textToSpeech( u"সুপ্রভাত! একটি চমৎকার দিন আশা করছি আপনার জন্য স্যার") playSound("result.mp3") elif findBanglaWord(recognised, u"শুভ অপরাহ্ন"): textToSpeech(u"ধন্যবাদ। শুভ অপরাহ্ন") playSound("result.mp3") elif findBanglaWord(recognised, u"শুভ সন্ধ্যা"): textToSpeech(u"ধন্যবাদ। শুভ সন্ধ্যা") playSound("result.mp3") elif findWholeWord('thank you')(recognised) or findWholeWord('thank')( recognised): speak.Speak("You are welcome.") elif findBanglaWord(recognised, u"ধন্যবাদ"): textToSpeech(u"আপনাকে স্বাগতম") playSound("result.mp3") elif findWholeWord('how are you')(recognised): speak.Speak("I am fine. Thank you") elif findBanglaWord(recognised, u"কেমন আছেন") or findBanglaWord( recognised, u"আছেন কেমন") or findBanglaWord( recognised, u"কেমন আছো"): textToSpeech(u"আমি ভালো। আপনি কেমন আছেন?") playSound("result.mp3") elif findWholeWord('your name')(recognised): speak.Speak("I am Smarty. I can make your work a lot easier.") elif findBanglaWord(recognised, u"নাম কি") or findBanglaWord( recognised, u"কি নাম"): textToSpeech(u"আমি Smarty") playSound("result.mp3") elif findWholeWord('open browser')(recognised) or findWholeWord( 'open chrome')(recognised) or findWholeWord('open firefox')( recognised) or findWholeWord('open internet explorer')( recognised): if findWholeWord('open browser')(recognised) or findWholeWord( 'browser')(recognised): speak.Speak("All right, I will do it for you.") webbrowser.open('http://www.google.com') elif findWholeWord('open chrome')(recognised): speak.Speak("All right, I will open Chrome.") url = 'chrome://newtab' chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' webbrowser.get(chrome_path).open(url) elif findWholeWord('open internet explorer')( recognised) or findWholeWord('internet explorer')( recognised): ie = webbrowser.get(webbrowser.iexplore) ie.open('google.com') elif findWholeWord('open mozilla firefox')( recognised) or findWholeWord('open firefox')( recognised) or findWholeWord('firefox')(recognised): speak.Speak("All right, I will open Firefox for you.") webbrowser.get( 'C:/Program Files/Mozilla Firefox/firefox.exe %s').open( 'http://www.google.com') elif findWholeWord('what time is it')(recognised) or findWholeWord( 'what is the time now')(recognised) or findWholeWord( 'tell me the time')( recognised) or findWholeWord('what time')( recognised) and findWholeWord('now')(recognised): timenow = time.localtime() timeh = timenow.tm_hour timem = timenow.tm_min if timeh < 13: ampm = "AM" else: ampm = "PM" if timem > 9: extra = " " else: extra = "oh" speak.Speak("the time is " + str(timeh) + extra + str(timem) + ampm) elif findBanglaWord(recognised, u"কয়টা বাজে") or findBanglaWord( recognised, u"বাজে কয়টা") or findBanglaWord( recognised, u"সময় কত"): timenow = time.localtime() timeH = timenow.tm_hour timeM = timenow.tm_min ampm = "AM" if timeH == 0: timeH = 12 if timeH == 12: ampm = "PM" if timeH > 12 and timeH <= 23: timeH = timeH - 12 ampm = "PM" if ampm == "AM": somoy = u"এখন সময় সকাল " + avro.parse( str(timeH)) + u" টা বেজে " + avro.parse( str(timeM)) + u" মিনিট" else: somoy = u"এখন সময় বিকেল " + avro.parse( str(timeH)) + u" টা বেজে " + avro.parse( str(timeM)) + u" মিনিট" print somoy textToSpeech(somoy) playSound("result.mp3") elif findWholeWord('what is the temperature')( recognised) or findWholeWord('what is the weather')( recognised) or findWholeWord('weather in')(recognised): loc = "Sylhet, Bangladesh" if "dhaka" in recognised: loc = "Dhaka, Bangladesh" elif "chittagong" in recognised: loc = "Chittagong, Bangladesh" elif "new york" in recognised: loc = "New York" lookup = pywapi.get_location_ids(loc) #print lookup for i in lookup: location_id = i print "loocation_id = " + location_id weather = pywapi.get_weather_from_weather_com(location_id) speak.Speak("the weather in " + loc + " is " + weather['current_conditions']['text'] + ". Current temp " + weather['current_conditions']['temperature'] + " degrees Celsius") elif findBanglaWord(recognised, u"ওয়েদার কেমন") or findBanglaWord( recognised, u"আবহাওয়া কেমন") or findBanglaWord( recognised, u"আবহাওয়ার খবর") or findBanglaWord( recognised, u"তাপমাত্রা কেমন") or findBanglaWord( recognised, u"আবহাওয়ার কি অবস্থা"): loc = "Sylhet, Bangladesh" lookup = pywapi.get_location_ids(loc) for i in lookup: location_id = i weather = pywapi.get_weather_from_weather_com(location_id) text = weather['current_conditions']['text'] temp = weather['current_conditions']['temperature'] abohowya = u"বর্তমান আবহাওয়া " + text + u" এবং তাপমাত্রা " + avro.parse( str(temp)) + u" ডিগ্রি সেলসিয়াস" textToSpeech(abohowya) playSound("result.mp3") elif findWholeWord('go to')(recognised) and ".com" in recognised: domain = recognised.split("go to ", 1)[1] speak.Speak("All right, I will take you to" + domain) webbrowser.open('http://www.' + domain) elif findWholeWord('close')(recognised): f = recognised.split("close ", 1)[1] speak.Speak(f + " is closed Sir.") p = 'TASKKILL /F /IM ' + f + '.exe' try: os.system(p) except: speak.Speak(f + " is already closed Sir") elif findWholeWord('lock')(recognised) and findWholeWord('pc')( recognised ) or findWholeWord('lock')(recognised) and findWholeWord('computer')( recognised) or findWholeWord('lock')( recognised) and findWholeWord('system')(recognised): ctypes.windll.user32.LockWorkStation() elif findBanglaWord(recognised, "কম্পিউটার তালা"): ctypes.windll.user32.LockWorkStation() elif findWholeWord('shutdown')(recognised) and findWholeWord('pc')( recognised ) or findWholeWord('shutdown')(recognised) and findWholeWord( 'computer')(recognised) or findWholeWord('shutdown')( recognised) and findWholeWord('system')(recognised): os.system('shutdown -s') elif findBanglaWord( recognised, "কম্পিউটার বন্ধ করুন") or findBanglaWord( recognised, "কম্পিউটার বন্ধ করো") or findBanglaWord( recognised, "কম্পিউটার বন্ধ কর"): os.system('shutdown -s') else: #internal search qDict = {} cntDict = {} for word in recognised.split(): qDict[word] = 1 path = u"""C:/Users/royta/Desktop/Final/""" files = os.listdir(path) for txtfiles in files: if ".txt" in txtfiles: p = path + txtfiles cnt = 0 with codecs.open(p, 'r', encoding='utf-8', errors='ignore') as f: for line in f: for word in line.split(): if word in qDict: cnt += 1 cntDict[txtfiles] = cnt Max = 0 fileName = "" for key, value in cntDict.iteritems(): #print key, "-->", value if value > Max: Max = value fileName = key if Max == 0: print "Nothing matched. Looking online for solution." else: print "Maximum matched ", fileName, " --> ", Max #end of the internal search print recognised if detect(recognised) == "en": #wikipedia English stuff querySummary = "" wikipedia.set_lang("en") try: idx = 0 searchResult = wikipedia.search(recognised) length = len(searchResult) i = 0 while i < length: if searchResult[i] == recognised: idx = i break i += 1 querySummary = wikipedia.summary(searchResult[idx], sentences=3) result = remove_text_between_parens(querySummary) print result speak.Speak(result) except IndexError: playSound("error.mp3") except wikipedia.exceptions.DisambiguationError: playSound("error.mp3") except wikipedia.exceptions.PageError: playSound("error.mp3") else: #wikipedia Bangla stuff querySummary = u"" wikipedia.set_lang("bn") try: idx = 0 searchResult = wikipedia.search(recognised) length = len(searchResult) i = 0 while i < length: if searchResult[i] == recognised: idx = i break i += 1 playSound("waitmsg.mp3") querySummary = wikipedia.summary(searchResult[idx]) #3 line summary result = sentence(3, querySummary) result = remove_text_between_parens(result) #print result textToSpeech(result) playSound("result.mp3") except IndexError: playSound("error.mp3") except wikipedia.exceptions.DisambiguationError: playSound("error.mp3") except wikipedia.exceptions.PageError: playSound("error.mp3") else: playSound("error.mp3")
#!/usr/local/bin/python #coding:utf8 from pyavrophonetic import avro from textblob import TextBlob from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer banglish = "ami to shudhu Ilish je Chandpur er eita confirm korechilam... Shorshe r sathe mile je sorshe ilish namok shushadu khabar toiri hobe ami ki jani." #banglish = "আগামী ২০ থেকে ২৭ জুলাই পর্যন্ত (শুক্রবার ব্যতীত) নগরীর হ্যানে রেলওয়ে মাধ্যমিক স্কুলে সদরের ২১নং ওয়ার্ডের ভোটারদের স্মার্ট কার্ড বিতরণ করা হবে। এছাড়া ৩০ জুলাই" print banglish tr_bng = avro.parse(banglish) print tr_bng blob = TextBlob(tr_bng) tr_eng = blob.translate(to="en") print tr_eng.sentences analyser = SentimentIntensityAnalyzer() def print_sentiment_scores(sentence): snt = analyser.polarity_scores(sentence) print("{:-<40} {}".format(sentence, str(snt))) for sentence in tr_eng.sentences: #print type(sentence) stn = unicode(sentence) print_sentiment_scores(stn)
def test_patterns_with_rules_svaravarna(self): """Test patterns - with rules - svaravarna""" # Test some numbers self.assertEqual(utf("অ"), avro.parse("o")) self.assertEqual(utf("আ"), avro.parse("a")) self.assertEqual(utf("ই"), avro.parse("i")) self.assertEqual(utf("ঈ"), avro.parse("I")) self.assertEqual(utf("উ"), avro.parse("u")) self.assertEqual(utf("উ"), avro.parse("oo")) self.assertEqual(utf("ঊ"), avro.parse("U")) self.assertEqual(utf("এ"), avro.parse("e")) self.assertEqual(utf("ঐ"), avro.parse("OI")) self.assertEqual(utf("ও"), avro.parse("O")) self.assertEqual(utf("ঔ"), avro.parse("OU"))