From 47f59aaad7a5ab8c189905544a761940ae9f8509 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 18 Mar 2007 02:11:51 +0000 Subject: Improved automata diagram drawing (include notes, use standard initial note notation). Made compilation without Jack possible. git-svn-id: http://svn.drobilla.net/lad/machina@363 a436a847-0d15-0410-975c-d299462d15a1 --- util/machina2dot | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ util/machina2dot.py | 78 ------------------------------------------------- 2 files changed, 84 insertions(+), 78 deletions(-) create mode 100755 util/machina2dot delete mode 100755 util/machina2dot.py (limited to 'util') diff --git a/util/machina2dot b/util/machina2dot new file mode 100755 index 0000000..e3e420c --- /dev/null +++ b/util/machina2dot @@ -0,0 +1,84 @@ +#!/usr/bin/python + +import sys +import RDF + +model = RDF.Model() +parser = RDF.Parser(name="guess") + +if len(sys.argv) != 2: + print "Usage: machina2dot FILE" + sys.exit(-1) + +parser.parse_into_model(model, "file:" + sys.argv[1]) + +print """ +digraph finite_state_machine { + rankdir=LR; + node [ shape = circle ]; +""", + +node_durations = { } + +initial_nodes_query = RDF.SPARQLQuery(""" +PREFIX machina: +SELECT DISTINCT ?n ?dur ?note WHERE { + ?m machina:initialNode ?n . + ?n a machina:Node ; + machina:duration ?dur . + OPTIONAL { ?n machina:enterAction ?a . + ?a machina:midiNote ?note } +} +""") + +invis_id = 0; + +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 [ style = invis ] ", + print "invis%d" % invis_id, " }" + print '\t', node_id, "[ label = \"d =", duration, "\"];" + print '\t', "invis%d" % invis_id, " -> ", node_id + invis_id += 1 + + +nodes_query = RDF.SPARQLQuery(""" +PREFIX machina: +SELECT DISTINCT ?n ?dur ?note WHERE { + ?m machina:node ?n . + ?n a machina:Node ; + machina:duration ?dur . + OPTIONAL { ?n machina:enterAction ?a . + ?a machina:midiNote ?note } +} +""") + +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 + label = "d=%.2f" % duration + if result['note']: + label += "\\nn=%s" % result['note'].literal_value['string'] + print '\t', node_id, "[ label=\"%s\" ]" % label + + +edge_query = RDF.SPARQLQuery(""" +PREFIX machina: +SELECT DISTINCT ?tail ?head ?prob WHERE { + ?e a machina:Edge ; + machina:tail ?tail ; + machina:head ?head ; + machina:probability ?prob . +} +""") + +for edge in edge_query.execute(model): + print '\t', edge['tail'].blank_identifier, ' -> ', + print edge['head'].blank_identifier, ' ', + print "[ label = \"%1.2f\"" % float(edge['prob'].literal_value['string']), + print "minlen = ", node_durations[edge['tail'].blank_identifier] * 2, " ];" + +print "}" diff --git a/util/machina2dot.py b/util/machina2dot.py deleted file mode 100755 index cb704ef..0000000 --- a/util/machina2dot.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/python - -import sys -import RDF - -model = RDF.Model() -parser = RDF.Parser(name="guess") - -if len(sys.argv) != 2: - print "Usage: machina2dot FILE" - sys.exit(-1) - -parser.parse_into_model(model, "file:" + sys.argv[1]) - - -print """ -digraph finite_state_machine { - rankdir=LR; - node [ shape = circle ]; -""", - -node_durations = { } - -initial_nodes_query = RDF.SPARQLQuery(""" -PREFIX machina: -SELECT DISTINCT ?n ?dur WHERE { - ?m machina:initialNode ?n . - ?n a machina:Node ; - machina:duration ?dur . -} -""") - -invis_id = 0; - -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 [ style = invis ] ", - print "invis%d" % invis_id, " }" - print '\t', node_id, "[ label = \"d =", duration, "\"];" - print '\t', "invis%d" % invis_id, " -> ", node_id - invis_id += 1 - - -nodes_query = RDF.SPARQLQuery(""" -PREFIX machina: -SELECT DISTINCT ?n ?dur WHERE { - ?m machina:node ?n . - ?n a machina:Node ; - machina:duration ?dur . -} -""") - -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 =", "%.2f" % duration, "\"]; " - - -edge_query = RDF.SPARQLQuery(""" -PREFIX machina: -SELECT DISTINCT ?tail ?head ?prob WHERE { - ?e a machina:Edge ; - machina:tail ?tail ; - machina:head ?head ; - machina:probability ?prob . -} -""") - -for edge in edge_query.execute(model): - print '\t', edge['tail'].blank_identifier, ' -> ', - print edge['head'].blank_identifier, ' ', - print "[ label = \"", "%1.2f" % float(edge['prob'].literal_value['string']), "\" ", - print "minlen = ", node_durations[edge['tail'].blank_identifier] * 2, " ];" - -print "}" -- cgit v1.2.1