aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--Makefile.am1
-rw-r--r--configure.ac1
-rw-r--r--src/engine/Machine.cpp12
-rw-r--r--src/engine/Node.cpp4
-rw-r--r--util/Makefile.am1
-rwxr-xr-xutil/machina2dot.py71
6 files changed, 85 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index 08e5c1e..4d147ac 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,4 @@
+DIST_SUBDIRS = util
SUBDIRS = src
desktopfilesdir = $(datadir)/applications
diff --git a/configure.ac b/configure.ac
index 0ae4980..f56438e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,6 +76,7 @@ AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([src/engine/Makefile])
AC_CONFIG_FILES([src/engine/machina/Makefile])
AC_CONFIG_FILES([src/gui/Makefile])
+AC_CONFIG_FILES([util/Makefile])
AC_CONFIG_FILES([machina.desktop])
AC_OUTPUT
diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp
index 41335bc..6cade39 100644
--- a/src/engine/Machine.cpp
+++ b/src/engine/Machine.cpp
@@ -221,9 +221,15 @@ Machine::write_state(Raul::RDFWriter& writer)
(*n)->write_state(writer);
- writer.write(RdfId(RdfId::RESOURCE, ""),
- RdfId(RdfId::RESOURCE, "machina:node"),
- (*n)->id());
+ if ((*n)->is_initial()) {
+ writer.write(RdfId(RdfId::RESOURCE, ""),
+ RdfId(RdfId::RESOURCE, "machina:initialNode"),
+ (*n)->id());
+ } else {
+ writer.write(RdfId(RdfId::RESOURCE, ""),
+ RdfId(RdfId::RESOURCE, "machina:node"),
+ (*n)->id());
+ }
for (Node::Edges::const_iterator e = (*n)->outgoing_edges().begin();
e != (*n)->outgoing_edges().end(); ++e) {
diff --git a/src/engine/Node.cpp b/src/engine/Node.cpp
index ecb7a22..47eee35 100644
--- a/src/engine/Node.cpp
+++ b/src/engine/Node.cpp
@@ -131,9 +131,9 @@ Node::write_state(Raul::RDFWriter& writer)
RdfId(RdfId::RESOURCE, "machina:duration"),
Raul::Atom((float)_duration));
- for (Node::Edges::const_iterator e = _outgoing_edges.begin();
+ /*for (Node::Edges::const_iterator e = _outgoing_edges.begin();
e != _outgoing_edges.end(); ++e)
- (*e)->write_state(writer);
+ (*e)->write_state(writer);*/
}
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}"