plint

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

commit dbd295c4969b36ec4e14c3282bc0d83c72110405
parent b793213e9354089bd56be0daa31d42bf4a267cc2
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue,  2 Aug 2016 09:50:40 +0200

Merge branch 'master' of a3nm.net:git/plint

Diffstat:
TODO | 4++++
common.py | 2++
verse.py | 4++--
versetest.py | 17+++++++++++++++++
4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/TODO b/TODO @@ -8,6 +8,10 @@ Concluera l'examen. Venez, je vous invite ! /usr/lib/python3.5/re.py:203: FutureWarning: split() requires a non-empty pattern match. Remerciez-le plutôt, et félicitez-vous + +- fuzz testing +- log exceptions separately for plint_web + - faire marcher oublieux - change additions to give numerical syllable count - document expected errors of test.sh and commit necessary files diff --git a/common.py b/common.py @@ -52,6 +52,8 @@ def rm_punct(text, rm_all=False, rm_apostrophe=False, rm_apostrophe_end=True): if rm_apostrophe_end: text = re.sub("'*$", "", text) # apostrophes at end of line text = re.sub("[‒–—―⁓⸺⸻]", " ", text) # no weird dashes + text = re.sub("^--*\s", " ", text) # no isolated dashes + text = re.sub("--*\s", " ", text) # no trailing dashes #TODO rather: keep only good chars if not rm_all: diff --git a/verse.py b/verse.py @@ -351,12 +351,12 @@ class Verse: cs = re.split(self.hyphen_regexp, word) miss = "" for i in range(len(cs)): - if re.match("^-*$", cs[i]): + if re.match("^-*$", cs[i]) or re.match("^ *$", cs[i]): if len(pre_chunks2) > 0: pre_chunks2[-1] = (pre_chunks2[-1][0], pre_chunks2[-1][1] + cs[i]) continue else: - miss = cs[i] + miss += cs[i] continue if is_consonants(normalize(cs[i])): pre_chunks2.append((False if i < len(cs) - 1 else True, miss + cs[i])) diff --git a/versetest.py b/versetest.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 +import common import template import diaeresis import common @@ -26,6 +27,22 @@ class SanityCheck(unittest.TestCase): v.parse() self.assertEqual(text, v.line) + def testLeadingSpaceHyphenVowel(self): + text = " -a" + v = verse.Verse(text, template.Template(), template.Pattern("12")) + v.parse() + self.assertEqual(text, v.line) + + def testLeadingSpaceHyphenConsonant(self): + text = " -c" + v = verse.Verse(text, template.Template(), template.Pattern("12")) + v.parse() + self.assertEqual(text, v.line) + + def testLoneHyphens(self): + text = " - - -- -- - - - --" + self.assertEqual(common.normalize(text), "") + class Eliminate(unittest.TestCase): def testEliminateOneGue(self): text = "gue"