drime

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

commit 208db0bba699fd529d4b7bc871dfa5e2ccc54b2c
parent f82066fea0d4481b43b3d0cfa0218d873bd77610
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat, 21 Dec 2013 00:41:10 +0100

use vowels.py from plint

Diffstat:
README | 6+++---
metric.py | 8+++++---
vowels.py | 49-------------------------------------------------
3 files changed, 8 insertions(+), 55 deletions(-)

diff --git a/README b/README @@ -15,9 +15,9 @@ drime requires a working Python3 installation. drime requires the haspirater module <http://gitorious.org/haspirater/>. Just place the "haspirater.py" and "haspirater.json" file in the same folder as the -other files. It also requires the "rhyme.py" and "options.py" modules from -plint <http://gitorious.org/plint/> that you should put in the same folder, and -also "frhyme.py" (see plint's documentation). +other files. It also requires the "rhyme.py", "options.py" and "vowels.py" +modules from plint <http://gitorious.org/plint/> that you should put in the same +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. diff --git a/metric.py b/metric.py @@ -4,9 +4,11 @@ # this file is pretty generic, because it's part of a larger project I haven't # released yet, i should clean this up someday +# TODO: use verse.py from plint instead + import re from common import normalize, is_vowels, consonants, sure_end_fem -from vowels import possible_weights +from vowels import possible_weights_approx import haspirater def annotate_aspirated(word): @@ -40,9 +42,9 @@ def fit(chunks, pos, left): # actually, this will have an influence on the rhyme's gender weights = [0, 1] else: - weights = possible_weights(chunks[pos]) + weights = possible_weights_approx(chunks[pos]) else: - weights = possible_weights(chunks[pos]) + weights = possible_weights_approx(chunks[pos]) result = [] for weight in weights: # combine all possibilities diff --git a/vowels.py b/vowels.py @@ -1,49 +0,0 @@ -#!/usr/bin/python -#coding: utf-8 - -"""Compute the number of syllabes taken by a vowel chunk""" - -from common import strip_accents - -def contains_trema(chunk): - """Test if a string contains a word with a trema""" - for x in ['ä', 'ï', 'ö', 'ü', 'ÿ']: - if x in chunk: - return True - return False - -def possible_weights(chunk): - """Return the possible number of syllabes taken by a vowel chunk""" - if len(chunk) == 1: - return [1] - # old spelling and weird exceptions - if chunk in ['ouï']: - return [2] - if chunk in ['eüi', 'aoû']: - return [1] - if contains_trema(chunk): - return [2] - chunk = strip_accents(chunk, True) - if chunk in ['ai', 'ou', 'eu', 'ei', 'eau', 'eoi', 'eui', 'au', 'oi', - 'oie', 'œi', 'œu', 'eaie', 'aie', 'oei', 'oeu', 'ea', 'ae', 'eo', - 'eoie', 'oe', 'eai', 'eue', 'aa', 'oo', 'ee', 'ii', 'aii', - 'yeu', 'ye']: - return [1] - for x in ['oa', 'ea', 'eua', 'ao', 'euo', 'ua', 'uo', 'yo', 'yau']: - if x in chunk: - return [2] - # beware of "déesse" - if chunk == 'ée': - return [1, 2] - if chunk[0] == 'i': - return [1, 2] - if chunk[0] == 'u' and (strip_accents(chunk[1]) in ['i', 'e']): - return [1, 2] - if chunk[0] == 'o' and chunk[1] == 'u' and len(chunk) >= 3 and strip_accents(chunk[2]) in ['i', 'e']: - return [1, 2] - if 'é' in chunk or 'è' in chunk: - return [2] - - # TODO hmm - return [1, 2] -