1#!/usr/bin/env perl 2 3use strict; 4 5my $nstates; 6while (<>) { 7 chomp; 8 s/#.*$//; 9 next if /^$/; 10 11 if (/FSG_BEGIN (\S+)/) { 12 print "digraph $1 {\n\trankdir=LR;\n\t"; 13 } 14 elsif (/NUM_STATES (\d+)/) { 15 $nstates = $1; 16 } 17 elsif (/START_STATE (\d+)/) { 18 } 19 elsif (/FINAL_STATE (\d+)/) { 20 my $end = $1; 21 22 print "\tnode [shape=circle];"; 23 for (my $i = 0; $i < $nstates; ++$i) { 24 print " $i" unless $i == $end; 25 } 26 print ";\n\tnode [shape=doublecircle]; $end;\n\n"; 27 } 28 elsif (/TRANSITION/) { 29 my (undef, $from, $to, $weight, $word) = split; 30 31 my $label; 32 if ($weight != 1.0 and defined($word)) { 33 $label = sprintf "%s/%.2f", $word, $weight; 34 } 35 elsif ($weight != 1.0) { 36 $label = sprintf "%.2f", $weight; 37 } 38 elsif ($word) { 39 $label = $word; 40 } 41 print "\t$from -> $to [label=\"$label\"];\n"; 42 } 43} 44print "}\n"; 45