drime

French rhyme dictionary with web and CLI interface
git clone https://a3nm.net/git/drime/
Log | Files | Refs | README

commit 11d1c425321e7d9d5f83e645b84e2d43b2c876ba
parent b4e2473c5c33c67daf10dadbca01b3ccca3632f7
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue, 27 Dec 2011 02:05:00 +0100

cleanup

Diffstat:
query.py | 34+++++++++++++---------------------
1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/query.py b/query.py @@ -109,13 +109,13 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): minsyll == None, minsyll, maxsyll == None, maxsyll, maxsyll, elide,) query = ''' SELECT t1.feminine AS t1_feminine, - t2.word AS t2_word, - t2.phon AS t2_phon, - t2.freq AS t2_freq, - t2.min_nsyl AS t2_min_nsyl, - t2.max_nsyl AS t2_max_nsyl, - t2.elidable AS t2_elidable, - t2.orig AS t2_orig, + t2.word AS word, + t2.phon AS phon, + t2.freq AS freq, + t2.min_nsyl AS min_nsyl, + t2.max_nsyl AS max_nsyl, + t2.elidable AS elidable, + t2.orig AS orig, t2.feminine AS t2_feminine ''' + rest #+ limit print (query) @@ -123,19 +123,10 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): print ("DONE") result = [] - for x in cursor: - decode_all(x) - if x['t1_feminine'] != x['t2_feminine'] and gender: + for row in cursor: + decode_all(row) + if row['t1_feminine'] != row['t2_feminine'] and gender: continue - row = dict([ - (k[3:], x[k]) for k in x.keys() - if k.startswith('t2_')]) - for k in row.keys(): - if isinstance(row[k], str): - try: - row[k] = row[k].decode('utf8') - except UnicodeDecodeError: - row[k] = row[k].decode('latin1') if (row['word'].endswith('-'+word)): continue if (row['word'] == word and row['word'] == word @@ -143,7 +134,7 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): continue # don't display the word if it has only one possible origin row['freq'] = float(row['freq']) row['phon_rhyme'] = lcs(phon, row['phon']) - row['word_rhyme'] = lcs(phon, row['word']) + row['word_rhyme'] = lcs(word, row['word']) row['key'] = ( -row['phon_rhyme'], # phon_rhyme desc -row['word_rhyme'], # eye_rhyme desc @@ -151,8 +142,8 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): -row['freq'], # frequency desc row['word'] # alphabetical order ) - row['phon'] = to_xsampa(row['phon']) result.append(row) + print ("DONE2") result2 = [] seen = set() @@ -168,6 +159,7 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): row['orig'] = ', '.join( [a[0] + (' ('+a[1]+')' if row['word'] != a[1] else '') for a in bases]) + row['phon'] = to_xsampa(row['phon']) result2.append(row) seen.add(row['word']) count = len(result2)