up typo correction
This commit is contained in:
parent
73ca5a580e
commit
dd196d7392
3 changed files with 11 additions and 18 deletions
Binary file not shown.
|
@ -21,7 +21,16 @@ def corriger_typo(contenu):
|
||||||
|
|
||||||
# Corriger les entêtes orgmode (remplacer ": " par ":")
|
# Corriger les entêtes orgmode (remplacer ": " par ":")
|
||||||
contenu = re.sub(r"^(#\+[A-Z_]+): ", r"\1:", contenu, flags=re.MULTILINE)
|
contenu = re.sub(r"^(#\+[A-Z_]+): ", r"\1:", contenu, flags=re.MULTILINE)
|
||||||
|
# Corriger les espaces manquants autour de certaines ponctuations
|
||||||
|
contenu = re.sub(r"([.,;:!?])( )?", r"\1 ", contenu)
|
||||||
|
contenu = re.sub(r"( )([.,;:!?])", r" \2", contenu)
|
||||||
|
# replace demiquatratin by full quadratin
|
||||||
|
contenu = contenu.replace('–', '—')
|
||||||
|
contenu = contenu.replace(' ?', chr(160)+"?")
|
||||||
|
contenu = contenu.replace(' !', chr(160)+"!")
|
||||||
|
contenu = contenu.replace(' »', chr(160)+"»")
|
||||||
|
contenu = contenu.replace('« ', "«"+chr(160))
|
||||||
|
contenu = contenu.replace('y’a', "y a")
|
||||||
return contenu
|
return contenu
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,22 +53,6 @@ def comparer_textes(texte_original, texte_corrige):
|
||||||
return nb_maj, nb_sauts, nb_entetes, nb_espaces
|
return nb_maj, nb_sauts, nb_entetes, nb_espaces
|
||||||
|
|
||||||
|
|
||||||
# Corriger les espaces manquants autour de certaines ponctuations
|
|
||||||
contenu_corrige = re.sub(r"([.,;:!?])( )?", r"\1 ", contenu_corrige)
|
|
||||||
contenu_corrige = re.sub(r"( )([.,;:!?])", r" \2", contenu_corrige)
|
|
||||||
# replace demiquatratin by full quadratin
|
|
||||||
contenu_corrige = contenu_corrige.replace('–', '—')
|
|
||||||
contenu_corrige = contenu_corrige.replace(' ?', chr(160)+"?")
|
|
||||||
contenu_corrige = contenu_corrige.replace(' !', chr(160)+"!")
|
|
||||||
contenu_corrige = contenu_corrige.replace(' »', chr(160)+"»")
|
|
||||||
contenu_corrige = contenu_corrige.replace('« ', "«"+chr(160))
|
|
||||||
contenu_corrige = contenu_corrige.replace('y’a', "y a")
|
|
||||||
|
|
||||||
nb_espaces = len(re.findall(r"([.,;:!?])( )?", contenu)) - len(re.findall(r"([.,;:!?])( )?", contenu_corrige)) + len(re.findall(r"( )([.,;:!?])", contenu)) - len(re.findall(r"( )([.,;:!?])", contenu_corrige))
|
|
||||||
if nb_espaces > 0:
|
|
||||||
print(f" Ajout d'espaces autour de certaines ponctuations : {nb_espaces} modification(s)")
|
|
||||||
|
|
||||||
|
|
||||||
def sauvegarder_si_modifie(contenu_corrige, nb_maj, nb_sauts, nb_espaces):
|
def sauvegarder_si_modifie(contenu_corrige, nb_maj, nb_sauts, nb_espaces):
|
||||||
# Faire un rapport des modifications apportées
|
# Faire un rapport des modifications apportées
|
||||||
if nb_maj == 0 and nb_sauts == 0 and nb_espaces == 0:
|
if nb_maj == 0 and nb_sauts == 0 and nb_espaces == 0:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from format_typo import corriger_typo
|
||||||
|
|
||||||
def test_correction_entetes_org(self):
|
def test_correction_entetes_org(self):
|
||||||
texte_avec_entetes = """* chapitre 1 :titre:
|
texte_avec_entetes = """* chapitre 1 :titre:
|
||||||
* chapitre 2 : titre :"""
|
* chapitre 2 : titre : """
|
||||||
texte_corrige = corriger_typo(texte_avec_entetes)
|
texte_corrige = corriger_typo(texte_avec_entetes)
|
||||||
self.assertEqual(texte_corrige, """* chapitre 1 :titre:
|
self.assertEqual(texte_corrige, """* chapitre 1 :titre:
|
||||||
* chapitre 2 :titre:""")
|
* chapitre 2 :titre:""")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue