plint

French poetry validator (local mirror of https://gitlab.com/a3nm/plint)
git clone https://a3nm.net/git/plint/
Log | Files | Refs | README

commit f681c6f9d3c578c81e27a8aa5e7e17cda3bce8e5
parent e0e5c2b870b696ed73b597b70ae074b5c974fb8b
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue, 27 Oct 2020 20:58:32 +0100

Merge branch 'master' of gitlab.com:a3nm/plint into master

Diffstat:
plint/chunk.py | 39+++++++++++++++++++++++++++++----------
plint/test_data/racine_phedre | 2+-
2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/plint/chunk.py b/plint/chunk.py @@ -25,10 +25,15 @@ class Chunk: self.text_pron = None self.elision = None self.no_hiatus = None + self.causes_hiatus = None self.elidable = None self.word_end = False - # TODO What is a weight without s? + + # self.weight contains the weight attributed to the chunk when fitting + # all chunks of the verse (function fit in chunks.py) to respect the + # metric self.weight = None + self.verse = verse def __repr__(self): @@ -185,7 +190,7 @@ class Chunk: def elide_vowel_problems(self, chunk_group): if self.elision is None: - self.elision = elision_wrap(chunk_group) + self.elision_wrap(chunk_group) def process_y_cases(self, previous_chunk, next_chunk): new_word_from_chunk = [] @@ -274,7 +279,7 @@ class Chunk: or (only_two_parts and previous_chunk.text == 'e' and self.text == 't')): # it happens if the next word is not marked no_hiatus # and starts with something that causes elision - if all(next_chunk.elision) and next_chunk.no_hiatus is None: + if next_chunk.causes_hiatus and next_chunk.no_hiatus is None: self.error = "hiatus" next_chunk.error = "hiatus" @@ -594,6 +599,27 @@ class Chunk: print(str(self.weight) + ' ' + ' '.join(self.make_query(chunks_before, chunks_after)), file=output_file) + # set self.elision and self.causes_hiatus + def elision_wrap(self, chunk_group): + first_letter = common.remove_punctuation(chunk_group[0].original.strip()) + word = ''.join(chunk.text for chunk in chunk_group) + original_word = ''.join(chunk.original for chunk in chunk_group) + self.elision = elision(word, + original_word, + first_letter == first_letter.upper()) + + self.causes_hiatus = False + if is_vowels(word[0]): + # "oui, oui" often occurs + if word not in ["oui", "ouis"]: + self.causes_hiatus = True + elif word[0] == 'h': + result = list(map((lambda s: not s), + haspirater.lookup(normalize(original_word)))) + if len(result) == 1 and True in result: + self.causes_hiatus = True + + LETTERS = { 'f': 'effe', @@ -612,13 +638,6 @@ LETTERS = { } -def elision_wrap(chunk_group): - first_letter = common.remove_punctuation(chunk_group[0].original.strip()) - temp = elision(''.join(chunk.text for chunk in chunk_group), - ''.join(chunk.original for chunk in chunk_group), - first_letter == first_letter.upper()) - return temp - def elision(word, original_word, was_cap): if word.startswith('y'): diff --git a/plint/test_data/racine_phedre b/plint/test_data/racine_phedre @@ -157,7 +157,7 @@ Ah, seigneur ! si votre heure est une fois marquée, Le ciel de nos raisons ne sait point s’informer. Thésée ouvre vos yeux en voulant les fermer ; Et sa haine irritant une flamme rebelle, -Prête à son ennemi une grâce nouvelle. +Prête à son ennemie une grâce nouvelle. Enfin d’un chaste amour pourquoi vous effrayer ? S’il a quelque douceur, n’osez-vous l’essayer ? En croirez-vous toujours un farouche scrupule ?