HFST: Better Cola Machine

We exemplify the use of HFST command line tools with an example taken from Beesley & Karttunen (Finite-State Morphology, pages 466 - 469). See the solution in the book for more information on the example. FORMAT is the implementation format that is used. The solution given here can also be executed with a single script.

We have a set of regular expressions that we want to compile into transducers and compose those transducers. We start with a simple identity transducer [?] named Solution that can be used as an initial value for the solution because for any transducer A, [?] .o. A is equivalent to A.

echo "[?]" | hfst-regexp2fst -f $FORMAT > Solution

We then compile each regular expression into a transducer and compose the current value of Solution with that transducer and set the result of the composition as a new value for Solution.

for i in '[ D -> N^2, Q -> N^5 ]' \
         'N^5/\N @-> ...  "[COLA]"' \
         'N -> 0 || _ $"[COLA]"' \
         'N^2/\N @-> ...  D' \
         'N -> 0 || _ $D'; do
  echo $i | hfst-regexp2fst -f $FORMAT | hfst-compose -1 Solution > TMP;
  mv TMP Solution;

We finally minimize the result.

hfst-minimize Solution > BetterColaMachine

-- ErikAxelson - 2011-10-20