vendredi 3 juillet 2020

Infinite loop when trying to split words into syllables

I was working on a program to split words into syllables. One of the rules is making me sad since I think all should work fine, but it actually loops infinitely:

def division_R2(line):
    r2a = re.search(patron_R2a, line)
    while r2a:
        linea = re.sub(patron_R2a ,r2a.group(1)+'-'+r2a.group(2)+r2a.group(8), linea, 1)
        r2a = re.search(patron_R2a, line)
    #until here it works fine.
    r2b = re.search(patron_R2b, line)
    while r2b:
        #if true -> infinite loop
        if not (patron_ch.fullmatch(r2b.group(2)+r2b.group(3)) or patron_ll.fullmatch(r2b.group(2)+r2b.group(3))):
            line = re.sub(patron_R2b ,r2b.group(1)+r2b.group(2)+'-'+r2b.group(3)+r2b.group(4), line, 1)
        r2b = re.search(patron_R2b, line)
        
    return line

If I remove the if condition and indent it correctly, this doesn't happen, but then it breaks up the words inaccurately.

Aucun commentaire:

Enregistrer un commentaire