drime

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

commit bf1b4130a469463040a3974a6b58a3e43149de5f
parent 208db0bba699fd529d4b7bc871dfa5e2ccc54b2c
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Mon,  6 Jan 2014 01:51:37 +0100

Merge branch 'master' of gitorious.org:drime/drime

Diffstat:
README | 28++++++++++++++++++++++++----
TODO | 6++++--
query.py | 13+++++++++----
templates/about.html | 9+++++++--
4 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/README b/README @@ -22,6 +22,16 @@ folder, and also "frhyme.py" (see plint's documentation). drime also requires PyMySQL <http://www.pymysql.org> and Flask <http://flask.pocoo.org/> for Python3. +drime requires a working MySQL installation (package mysql-server on Debian +systems) and the instructions in this README require the MySQL client (package +mysql-client) to populate the database. You will probably want to create a +database and a user for drime, probably along the lines of the following SQL +commands executed using "mysql -u root -p": + + CREATE DATABASE drime; + CREATE USER 'drime'@'localhost' IDENTIFIED BY 'mysecretpassword'; + GRANT ALL ON drime.* TO 'drime'@'localhost'; + == 3. Generating the DB == The program database isn't shipped, but scripts are provided to build it @@ -41,7 +51,9 @@ If this is not your first attempt, unzip might prompt you about overwriting existing files. Answer 'A'. To import the output of lexique2sql.sh in a MySQL database (on localhost, -database 'drime', as user 'drime', interactive password authentication), run: +database 'drime', as user 'drime', interactive password authentication, the +password being "mysecretpassword" if you followed the instructions of the +previous section), run: cat output.sql | cat <(echo 'use drime;') - | @@ -50,7 +62,7 @@ database 'drime', as user 'drime', interactive password authentication), run: mysql --default-character-set=utf8 -D drime -u drime -p To monitor progress, use the pv utility (replace "cat output.sql" by -"pv -l output.sql". +"pv -l output.sql"). == 4. Using the DB == @@ -82,9 +94,17 @@ specifics are left as an unpleasant exercise to the reader. Run: - ./query.py QUERY [NSYL [GENDER]] + ./query.py QUERY [NSYL [GENDER [CLASSICAL [PAGE]]]] + +The parameters are the same as the four fields of the web interface, with the +option to specify a page. For instance, to request rhymes for "chanter" with +between 2-4 syllables, respecting genre but not classical constraints, run: + + ./query.py chanter 2-4 true true + +To get the second page of results, run: -The parameters are the same as the three fields of the web interface. + ./query.py chanter 2-4 true true 2 Results are returned in a raw format (if the query is successful). To pretty-print, do: diff --git a/TODO b/TODO @@ -1,5 +1,7 @@ -- disable classical +- disable classical correctly on web interface - only use python3 - change db module - refactor common.py with plint -- lien pour forcer la langue +- lien pour forcer la langue sur l'interface web +- meilleure notion de la rime +- approche automatique, à base d'un corpus, avec exemples ? diff --git a/query.py b/query.py @@ -196,11 +196,11 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, classical, offset, siz row['phon'] = to_xsampa(row['phon']) result2.append(row) c += 1 - if c > size: + if c > offset + size: break seen.add(row['word']) count = len(result) - result2 = result2[:size] + result2 = result2[offset:offset+size] #cursor = run_query(''' #SELECT count(t2.word) @@ -211,13 +211,18 @@ def do_query(word, phon, minsyll, maxsyll, elide, gender, classical, offset, siz if __name__ == '__main__': def usage(): - print ("Usage: %s QUERY [NSYL [GENDER [CLASSICAL]]]" % sys.argv[0]) + print ("Usage: %s QUERY [NSYL [GENDER [CLASSICAL [PAGE]]]]" % sys.argv[0]) try: for p in [3, 4]: if p < len(sys.argv): sys.argv[p] = convert(sys.argv[p]) + try: + # adjust page to number starting at 0 + sys.argv[5] = max(int(sys.argv[5]) - 1, 0) + except IndexError: + pass # page not specified r, c, sure = query(*sys.argv[1:]) - except BadValues: + except (BadValues, ValueError, TypeError): print ("Bad values passed as arguments.") usage() sys.exit(4) diff --git a/templates/about.html b/templates/about.html @@ -68,6 +68,8 @@ résultats dérivés d'un autre résultat mieux classé.</li> <li>Le système ne produira pas de résultats suivant la règle classique de la liaison supposée.</li> <li>Le système ne renvoie que les {{ pagesize }} meilleurs résulats.</li> +<li>Le système peut faire une interprétation trop stricte des règles classiques +(ça ne devrait pas arriver souvent).</li> </ul> <h2>Quels sont les résultats surnuméraires&nbsp;? (faux positifs)</h2> @@ -78,7 +80,8 @@ faire une rime acceptable (par exemple "reprendre" et "prendre").</li> <li>Le système autorisera des rimes pour l'œil abusives (vers la fin des résultats).</li> <li>Le système autorisera des rimes qui ne sont pas acceptables pour les règles -classiques. C'est un problème si vous essayez de les suivre.</li> +classiques, parce qu'il est trop tolérant quant à l'interprétation des règles +classiques.</li> </ul> @@ -162,6 +165,8 @@ derived from a previous result.</li> <li>The system will not accept rhymes for the classical rule of <em>liason supposée</em>.</li> <li>The system will only return the {{ pagesize }} best results.</li> +<li>The system may be too strict when enforcing classical rules (it shouldn't +happen very often, though).</li> </ul> <h2>Which results are unnecessary? (false positives)</h2> @@ -171,7 +176,7 @@ make a decent rhyme with it (eg. "reprendre" for "prendre").</li> <li>The system will provide results with a wrong syllable count.</li> <li>The system will provide abusive visual rhymes (at the end of the results).</li> <li>The system will provide rhymes which do not follow classical constraints, -which is a problem if you want to follow them.</li> +because its interpretation of them may be too liberal.</li> </ul> <h2>How are results sorted?</h2>