Download programs/fsg2dot.pl from camenduru/pocketsphinx: direct link, hf CLI and curl.
- Browser
- Download file 856 Bytes
-
https://huggingface.co/camenduru/pocketsphinx/resolve/main/programs/fsg2dot.pl
- Command line
-
hf download hf://camenduru/pocketsphinx/programs/fsg2dot.pl
-
curl -L -o fsg2dot.pl https://huggingface.co/camenduru/pocketsphinx/resolve/main/programs/fsg2dot.pl
856 Bytes
| #!/usr/bin/env perl | |
| use strict; | |
| my $nstates; | |
| while (<>) { | |
| chomp; | |
| s/#.*$//; | |
| next if /^$/; | |
| if (/FSG_BEGIN (\S+)/) { | |
| print "digraph $1 {\n\trankdir=LR;\n\t"; | |
| } | |
| elsif (/NUM_STATES (\d+)/) { | |
| $nstates = $1; | |
| } | |
| elsif (/START_STATE (\d+)/) { | |
| } | |
| elsif (/FINAL_STATE (\d+)/) { | |
| my $end = $1; | |
| print "\tnode [shape=circle];"; | |
| for (my $i = 0; $i < $nstates; ++$i) { | |
| print " $i" unless $i == $end; | |
| } | |
| print ";\n\tnode [shape=doublecircle]; $end;\n\n"; | |
| } | |
| elsif (/TRANSITION/) { | |
| my (undef, $from, $to, $weight, $word) = split; | |
| my $label; | |
| if ($weight != 1.0 and defined($word)) { | |
| $label = sprintf "%s/%.2f", $word, $weight; | |
| } | |
| elsif ($weight != 1.0) { | |
| $label = sprintf "%.2f", $weight; | |
| } | |
| elsif ($word) { | |
| $label = $word; | |
| } | |
| print "\t$from -> $to [label=\"$label\"];\n"; | |
| } | |
| } | |
| print "}\n"; | |