]> hydra-www.ietfng.org Git - dyna2/commitdiff
circle. Mouse over shows the rule source and rule index.
authorTim Vieira <tim.f.vieira@gmail.com>
Sun, 7 Jul 2013 20:17:39 +0000 (16:17 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Sun, 7 Jul 2013 20:17:39 +0000 (16:17 -0400)
minor tweaks to readme.

README.md
src/Dyna/Backend/Python/debug.py
src/Dyna/Backend/Python/post/draw_circuit.py
src/Dyna/Backend/Python/repl.py

index 1cbbeb06d0947b044eaea8a238320478bbafed33..a0431c6b5a4ca16b4cd511cc515cd7c4ce279cf2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -15,16 +15,12 @@ Quick Start
 -----------
 
 First, ensure that you have the Haskell platform 2012.2 or later installed
-either through your favorite package manager (e,g, `apt-get install
+either through your favorite package manager (e.g., `apt-get install
 haskell-platform`) or by installing it stand-alone from the haskell homepage.
 
 This is enough to get you the compiler up and running. In order execute
-programs, you'll need to set up the Python backend up. For that you'll need to
-have the following:
-
-    * Python 2.7+
-
-The python modules required
+programs, you'll need to set up the Python backend. For that you'll need `Python
+2.7+` and the following python modules
 
     $ easy_install ipython
 
index 3aef59d040f2fbb4e4c63094830f6e4d25c0dd28..2aa120aaea94d4649077df40fd006c8c5b98d9d9 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 """
-Generates a visual representation of a Dyna program rules after the
+Generates a visual representation of a Dyna program's rules after the
 normalization process.
 """
 
@@ -16,7 +16,7 @@ try:
     from pygments.lexers import get_lexer_by_name
     from pygments.formatters import HtmlFormatter
 
-except ImportError as e:
+except ImportError:
     def format_code(code):
         warn('pygments not installed.')
         return code, 0
@@ -109,8 +109,8 @@ class Hypergraph(object):
 
                 # connect body variables to edge crux
                 for b in e.body:
-#                    print >> f, '"%s" -> "%s" [arrowhead=none];' % (b, id(e))
-                    print >> f, '"%s" -> "%s";' % (b, id(e))
+                    print >> f, '"%s" -> "%s" [arrowhead=none];' % (b, id(e))
+#                    print >> f, '"%s" -> "%s";' % (b, id(e))
 
                 # connect head variables to edge
 #                print >> f, '  "%s" [label="",shape=point];' % (id(e))
@@ -136,27 +136,27 @@ class Hypergraph(object):
         self.render(name)
         os.system('gnome-open %s.svg 2>/dev/null' % name)
 
-    def get_function(self, x):
-        """
-        String of symbolic representation of ``x``, a variable or function, in
-        this expresion graph.
-        """
-
-        if isinstance(x, Edge):
-            label = re.sub('@\d+$', '', x.label)
-            if not x.body:  # arity 0
-                return label
-
-            if not label[0].isalpha() and len(x.body) == 2:
-                [a,b] = map(self.get_function, x.body)
-                return '(%s %s %s)' % (a, label, b)
-
-            return '%s(%s)' % (label, ', '.join(map(self.get_function, x.body)))
-        else:
-            if not self.incoming[x]:  # input variable
-                return x
-            [e] = self.incoming[x]
-            return self.get_function(e)
+#    def get_function(self, x):
+#        """
+#        String of symbolic representation of ``x``, a variable or function, in
+#        this expresion graph.
+#        """
+#
+#        if isinstance(x, Edge):
+#            label = re.sub('@\d+$', '', x.label)
+#            if not x.body:  # arity 0
+#                return label
+#
+#            if not label[0].isalpha() and len(x.body) == 2:
+#                [a,b] = map(self.get_function, x.body)
+#                return '(%s %s %s)' % (a, label, b)
+#
+#            return '%s(%s)' % (label, ', '.join(map(self.get_function, x.body)))
+#        else:
+#            if not self.incoming[x]:  # input variable
+#                return x
+#            [e] = self.incoming[x]
+#            return self.get_function(e)
 
     def toposort(self, root):
         visited = set()
@@ -208,6 +208,7 @@ def graph_styles(g):
 
     # edge styles
     for e in g.edges:
+        sty[e].update({'shape': 'rectangle'})
         if    e.label.startswith('&') \
            or e.label.startswith('!') \
            or e.label.startswith('=') :  # distiguish unif edges
index 6509e5b8f6459480a83db8344264a27d99abceec..194c5071cd7bdbcb6650da45374dcfa0ac7263d3 100644 (file)
@@ -1,10 +1,39 @@
 # -*- coding: utf-8 -*-
+"""
+TODO: draw subgraph of nodes matching a query.
+"""
 
+import re
 import webbrowser
 from debug import Hypergraph
 from cStringIO import StringIO
 from utils import lexer, subst
 
+HEADER = """
+<html>
+<head>
+<style>
+body {
+  background-color: black;
+  color: white;
+}
+</style>
+
+<!--
+<script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
+<script>
+function clicked(x) {
+  alert(x.childNodes);
+}
+</script>
+-->
+
+</head><body>
+"""
+
+FOOTER = """
+</body></html>
+"""
 
 def circuit(edges):
     # create hypergraph object
@@ -59,36 +88,56 @@ class draw_circuit(object):
         es = infer_edges(interp)
         c = circuit(es)
 
+        from collections import defaultdict
+        sty = defaultdict(dict)
+        for e in c.edges:
+            sty[e].update(dict(shape='circle',
+                               width='.125',
+                               fillcolor="yellow",
+                               label=''))
+
         with file(outfile, 'wb') as f:
-            print >> f, """
-            <html>
-            <head>
-            <style>
-            body {
-              background-color: black;
-              color: white;
-            }
-            </style>
-            </head>
-            <body>
-            """
+            print >> f, HEADER
 
             x = StringIO()
             interp.dump_charts(x)
 
             print >> f, '<div style="position:absolute;">%s</div>' \
-                % '<h1>Charts</h1>%s' \
+                % '<h1>Solution</h1>%s' \
                 % '<pre style="width: 500px;">%s</pre>' \
                 % x.getvalue()
 
+            svg = c.render('circuit', sty=sty)
+
+            E = {str(id(e)): e for e in c.edges}
+
+            def foo(m):
+                z, i, cls, x, q = m.groups()
+
+                if cls == 'edge':
+                    # split on arrow ->
+                    u, v = x.split('&#45;&gt;')
+                    print 'edge:', i, u, v
+                else:
+                    if x in E:
+                        print 'crux', i, x,
+                        rule = interp.rules[int(E[x].label)]
+                        x = '%s   %% rule %s' % (rule.src, rule.index)
+                    else:
+                        print 'node:', i, x
+
+                return '<g id="%s" class="%s"><title>%s</title>%s</g>' % (i, cls, x, q)
+
+            svg = re.sub('<g (id="([^"]+)" class="(node|edge)"><title>([^<>]+)</title>([\w\W]+?)</g>)', foo, svg)
+
             print >> f, """
             <div style="width: 800px; position:absolute; left: 550px">
             <h1>Hypergraph</h1>
             %s
             </div>
-            """ % c.render('circuit')
+            """ % svg
 
-            print >> f, '</body></html>'
+            print >> f, FOOTER
 
         if open:
             webbrowser.open(f.name)
index 7ce7bbffb051aad91ac7af244348f57488e1e75c..a9299ea31f4b72723e85f1831f4d3f32a01eed6f 100644 (file)
@@ -1,9 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
-TODO: unsubscribe
-
-TODO: subscriptions probably should only show "changes"
+TODO: subscriptions: unsubscribe, only show changes
 
 TODO: help should print call signature of loads and post-processors in addition
 to help.