def TextData(dict): if 's-name' not in dict.keys(): surah = int(dict['surah']) else: dict1, dict2 = dictionary() s1_name = dict['s-name'] surah = int(dict1[s1_name]) ayah = int(dict['ayah']) if 'ed' not in dict.keys(): edition = 'en.ahmedali' else: if dict['ed'] == 'urdu': edition = 'ur.ahmedali' else: edition = dict['ed'] if surah <= 114 and surah >= 1: full_surah = requests.get('http://api.alquran.cloud/v1/surah/' + str(surah) + '/' + edition) full_surah = full_surah.json() full_surah = full_surah['data']['ayahs'] quran_text = full_surah[ayah - 1]['text'] quran_text = textwrap.wrap(quran_text, 235) return quran_text else: quran_text = [ "Error", "sorry,we can't interpret your data.Please enter the correct details" ] return quran_text
def help(message): bot.send_chat_action(message.chat.id, action='typing') bot.clear_step_handler(message) bot.send_message(chat_id=message.chat.id, text=dictionary(message.text), parse_mode='HTML', reply_markup=new_menu_button_keyboard())
def instruction_for_the_command(message, command, next_step): bot.clear_step_handler(message) bot.edit_message_text(text=dictionary(command), chat_id=message.chat.id, message_id=message.message_id, reply_markup=new_menu_button_keyboard(), parse_mode='HTML') bot.register_next_step_handler(message, next_step)
def result_of_the_command(message, command, next_command): keyboard = types.InlineKeyboardMarkup(row_width=2) keyboard.add(back_to_menu_button(), continue_button(next_command)) bot.edit_message_text(text=dictionary(command), chat_id=message.chat.id, message_id=message.message_id, reply_markup=keyboard, parse_mode='HTML')
def start(message): bot.send_chat_action(message.chat.id, action='typing') bot.clear_step_handler(message) bot.send_message(chat_id=message.chat.id, text=(dictionary( message.text, message.from_user.first_name )), parse_mode='HTML', reply_markup=new_menu_button_keyboard())
def from_min_to_max(string): numbers = string.split(' ', maxsplit=1) x = int(numbers[0]) y = int(numbers[1]) if (x < y): return int(random.uniform(int(x), int(y + 1))) elif (x > y): return int(random.uniform(int(y), int(x + 1))) else: return dictionary('equals_digits')
def send_result(message, generator, command): chat_id = message.chat.id bot.send_chat_action(chat_id, action='typing') try: if (not check_comands(message)): bot.send_message(chat_id=chat_id, text=generator(message.text), parse_mode='HTML') except Exception: bot.send_message(chat_id=chat_id, text=dictionary('error'), reply_to_message_id=message.message_id, parse_mode='HTML') bot.register_next_step_handler(message, command)
def newSearch(key, group="Saw", levenshtein=True, dbpath=DB_PATH, prefix=""): if not key: yield "" if not dbpath in dbs.keys(): dbs[dbpath] = dictionary(dbpath, prefix) if group == "Saw": result = dbs[dbpath].searchWord(key) if levenshtein: result = accurate_search.byLevenshtein(key, result) elif group == "Laeh": result = searchExamples(key) value = "" if group != "Laeh": for i in result: for j in i[1]: yield j else: for i in result: if i not in value: yield i
def newSearch(key, group="Saw", levenshtein=True, dbpath=DB_PATH, prefix=""): if not key: yield "" if not dbpath in dbs.keys(): dbs[dbpath] = dictionary(dbpath, prefix) if group == "Saw": result = dbs[dbpath].searchWord(key, False) if levenshtein: result = accurate_search.byLevenshtein(key, result) elif group == "Laeh": result = searchExamples(key) value = "" if group != "Laeh": for i in result: for j in i[1]: yield j else: for i in result: if i not in value: yield i
def newSearch(key, group="Saw", accurate=True, dbpath=DB_PATH): if not key: yield "" if not dbpath in dbs.keys(): dbs[dbpath] = dictionary(dbpath) if group == "Laeh": result = searchExamples(key) else: result = dbs[dbpath].searchWord(key) if accurate: tokenizer = tokenizers[group] result = accurate_search.byWordsAndLevenshtein( key, result, tokenizer) value = "" if group == "Laeh": for i in result: if i not in value: yield i else: for i in result: for j in i[1]: yield j
def continue_button(command): button = types.InlineKeyboardButton( text=dictionary('continue_button'), callback_data=command) return button
import DataProcessing.configure as config from commonfun import * from dictionary import * # Load data data = [] with open(config.adddata, 'r') as fp: for line in fp.readlines(): line = line.strip('\n') data.append(line) # Deduplicate data data = deduplicate(data) #Load the polyphones dictionary loading = dictionary(config.polyphone) dic = loading.load() # Format the new corpus # And # Find the new polyphones dex = [] pinyin = [] newpolychar = set() for i in range(len(data)): x = data[i] ind = [] pin = [] s = '' index = 0
def yes_or_no(): return random.choice([dictionary('yes'), dictionary('no')])
def menu_message(message): bot.send_chat_action(message.chat.id, action='typing') bot.clear_step_handler(message) bot.send_message(chat_id=message.chat.id, text=dictionary('menu_title'), reply_markup=menu_keyboard())
import os import sys import re import copy #TODO: Avoid this. try: sys.path.insert(0, 'blindtex') from iotools.stringtools import reportProblem except ValueError: from iotools.stringtools import reportProblem #-------------------------------------------------------------------------- #Variables dirección del los json #Lista de objetos diccionario: dOrdinary = dictionary(os.path.join('converter', 'dicts', 'Ordinary.json')) dLargeOperators = dictionary( os.path.join('converter', 'dicts', 'LargeOperators.json')) dBinaryOperators = dictionary( os.path.join('converter', 'dicts', 'BinaryOperators.json')) dBinaryRelations = dictionary( os.path.join('converter', 'dicts', 'BinaryRelations.json')) dMathFunctions = dictionary( os.path.join('converter', 'dicts', 'MathFunctions.json')) dArrows = dictionary(os.path.join('converter', 'dicts', 'Arrows.json')) dDelimiters = dictionary(os.path.join('converter', 'dicts', 'Delimiters.json')) dAccents = dictionary(os.path.join('converter', 'dicts', 'Accents.json')) dStyles = dictionary(os.path.join('converter', 'dicts', 'Styles.json')) dDots = dictionary(os.path.join('converter', 'dicts', 'Dots.json')) dUser = dictionary(os.path.join('converter', 'dicts', 'UserDict.json')) #-------------------------------------------------------------------------------
'boldmath': [0, ['negrilla']] } Dots = { 'dots': [0, ['puntos']], 'ldots': [0, ['puntos bajos']], 'cdots': [0, ['puntos centrados']], 'vdots': [0, ['puntos verticales']], 'ddots': [0, ['puntos diagonales']] } #Función para agregar al diccionario elementos key = '' value = '' #Estas variables de entrada se reconocerán posteriormente las dejo así por el momento, para probar con la GUI #addWord(key,value) Descomentar la línea cuando la función vaya a ser utulizada #TODO: Lista de objetos diccionario: dOrdinary = dictionary(Ordinary) dLargeOperators = dictionary(LargeOperators) dBinaryOperators = dictionary(BinaryOperators) dBinaryRelations = dictionary(BinaryRelations) dMathFunctions = dictionary(MathFunctions) dArrows = dictionary(Arrows) dDelimiters = dictionary(Delimiters) dAccents = dictionary(Accents) dStyles = dictionary(Styles) dDots = dictionary(Dots) #------------------------------------------------------------------------------- #The grammar. precedence = (('left', 'SUP', 'SUB', 'FRAC', 'ROOT'), ('right', 'LARGEOP'))
if TRAIN: from train import * from trainClassroom import * from trainProfessor import * from trainSchedule import * train(chatbot) trainClassroom(chatbotClassroom) trainProfessor(chatbotProfessor) trainSchedule(chatbotSchedule) scrapProfessorsForPresentation() sys.exit() start_remote_login() start_text_to_speech() d = dictionary() print('Done scraping!') server = SimpleWebSocketServer('', 8009, NLPController) _thread.start_new_thread(server.serveforever, ()) # Change to execute in the another browser DRIVER = webdriver.Chrome() sleep(1) start_presentation() while True: try: listen() except Exception as e:
def callback_inline(call): command = call.data message = call.message chat_id = message.chat.id message_id = message.message_id if (command == 'new_menu'): menu_message(message) bot.edit_message_reply_markup(chat_id=chat_id, message_id=message_id) elif (command == 'back_to_menu'): bot.clear_step_handler(message) bot.edit_message_text(text=dictionary('menu_title'), chat_id=chat_id, message_id=message_id, reply_markup=menu_keyboard()) elif (command == 'yes_or_no'): bot.edit_message_text(text=generators.yes_or_no(), chat_id=chat_id, message_id=message_id, reply_markup=new_menu_button_keyboard()) botan.track(token=botan_token, uid=message.chat.id, message=message, name='Да или нет') elif (command == 'choose_a_dice'): bot.edit_message_text(text=dictionary('how_many_faces'), chat_id=chat_id, message_id=message_id, reply_markup=dice_buttons_keyboard(command)) botan.track(token=botan_token, uid=message.chat.id, message=message, name='Кубики') elif (command == 'change_dice'): bot.edit_message_reply_markup(chat_id=chat_id, message_id=message_id) bot.send_message(chat_id=chat_id, text=dictionary('how_many_faces'), reply_markup=dice_buttons_keyboard(command)) elif (command == 'dice 4' or command == 'dice 6' or command == 'dice 8' or command == 'dice 12' or command == 'dice 20'): dice = command.split(' ')[1] buttons_with_dices = types.InlineKeyboardMarkup(row_width=2) buttons_with_dices.add( types.InlineKeyboardButton( text='🎲', callback_data=dice ), types.InlineKeyboardButton( text=dictionary('change_dice'), callback_data='change_dice'), new_menu_button() ) bot.edit_message_text(text=dice + dictionary('facees_of_dice'), chat_id=chat_id, message_id=message_id, reply_markup=buttons_with_dices) elif (command in ['4', '6', '8', '12', '20']): bot.send_message( chat_id=chat_id, text=generators.roll_a_dice(int(command))) elif (command == 'from_0_to_100'): bot.edit_message_text(text=generators.from_zero_to_hundred(), chat_id=chat_id, message_id=message_id, reply_markup=new_menu_button_keyboard()) botan.track(token=botan_token, uid=message.chat.id, message=message, name='От 0 до 100') elif (command == 'min_to_max'): result_of_the_command(message, command, 'enter_min_and_max') elif (command == 'enter_min_and_max'): instruction_for_the_command(message, command, enter_min_and_max) elif (command == 'one_from_seq'): result_of_the_command(message, command, 'enter_seq') elif (command == 'enter_seq'): instruction_for_the_command(message, command, enter_seq) elif (command == 'nonrep_numbers'): result_of_the_command(message, command, 'enter_number') elif (command == 'enter_number'): instruction_for_the_command(message, command, enter_number) elif (command == 'nonrep_numbers_for_seq'): result_of_the_command(message, command, 'enter_number_and_seq') elif (command == 'enter_number_and_seq'): instruction_for_the_command(message, command, enter_number_and_seq) elif (command == 'nonrep_numbers_except'): result_of_the_command(message, command, 'enter_number_and_exc') elif (command == 'enter_number_and_exc'): instruction_for_the_command(message, command, enter_number_and_exc) elif (command == 'nonrep_numbers_except_for_seq'): result_of_the_command(message, command, 'enter_number_and_exc_and_seq') elif (command == 'enter_number_and_exc_and_seq'): instruction_for_the_command( message, command, enter_number_and_exc_and_seq)
def new_menu_button(): button = types.InlineKeyboardButton( text=dictionary('menu_button'), callback_data='new_menu') return button
def menu_keyboard(): keyboard = types.InlineKeyboardMarkup(row_width=1) button = types.InlineKeyboardButton keyboard.add( button(text=dictionary('yes_or_no_button'), callback_data='yes_or_no'), button(text=dictionary('choose_a_dice_button'), callback_data='choose_a_dice'), button(text=dictionary('from_0_to_100_button'), callback_data='from_0_to_100'), button(text=dictionary('min_to_max_button'), callback_data='min_to_max'), button(text=dictionary('one_from_seq_button'), callback_data='one_from_seq'), button(text=dictionary('nonrep_numbers_button'), callback_data='nonrep_numbers'), button(text=dictionary('nonrep_numbers_for_seq_button'), callback_data='nonrep_numbers_for_seq'), button(text=dictionary('nonrep_numbers_except_button'), callback_data='nonrep_numbers_except'), button(text=dictionary('nonrep_numbers_except_for_seq_button'), callback_data='nonrep_numbers_except_for_seq'), button(text=dictionary('share_button'), switch_inline_query=dictionary('share_query')) ) return keyboard