francescomecca.eu/correggi_accenti.py
2017-03-20 00:51:47 +01:00

52 lines
1.5 KiB
Python

import re
letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y', 'z']
symbols = ['"','#','`','%','&','\'','(',')','*','+',',','-','.','/', '\n']
errDict = {'á': 'à', 'í': 'ì', 'ó': 'ò', 'ú': 'ù', 'É': 'È'}
# printl = print ('what')
def main (filename):
# you could write better things
with open (filename, "r") as f:
wordsAll = f.read ()
# with open (filename + '.corretto.md' , "w") as f:
with open (filename , "w") as f:
for w in wordsAll.split (' '):
# á ó é ú í
# check verbo essere
try:
if w[0] == 'é':
w.replace ('é', 'è')
<<<<<<< HEAD
# if w[0] == 'e' and w[1] == '`':
# w = w.replace ('e`', 'è')
# w = w[1:]
=======
if w[0] == 'e' and w[1] == '`':
w.replace ('e`', 'è')
w = w[1:]
>>>>>>> e76363a87578890361a3133973252a6b01399c47
except:
pass
try:
# check vocali gravi
w = [e if e not in errDict else errDict[e] for e in w]
w = ''.join (w)
except:
# ugly, check len
pass
if '' in w:
w = w.replace ('', 'po\'')
f.write (w + ' ')
# print (w + ' ', end='')
f.write ('\n')
if __name__ == '__main__':
import sys
for arg in sys.argv[1:]:
main (arg)