werkend dotscript
authorMart Lubbers <mart@martlubbers.net>
Tue, 26 Jan 2016 07:58:45 +0000 (08:58 +0100)
committerMart Lubbers <mart@martlubbers.net>
Tue, 26 Jan 2016 07:58:45 +0000 (08:58 +0100)
a4/tcp/results/van_learnlib_naar_dot.py [new file with mode: 0755]

diff --git a/a4/tcp/results/van_learnlib_naar_dot.py b/a4/tcp/results/van_learnlib_naar_dot.py
new file mode 100755 (executable)
index 0000000..86d5e7f
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/env python2
+
+import sys
+import re
+
+sys.stderr.write("""Usage: {} [INPUT [OUTPUT]
+als input/output niet specificeerd pakt hij stdin/stdout
+voorbeeld:
+\t$ < file.dot ./van_learnlib_naar_dot.py | dot -Tpdf > file.pdf
+""".format(sys.argv[0]))
+
+if len(sys.argv) == 1:
+    inputfile = sys.stdin
+    outputfile = sys.stdout
+elif len(sys.argv) == 2:
+    inputfile = open(sys.argv[1], 'r')
+    outputfile = sys.stdout
+else:
+    inputfile = open(sys.argv[1], 'r')
+    outputfile = open(sys.argv[2], 'w')
+
+data = []
+pat = r's(?P<f>\d+) -> s(?P<t>\d+) \[label="(?P<i>\S+) / (?P<o>\S+)"\];'
+
+for line in inputfile:
+    match = re.search(pat, line)
+    if match:
+        outputfile.write('\ts{0} -> s{0}_ [label="!{1}"]\n'.format(
+            match.group('f'), match.group('i')))
+        outputfile.write('\ts{}_ -> s{} [label="?{}"]\n'.format(
+            match.group('f'), match.group('t'), match.group('o')))
+    else:
+        outputfile.write(line)
+
+if inputfile != sys.stdin:
+    inputfile.close()
+if outputfile != sys.stdout:
+    outputfile.close()