[RavenclawDev 237] [14] Tools: Added a folder remotely

tk@edam.speech.cs.cmu.edu tk at edam.speech.cs.cmu.edu
Wed Apr 4 15:48:59 EDT 2007


An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/ravenclaw-developers/attachments/20070404/dbe33b3f/attachment.html
-------------- next part --------------
Added: Tools/RCTaskViz/RCTaskViz.pl
===================================================================
--- Tools/RCTaskViz/RCTaskViz.pl	                        (rev 0)
+++ Tools/RCTaskViz/RCTaskViz.pl	2007-04-04 19:48:59 UTC (rev 14)
@@ -0,0 +1,129 @@
+#!/bin/perl
+
+use English;
+use strict;
+
+use GraphViz;
+
+my $g = GraphViz->new(directed => 1, layout => 'dot');
+
+die "usage: $0 {dialog task filename}$/" if !@ARGV;
+my $taskfile = shift;
+open(TASKFILE, $taskfile) || die "could not open taskfile '$taskfile'$/";
+
+my $MAX_LABEL = 55;
+my @defaultattr = (shape => 'box', style => 'filled');
+
+my $state = 1;
+my %agency;
+my $aref;
+my $subref;
+my $gref;
+my $root;
+my %hblah;
+my @ablah;
+my $agency_name;
+while(<TASKFILE>) {
+    if($state) {
+	if(/\/\*/) {
+	    $state = 0;
+	    next;
+	}
+    } else {
+	if(/\*\//) {
+	    $state = 1;
+	} else {
+	    next;
+	}
+    }
+    next if /^\s*\/\//;
+    if (/DEFINE_AGENCY\s*\(\s*([^,\s]+)/) {
+	#print "got DEFINE AGENCY$/";
+	$agency_name = $1;
+	$aref = $agency{$agency_name} = {};
+	$subref = ${$aref}{'subagents'} = [];
+	$gref = ${$aref}{'grammar'} = '';
+	$g->add_node($agency_name, 
+		     @defaultattr,
+		     shape => 'ellipse', 
+		     fillcolor => 'antiquewhite');
+    } elsif (/DEFINE_EXPECT_AGENT\s*\(\s*([^,\s]+)/) {
+	$agency_name = $1;
+	$aref = $agency{$agency_name} = {};
+	$subref = ${$aref}{'subagents'} = [];
+	$gref = ${$aref}{'grammar'} = '';
+	$g->add_node($agency_name, @defaultattr, fillcolor => 'aquamarine');
+    } elsif (/DEFINE_INFORM_AGENT\s*\(\s*([^,\s]+)/) {
+	$agency_name = $1;
+	$aref = $agency{$agency_name} = {};
+	$subref = ${$aref}{'subagents'} = [];
+	$gref = ${$aref}{'grammar'} = '';
+	$g->add_node($agency_name, @defaultattr, fillcolor => 'brown');
+    } elsif (/DEFINE_REQUEST_AGENT\s*\(\s*([^,\s]+)/) {
+	$agency_name = $1;
+	$aref = $agency{$agency_name} = {};
+	$subref = ${$aref}{'subagents'} = [];
+	$gref = ${$aref}{'grammar'} = '';
+	$g->add_node($agency_name, @defaultattr, fillcolor => 'chartreuse');
+    } elsif (/DEFINE_EXECUTE_AGENT\s*\(\s*([^,\s]+)/) {
+	$agency_name = $1;
+	$aref = $agency{$agency_name} = {};
+	$subref = ${$aref}{'subagents'} = [];
+	$gref = ${$aref}{'grammar'} = '';
+	$g->add_node($agency_name, @defaultattr, fillcolor => 'chocolate');
+    } elsif (/SUBAGENT\([^,]+,\s*([^,\s]+)/) {
+	#print "got SUBAGENT$/";
+	push @{$subref}, $1;
+	$g->add_node($1);
+	$g->add_edge($agency_name => $1);
+    } elsif (/DECLARE_DIALOG_TASK_ROOT\s*\([^,]+,\s*([^,\s]+)/) {
+	#print "got DECLARE DIALOG TASK ROOT$/";
+	$root = $1;
+    } elsif (/GRAMMAR_MAPPING\s*\(/) {
+	my $tail = $POSTMATCH;
+	#print "tail: '$tail'$/";
+	while($tail !~ /\)/) {
+	    if($tail =~ /\S/) {
+		$tail =~ s/\s*$//;
+		$tail =~ s/^\s*//;
+		$gref .= $tail.' ';
+		#print "adding '$tail'$/";
+	    }
+	    $tail = <TASKFILE>;
+	}
+	if($tail =~ /(\S+)\)/) {
+	    $gref .= $1;
+	    #print "adding '$1'$/";
+	}
+	if($gref) {
+	    if(length($gref) > $MAX_LABEL) {
+		$gref = substr($gref, 0, $MAX_LABEL-3).'...';
+	    }
+	    $g->add_node($agency_name, 
+			 'label'=>$agency_name.': '.$gref);
+	}
+    }
+}
+#print_agency($root);
+$g->as_canon('taskviz.txt');
+$g->as_png('taskviz.png');
+
+sub print_agency {
+    my $name = shift;
+    my $level = shift;
+
+    my $i = $level;
+    while($i--) {print "\t";}
+    print $name, $/;
+    my $aref = $agency{$name};
+    my $type;
+    my $val;
+    for(keys %{$aref}) {
+	next if $_ = 'subagents';
+	for($i = $level+1; $i; $i--) {print "\t";}
+	print "${_}: ${$aref}{$_}$/";
+    }
+    for(@{${$aref}{'subagents'}}) {
+	&print_agency($_, $level+1);
+    }
+}

Added: Tools/RCTaskViz/README
===================================================================
--- Tools/RCTaskViz/README	                        (rev 0)
+++ Tools/RCTaskViz/README	2007-04-04 19:48:59 UTC (rev 14)
@@ -0,0 +1,12 @@
+This program parses the task structure. It produces a png of the graph
+as well as the canonical text version compatible with AT&T's
+Graphvis. In order to run it you'll need AT&T's graphviz and the
+GraphVis perl module.
+
+Run with the task cpp file as an argument, as in
+
+$ ./RCTaskViz.pl ../../Agents/TeamTalkDM/TeamTalkDialogTask.cpp
+
+The png will be produced in that directory as 'taskviz.png' and the
+AT&T compatible text format will be produced as 'taskviz.txt'.
+

Added: Tools/RCTaskViz/taskviz-example.png
===================================================================
(Binary files differ)


Property changes on: Tools/RCTaskViz/taskviz-example.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream


More information about the Ravenclaw-developers mailing list