aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-02-28 02:48:54 +0000
committerDavid Robillard <d@drobilla.net>2007-02-28 02:48:54 +0000
commitde25ae35ccb0613290ba20bfcf0ea15476c26ed5 (patch)
tree817ea07a9c1098c100ec32a3ad72a793eea40c6c /util
parentd288ce4b8180e4c79f61bed85f0fa5d4cd36acc3 (diff)
downloadmachina-de25ae35ccb0613290ba20bfcf0ea15476c26ed5.tar.gz
machina-de25ae35ccb0613290ba20bfcf0ea15476c26ed5.tar.bz2
machina-de25ae35ccb0613290ba20bfcf0ea15476c26ed5.zip
Added python script to convert RDF files to dot graphs.
git-svn-id: http://svn.drobilla.net/lad/machina@340 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'util')
-rw-r--r--util/Makefile.am1
-rwxr-xr-xutil/machina2dot.py71
2 files changed, 72 insertions, 0 deletions
diff --git a/util/Makefile.am b/util/Makefile.am
new file mode 100644
index 0000000..7186db5
--- /dev/null
+++ b/util/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST = machina2dot.py
diff --git a/util/machina2dot.py b/util/machina2dot.py
new file mode 100755
index 0000000..bbf9725
--- /dev/null
+++ b/util/machina2dot.py
@@ -0,0 +1,71 @@
+#!/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;
+ size="8,5"
+ node [shape = doublecircle];
+""",
+
+
+initial_nodes = RDF.SPARQLQuery("""
+PREFIX machina: <http://drobilla.net/ns/machina#>
+SELECT ?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 "\"]; "
+
+print "\tnode [shape = circle];"
+
+
+nodes = RDF.SPARQLQuery("""
+PREFIX machina: <http://drobilla.net/ns/machina#>
+SELECT ?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 "\"]; "
+
+
+edges = RDF.SPARQLQuery("""
+PREFIX machina: <http://drobilla.net/ns/machina#>
+SELECT ?tail ?head ?prob WHERE {
+ ?e a machina:Edge ;
+ 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}"