plint

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

commit 0dcd01ce67ec1791652c2d7783d7a4063be9983c
parent e3450cac6e652683a4917913e298d7d8178147e9
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sun, 10 Sep 2017 17:30:37 +0200

only allow hemistiches on elision when eliding

- fixes "Tatata ta verre un tata tatata"
- add unit test
- removes support for undocumented option "check_end_hemistiche"

Diffstat:
TODO | 3---
options.py | 1-
template.py | 5+++--
verse.py | 19++++++++++++-------
versetest.py | 15+++++++++++++--
5 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/TODO b/TODO @@ -1,8 +1,5 @@ "pays" and "paysage": "payse", "abbaye" -should be rejected (hemistiche is broken): -Tatata ta verre un tata tatata - -ue and -ues should be ambiguous (except g/q) Concluera l'examen. Venez, je vous invite ! ^ n'existe pas, mais vérifier diff --git a/options.py b/options.py @@ -7,7 +7,6 @@ default_options = { 'eye_tolerance_ok': True, 'repeat_ok': True, 'incomplete_ok': True, - 'check_end_hemistiche': True, 'check_occurrences': True, 'poor_eye_required': True, 'poor_eye_supposed_ok': False, diff --git a/template.py b/template.py @@ -11,12 +11,14 @@ from options import default_options class Pattern: - def __init__(self, metric, myid="", femid="", constraint=None): + def __init__(self, metric, myid="", femid="", constraint=None, hemistiches=None): self.metric = metric self.parse_metric() self.myid = myid self.femid = femid self.constraint = constraint + if hemistiches: + self.hemistiches = hemistiches def parse_metric(self): """Parse from a metric description""" @@ -43,7 +45,6 @@ class Template: 'ambiguous_ok': 'forbidden_ok', 'ambigu_ok': 'forbidden_ok', 'dierese': 'diaeresis', - 'verifie_fin_hemistiche': 'check_end_hemistiche', 'verifie_occurrences': 'check_occurrences', 'repetition_ok': 'repeat_ok', 'incomplet_ok': 'incomplete_ok', diff --git a/verse.py b/verse.py @@ -514,11 +514,12 @@ class Verse: for weight in chunk.get('weights', [0]): next_hemistiches = hemistiches if (len(hemistiches) > 0 and count + weight == hemistiches[0] and - is_vowels(chunk['text']) and (chunk['hemis'] == "ok" or not - self.template.options['check_end_hemistiche'] and - chunk['hemis'] != "cut")): - # we hemistiche here - next_hemistiches = next_hemistiches[1:] + is_vowels(chunk['text'])): + # need to try to hemistiche + if (chunk['hemis'] == "ok" or (chunk['hemis'] == "elid" and weight + == 0)): + # we hemistiche here + next_hemistiches = next_hemistiches[1:] current = dict(self.chunks[pos]) if 'weights' in current: current['weight'] = weight @@ -557,8 +558,9 @@ class Verse: return "cut" ending += self.chunks[pos+1]['text'] if (ending in sure_end_fem): + ok_if_elid = False if True in self.chunks[pos].get('elidable', [False]): - return "ok" # elidable final -e + ok_if_elid = True # check that this isn't a one-syllabe wourd (which is allowed) ok = False try: @@ -569,7 +571,10 @@ class Verse: pass if not ok: # hemistiche ends in feminine - return "fem" + if ok_if_elid: + return "elid" # elidable final -e, but only OK if actually elided + else: + return "fem" return "ok" def problems(self): diff --git a/versetest.py b/versetest.py @@ -80,8 +80,9 @@ class BadChars(unittest.TestCase): return False class Counts(unittest.TestCase): - def runCount(self, text, limit=12): - v = verse.Verse(text, template.Template(), template.Pattern(str(limit))) + def runCount(self, text, limit=12, hemistiches=None): + v = verse.Verse(text, template.Template(), template.Pattern(str(limit), + hemistiches=hemistiches)) v.parse() return v.possible @@ -158,6 +159,16 @@ class ExceptionCounts(Counts): f = self.runCount(text, limit=12) self.assertEqual(1, len(f)) self.assertEqual(self.getWeight(f[0]), 12) + + def testHemisticheElide(self): + # from "Les Trophées", José-Maria de Heredia + text1 = "Tatata ta verre un tata tatata" + text2 = "Tatata tata verre un tata tatata" + f1 = self.runCount(text1, limit=12, hemistiches=[6]) + self.assertEqual(0, len(f1)) + f2 = self.runCount(text2, limit=12, hemistiches=[6]) + self.assertEqual(1, len(f2)) + self.assertEqual(self.getWeight(f2[0]), 12) class AspiratedCounts(Counts): def testBaudelaire1half(self):