plint

French poetry validator
git clone https://a3nm.net/git/plint/
Log | Files | Refs | README

commit 8b48d874b21135edb349c43e56e46956de5bc48c
parent 81e9f96d1b1805b2895539ee37fa338c6e91257b
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat,  7 Jul 2012 01:32:26 +0200

add check_end_hemistiche

Diffstat:
hemistiches.py | 16+++++++++-------
template.py | 6+++++-
2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/hemistiches.py b/hemistiches.py @@ -30,21 +30,22 @@ def check_spaces(align, pos): # hemistiche falls at the middle of a word return "cut" -def check_hemistiche(align, pos, hem): +def check_hemistiche(align, pos, hem, check_end_hemistiche): if pos >= len(align): # not enough syllabes for hemistiche return ("bad", pos) if hem == 0: # hemistiche should end here, check that this is a word boundary - if (align2str(align[:pos+1]).split()[-1]) in forbidden_hemistiche: - return ("forbidden", pos) + if check_end_hemistiche: + if (align2str(align[:pos+1]).split()[-1]) in forbidden_hemistiche: + return ("forbidden", pos) return (check_spaces(align, pos), pos) if hem < 0: # hemistiche falls at the middle of a vowel cluster return ("cut", pos) # skip consonants if not isinstance(align[pos], tuple): - return check_hemistiche(align, pos +1, hem) + return check_hemistiche(align, pos +1, hem, check_end_hemistiche) # hemistiche is there, we should not have a feminine ending here if hem == 1: if pos + 1 >= len(align): @@ -60,9 +61,10 @@ def check_hemistiche(align, pos, hem): if not ok: # hemistiche ends in feminine return ("fem", pos) - return check_hemistiche(align, pos+1, hem - align[pos][1]) + return check_hemistiche(align, pos+1, hem - align[pos][1], + check_end_hemistiche) -def check_hemistiches(align, hems): +def check_hemistiches(align, hems, check_end_hemistiche): """From a sorted list of distinct hemistiche positions, return a dictionary which maps each position to the status of this hemistiche""" @@ -71,7 +73,7 @@ def check_hemistiches(align, hems): pos = 0 h2 = 0 for h in hems: - r, pos = check_hemistiche(align, pos, h-h2) + r, pos = check_hemistiche(align, pos, h-h2, check_end_hemistiche) h2 = h result[h] = r return result diff --git a/template.py b/template.py @@ -47,6 +47,7 @@ class Template: self.pattern_line_no = 0 self.forbidden_ok = False self.normande_ok = True + self.check_end_hemistiche = True self.diaeresis = "classical" self.mergers = [] self.load(string) @@ -70,6 +71,8 @@ class Template: self.diaeresis = value if value not in ["permissive", "classical"]: raise ValueError + elif key == "check_end_hemistiche": + self.check_end_hemistiche = str2bool(value) else: raise ValueError @@ -136,7 +139,8 @@ class Template: possible = [] return errors, pattern possible = list(map((lambda p: (p[0], p[1], - check_hemistiches(p[0], pattern.hemistiches))), possible)) + check_hemistiches(p[0], pattern.hemistiches, self.check_end_hemistiche))), + possible)) possible = map((lambda x: (self.rate(pattern, x), x)), possible) possible = sorted(possible, key=(lambda x: x[0]))