44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
|
import re
|
||
|
|
||
|
sep = r"[.\-/]"
|
||
|
|
||
|
|
||
|
def convertir_point_median(texte):
|
||
|
versions = [texte]
|
||
|
# Règles à 3 composantes
|
||
|
regles3 = [fr"(\w+){sep}(\w+[es]*){sep}([es]+)",
|
||
|
fr"([td]eur){sep}([td]rice){sep}([s]+)",
|
||
|
fr"(eur){sep}(ice|euse){sep}([s]+)",
|
||
|
fr"(er){sep}(ère){sep}([s]+)",
|
||
|
fr"([fs]){sep}([fs]{2}e){sep}([s]+)",
|
||
|
fr"([eo][lnt]){sep}([eo]?[lnt]+e){sep}([s]+)"]
|
||
|
for r in regles3:
|
||
|
versions.append(re.sub(r, r"\1·\2·\3", versions[-1]))
|
||
|
# Règles à 2 composantes
|
||
|
regles2 = [fr"(\w+){sep}([es]+)",
|
||
|
fr"([td]eur[s]?){sep}([td]?rice[s]?)",
|
||
|
fr"(eur[s]?){sep}(euse[s]?|ice[s]?)",
|
||
|
fr"(eux|el){sep}(elle[s]?|euse[s]?|le[s]?)",
|
||
|
fr"(aux|al){sep}(ale[s]?)",
|
||
|
fr"(er[s]?){sep}(ère[s]?)",
|
||
|
fr"([s]){sep}([s]{2}e[s]?)",
|
||
|
fr"([eo][flnt][s]?){sep}([eo]?[flnt]+e[s]?)",
|
||
|
fr"(\w+e){sep}(\w+a)",
|
||
|
fr"(\w+t){sep}(te)"]
|
||
|
for r in regles2:
|
||
|
versions.append(re.sub(r, r"\1·\2", versions[-1]))
|
||
|
# Règles avec des parenthèses
|
||
|
reglesp = [r"(\w+)[\(]([es]+)[\)]",
|
||
|
r"([td]eur[s]?)[\(]([td]?rice[s]?)[\)]",
|
||
|
r"(eur[s]?)[\(](euse[s]?|ice[s]?)[\)]",
|
||
|
r"(eux|el)[\(](elle[s]?|euse[s]?|le[s]?)[\)]",
|
||
|
r"(aux|al)[\(](ale[s]?)[\)]",
|
||
|
r"(er[s]?)[\(](ère[s]?)[\)]",
|
||
|
r"([s])[\(]([s]{2}e[s]?)[\)]",
|
||
|
r"([eo][flnt][s]?)[\(]([eo]?[flnt]+e[s]?)[\)]",
|
||
|
r"(\w+e)[\(](\w+a)[\)]",
|
||
|
r"(\w+t)[\(](te)[\)]"]
|
||
|
for r in reglesp:
|
||
|
versions.append(re.sub(r, r"\1·\2", versions[-1]))
|
||
|
return versions[-1]
|