#!/usr/bin/perl ################################################# # # Takes a BN net and outputs a dot formatted list # of nodes and edges # # usage: dot-form.pl filename.net # # by Moises Goldszmidt # ################################################# ### get the header straight print "digraph G \{ \n \n"; print " size=\"7.5,10\"; \n"; print " ratio=compress; \n"; print " center=true; \n"; print " fontname=Helvetica; \n"; print " orientation=portrait; \n"; $i = 0; while (<>) { # if (/var '(\w*)\s/){ if (/var '([\w-]*)\s/){ $node[$i] = $1; if( (index $1, "_H") == 0 ) { print "node_$i [label = \"$1\",style = \"filled\", color = \"black\"] \n"; } else { print "node_$i [label = \"$1\"] \n"; } $ref{$1} = $i; $i = $i+1; } # elsif (/parents '(\w*)\s* '\(([\w*\s*]*)\)/){ elsif (/parents '([\w-]*)[\s]* '\(([\w-\s]*)/){ $child = $ref{$1}; @par_list = split(/\s+/,$2); foreach $j (@par_list){ $parent = $ref{$j}; print "node_$parent->node_$child \n"; } } } print "\n \} \n";