drime

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

commit cce9d0f47200f4b81b5dc1a8985b51945f3a6d83
parent 7f5a09ccc35be436646d0b181d7e2ce5fb890e93
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat, 24 Dec 2011 00:18:55 +0100

better presentation and ordering

Diffstat:
query.py | 25++++++++++++++++++++++---
templates/results.html | 6++----
2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/query.py b/query.py @@ -86,6 +86,9 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): ''', (word, word == None, phon, phon == None, minsyll == None, minsyll, maxsyll == None, maxsyll, maxsyll,)) result = {} + cache = {} + ncache = {} + seen = {} for x in cursor: if x['t1_feminine'] != x['t2_feminine'] and gender: continue @@ -93,20 +96,36 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, offset, size): x['t1_word'] + ' [' + x['t1_phon'] + ']') if key not in result.keys(): result[key] = [] + cache[key] = [] + seen[key] = set() row = dict([ (k[3:], x[k]) for k in x.keys() if k.startswith('t2_')]) + if row['base'] in seen[key]: + continue + seen[key].add(row['base']) + row['freq'] = float(row['freq']) row['phon_rhyme'] = lcs(x['t1_phon'], row['phon']) row['word_rhyme'] = lcs(x['t1_word'], row['word']) row['key'] = ( -row['phon_rhyme'], # phon_rhyme desc -row['word_rhyme'], # eye_rhyme desc - row['base'] == row['word'], # same as base - -float(row['freq']), # frequency desc + row['base'] != row['word'], # same as base + -row['freq'], # frequency desc row['word'] # alphabetical order ) - result[key].append(row) + row['derivation'] = row['kind'] + ( + ' (' + row['base'] + ')' + if row['base'] != row['word'] + else '') + if row['word'] == x['t1_word'] and row['phon'] == x['t1_phon']: + cache[key].append(row) + else: + result[key].append(row) for k in result.keys(): + # only display the word itself if multiple derivations are possible + if len(cache[key]) > 1: + result[k] += cache[key] result[k] = sorted(result[k], key=operator.itemgetter('key')) print(result) return result diff --git a/templates/results.html b/templates/results.html @@ -7,8 +7,7 @@ <th>pron<a href="about/#pron" class="help">?</a></th> <th>phon</th> <th>eye</th> - <th>kind</th> - <th>base</th> + <th>derivation</th> <th>freq</th> {% for r in result %} <tr> @@ -16,8 +15,7 @@ <td>{{ r.phon }}</td> <td class="num">{{ r.phon_rhyme }}</td> <td class="num">{{ r.word_rhyme }}</td> - <td class="num">{{ r.kind }}</td> - <td>{{ r.base }}</td> + <td>{{ r.derivation }}</td> <td class="num">{{ r.freq }}</td> </tr> {% endfor %}