#!/usr/bin/perl -w # # Alex Linke # # A short introduction on the filter's usage can be found here: # http://www.use-strict.de/software/fst2dot.html # # The filter is available under the terms of the MIT license: # http://www.use-strict.de/files/software/LICENSE.txt # # Changelog: # 2009-10-10 (0.2) -- Updated to new fst-print(1) format (SFST >= 1.3) # -- Various cleanups and tiny improvements # 2006-05-17 (0.1) -- Initial release # use strict; my $VERSION = "0.2"; die "fst2dot v$VERSION\n\nusage: $0 [file|-]\n" if (scalar(@ARGV) != 1); my $input = $ARGV[0] eq '-' ? '/dev/stdin' : $ARGV[0]; open FH, $input or die "$input: $!\n"; my @nodes; foreach my $line () { chomp($line); # i.e.: "0 1 B B" if ($line =~ /^(\d+)\t(\d+)\t([^\s]+)\t([^\s]+)$/) { my $label = $3 eq $4 ? $3 : "$3:$4"; push @nodes, qq(\n\t$1 -> $2 [label="$label"];); } elsif ($line =~ /^(\d+)$/) { push @nodes, qq(\n\t$1 [shape="doublecircle"]); } else { die "Error parsing line: '$line'\n"; } } close FH; die "No nodes extracted\n" unless scalar(@nodes); @nodes = sort(@nodes); print <