The fstclosure
command implements Kleene closure/Kleene star. That is, it converts a set of strings into the set of strings consisting of zero or more repetitions of strings in the input set. The command can also be used to emulate the “+” operator with --closure_plus
flag.
For example, given a simple automaton representing the regular expression a(b|c)
:
========================
Initial automaton
fstprint --osymbols=words.txt --isymbols=words.txt L.fst
0 1 a a
1 2 b b
1 3 c c
2 4 <eps> <eps>
3 4 <eps> <eps>
4
Running fstclosure
produces (a(b|c))*:
========================
Run fstclosure for Kleene Star
fstclosure L.fst Lstar.fst
fstprint --osymbols=words.txt --isymbols=words.txt Lstar.fst
5 0 <eps> <eps>
5
0 1 a a
1 2 b b
1 3 c c
2 4 <eps> <eps>
3 4 <eps> <eps>
4 0 <eps> <eps>
4
========================
While running fstclosure --closure_plus
produces (a(b|c))+.
========================
Run fstclosure for Kleene plus
fstclosure --closure_plus L.fst Lplus.fst
fstprint --osymbols=words.txt --isymbols=words.txt Lplus.fst
0 1 a a
1 2 b b
1 3 c c
2 4 <eps> <eps>
3 4 <eps> <eps>
4 0 <eps> <eps>
4
If you didn’t already know, you can display transducers graphically using
fstdraw
and the dot program. For example:fstdraw <FST file> | dot -Tx11
. This will pop up a window displaying the transducer. If you want to save the image, you can use-Tpng
or-Tpdf
(among other options) and then redirect it to a file. For example:fstdraw <FST file> | dot -Tpng > automaton.png
.Nice. Is it possible to get generating the pictures into demo.sh? Incidentally to run Jacob’s demo, copy it to your demo directory with
cp -R /home/mr249/kaldi-master/egs/rm/s5-jnc76/demo/fstclosure .
and then run it withsource demo.sh
.