Fstclosure

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

The language a(b|c)

The language a(b|c)

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
========================

(a(b|c))*

The language (a(b|c))*

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

(a(b|c))+

The language (a(b|c))+

2 thoughts on “Fstclosure

  1. Jacob Collard Post author

    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.

  2. Mats Rooth

    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 with source demo.sh.

Leave a Reply