def get_words_with_block(block, exclude=None): """ This functions returns a list of Korean words that rely on the same block. """ # DICTIONNARY IMPLEMENTATION if METHOD == 'dic': f = codecs.open(FILE, 'r', encoding='utf-8') lines = f.readlines() f.close() words = [] for line in lines: # Implementation 1: using hangul syllables if block.get_string() in line.split(',')[0]: word = line.split(',')[0].strip() if word != exclude: words.append(KoreanWord(string=word, \ meaning=line.split(',')[1].strip())) # DATABASE IMPLEMENTATION if METHOD == 'db': if block.get_ethym(): query = """SELECT * FROM `Korean` WHERE INSTR( ethym, '""" + block.get_ethym( ) + """') >0""" engine = create_engine(login.connection_string, echo=False) results = pd.io.sql.execute(query, engine) results = results.fetchall() words = [KoreanWord(string=r[0], ethym=r[1], meaning=r[2]) \ for r in results if r[0] != exclude and \ len(r[0]) == len(r[1]) and tools.detect_language(r[1]) is not 'korean'] # len check and ethym check to avoid some corrupted data from the database to be displayed else: # For example, we do not return a list of words for suffixes words = [] return words
def get_words_with_block(block, exclude=None): """ This functions returns a list of Korean words that rely on the same block. """ # DICTIONNARY IMPLEMENTATION if METHOD == 'dic': f = codecs.open(FILE, 'r', encoding='utf-8') lines = f.readlines() f.close() words = [] for line in lines: # Implementation 1: using hangul syllables if block.get_string() in line.split(',')[0]: word = line.split(',')[0].strip() if word != exclude: words.append(KoreanWord(string=word, \ meaning=line.split(',')[1].strip())) # DATABASE IMPLEMENTATION if METHOD == 'db': if block.get_ethym(): query = """SELECT * FROM `Korean` WHERE INSTR( ethym, '""" + block.get_ethym() + """') >0""" engine = create_engine(login.connection_string, echo=False) results = pd.io.sql.execute(query, engine) results = results.fetchall() words = [KoreanWord(string=r[0], ethym=r[1], meaning=r[2]) \ for r in results if r[0] != exclude and \ len(r[0]) == len(r[1]) and tools.detect_language(r[1]) is not 'korean'] # len check and ethym check to avoid some corrupted data from the database to be displayed else: # For example, we do not return a list of words for suffixes words = [] return words
# AWA MAIN #============================================================================== #UI.render_empty() # Entree UI.render_top() if DEBUG: UI.render_info('Python version ' + str(sys.version_info.major)) # Main form = cgi.FieldStorage() if 'word' in form.keys(): input_str = form["word"].value language = detect_language(_u(input_str)) if DEBUG: UI.render_info(language) if language == 'korean': from Korean import get_words_with_block from Korean import KoreanWord as Word elif language == 'thai': from Thai import get_words_with_block from Thai import ThaiWord as Word else: UI.render_error('Language not supported') if 'Word' in locals(): word = Word(input_str, compute_ethym=True) UI.render_main(word)
#============================================================================== #UI.render_empty() # Entree UI.render_top() if DEBUG: UI.render_info('Python version ' + str(sys.version_info.major)) # Main form = cgi.FieldStorage() if 'word' in form.keys(): input_str = form["word"].value language = detect_language(_u(input_str)) if DEBUG: UI.render_info(language) if language == 'korean': from Korean import get_words_with_block from Korean import KoreanWord as Word elif language == 'thai': from Thai import get_words_with_block from Thai import ThaiWord as Word else: UI.render_error('Language not supported') if 'Word' in locals(): word = Word(input_str, compute_ethym=True)