From 19b537a142c127dd2c1d9a40a7999714f9d2175d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 2 Mar 2007 00:05:18 +0000 Subject: Work towards Action serialization. Made edge length in dot graphs (from machina2dot) correspond to node duration to make automaton diagram map closer to music notation. git-svn-id: http://svn.drobilla.net/lad/machina@341 a436a847-0d15-0410-975c-d299462d15a1 --- util/machina2dot.py | 62 ++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'util') diff --git a/util/machina2dot.py b/util/machina2dot.py index bbf9725..f4e67ec 100755 --- a/util/machina2dot.py +++ b/util/machina2dot.py @@ -16,56 +16,60 @@ parser.parse_into_model(model, "file:" + sys.argv[1]) print """ digraph finite_state_machine { rankdir=LR; - size="8,5" - node [shape = doublecircle]; + node [shape = doublecircle, width = 1.25 ]; """, +node_durations = { } -initial_nodes = RDF.SPARQLQuery(""" +initial_nodes_query = RDF.SPARQLQuery(""" PREFIX machina: -SELECT ?n ?dur WHERE { +SELECT DISTINCT ?n ?dur WHERE { ?m machina:initialNode ?n . ?n a machina:Node ; machina:duration ?dur . } -""").execute(model) +""") -for result in initial_nodes: - print '\t', result['n'].blank_identifier, "[ label = \"", - print float(result['dur'].literal_value['string']), - print "\"]; " +for result in initial_nodes_query.execute(model): + node_id = result['n'].blank_identifier + duration = float(result['dur'].literal_value['string']) + node_durations[node_id] = duration + print '\t', node_id, "[ label = \"d:", duration, "\"];" -print "\tnode [shape = circle];" +print "\tnode [shape = circle, width = 1.25 ];" -nodes = RDF.SPARQLQuery(""" + +nodes_query = RDF.SPARQLQuery(""" PREFIX machina: -SELECT ?n ?dur WHERE { +SELECT DISTINCT ?n ?dur WHERE { ?m machina:node ?n . ?n a machina:Node ; machina:duration ?dur . } -""").execute(model) - -for result in nodes: - print '\t', result['n'].blank_identifier, "[ label = \"", - print float(result['dur'].literal_value['string']), - print "\"]; " +""") +for result in nodes_query.execute(model): + node_id = result['n'].blank_identifier + duration = float(result['dur'].literal_value['string']) + node_durations[node_id] = duration + print '\t', node_id, "[ label = \"d:", duration, "\"]; " -edges = RDF.SPARQLQuery(""" + +edge_query = RDF.SPARQLQuery(""" PREFIX machina: -SELECT ?tail ?head ?prob WHERE { +SELECT DISTINCT ?tail ?head ?prob WHERE { ?e a machina:Edge ; - machina:tail ?tail ; + machina:tail ?tail ; machina:head ?head ; machina:probability ?prob . } -""").execute(model); - -for result in edges: - print '\t', result['tail'].blank_identifier, ' -> ', - print result['head'].blank_identifier, ' ', - print "[ label = \"", result['prob'].literal_value['string'], "\" ];" - -print "\n}" +""") + +for edge in edge_query.execute(model): + print '\t', edge['tail'].blank_identifier, ' -> ', + print edge['head'].blank_identifier, ' ', + print "[ label = \"", edge['prob'].literal_value['string'], "\" ", + print "minlen = ", node_durations[edge['tail'].blank_identifier] * 7.5, " ];" + +print "}" -- cgit v1.2.1