tef-innu

Transducteur à états finis de l’innu
git clone git://git.asteride.xyz/tef-innu.git
Journaux | Fichiers | Références

commit 4c72357156635d7e48dba51f481e3d34171f5855
parent 2128e48fee6f1621305b6f28143e0529e9fccedc
Auteur: Loïc Daignault-Pichette <loic@asteride.xyz>
Date:   Sun, 28 Sep 2025 22:30:10 -0400

[inf] Générer l’extension d’un transducteur

Diffstat:
MMakefile | 9+++++++--
Abin/extension.py | 42++++++++++++++++++++++++++++++++++++++++++
2 fichiers modifiés, 49 insertions(+), 2 suppressions(-)

diff --git a/Makefile b/Makefile @@ -1,10 +1,12 @@ .SUFFIXES: -.SUFFIXES: .xfst .fst .err .ech .att +.SUFFIXES: .xfst .fst .err .ech .att .ext .xfst.fst: foma -e "source $<" -e "save stack $@" -s .fst.att: foma -e "load $<" -e "write att $@" -s +.att.ext: + bin/extension.py "$<" | sort > "$@" .ech.err: bin/inclusion.sh "$$(echo "$<" | sed 's/.ech$$/.fst/')" "$<" | tee "$@" @@ -18,5 +20,8 @@ ajouter_ech: bib/ajouter_ech.fst net: # Supprimer tous les fichiers .fst - find . -type f -name '*.fst' -o -name '*.err' -o -name '*.att' | \ + find . -type f -name '*.fst' -o \ + -name '*.err' \ + -o -name '*.att' \ + -o -name '*.ext' | \ xargs rm diff --git a/bin/extension.py b/bin/extension.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# +# tout.py -- Générer toutes les paires d’un transducteur +# +# $1 - Chemin vers un transducteur (.att) + +import sys + +etats = [] # arc, sup, inf +final = None +with open(sys.argv[1], 'r') as fichier: + etat = None + for ligne in fichier: + champs = [champ.strip() for champ in ligne.split('\t') if champ] + if len(champs) == 1: + final = int(champs[0]) + break + if champs[2] == "@0@": + champs[2] = "" + if champs[3] == "@0@": + champs[3] = "" + if champs[0] != etat: + etats.append([]) + etats[-1].append((int(champs[1]), champs[2], champs[3])) + etat = champs[0] + +pile = [(0, 0, 0, 0)] # etat, arc, isup, iinf +chaine_sup = "" +chaine_inf = "" + +while pile: + etat, arc, isup, iinf = pile.pop() + if etat == final: + print(chaine_sup + "\t" + chaine_inf) + continue + if len(etats[etat]) != arc + 1: # pas encore de dernier arc + pile.append((etat, arc + 1, isup, iinf)) + chaine_sup = chaine_sup[0:isup] + etats[etat][arc][1] + chaine_inf = chaine_inf[0:iinf] + etats[etat][arc][2] + isup = isup + len(etats[etat][arc][1]) + iinf = iinf + len(etats[etat][arc][2]) + pile.append((etats[etat][arc][0], 0, isup, iinf))