]> hydra-www.ietfng.org Git - dyna2/commitdiff
Further improvments to coverage (now at 87%).
authorTim Vieira <tim.f.vieira@gmail.com>
Wed, 7 Aug 2013 19:43:27 +0000 (15:43 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Wed, 7 Aug 2013 19:43:27 +0000 (15:43 -0400)
12 files changed:
src/Dyna/Backend/Python/load/__init__.py
src/Dyna/Backend/Python/load/matrix.py
src/Dyna/Backend/Python/load/tsv.py
src/Dyna/Backend/Python/post/__init__.py
src/Dyna/Backend/Python/post/draw.py
src/Dyna/Backend/Python/prioritydict.py
src/Dyna/Backend/Python/repl.py
src/Dyna/Backend/Python/stdlib.py
src/Dyna/Backend/Python/utils.py
test/repl/load.dynadoc
test/repl/post.dynadoc
test/repl/repl-misc.dynadoc

index c21d142cda4a089368da8001b677e11bfbadd7d4..51685f1a65930c1408834e7af5fb4d9b218f8d25 100644 (file)
@@ -11,7 +11,6 @@ def run(interp, line):
         [(name, module, args)] = re.findall('^([a-z][a-zA-Z_0-9]*) = ([a-z][a-zA-Z_0-9]*)\((.*)\)', line)
     except ValueError:
         print 'Error: failed to parse load command.'
-        print '    %s' % line
         print
         return
 
index dad044d49d7355aa4275f19af6191597d84b4add..d934b0cd6418b285c40aa93fec64472297a15c77 100644 (file)
@@ -78,11 +78,6 @@ class matrix(object):
         with file(filename) as f:
             for i, line in enumerate(f):
                 line = line.rstrip()
-                if not line:
-                    continue
-                if delim is not None:
-                    line = re.split(delim, line)
-                else:
-                    line = [line]
+                line = re.split(delim, line)
                 for j, v in enumerate(line):
                     term((i, j), astype(v))
index 78211f6db1b9f925e2da325e9bac08448b6b7473..768b7700a5e6cc8c7e4e63b507a64116363af24a 100644 (file)
@@ -12,7 +12,7 @@ class tsv(object):
     """
     Load tab-delimited files.
 
-    > load row = tsv("test/repl/english.gr")
+    > load row = tsv("test/repl/data/english.gr")
     > sol
     row/4
     =====
@@ -55,10 +55,5 @@ class tsv(object):
         with file(filename) as f:
             for i, line in enumerate(f):
                 line = line.rstrip()
-                if not line:
-                    continue
-                if delim is not None:
-                    line = re.split(delim, line)
-                else:
-                    line = [line]
+                line = re.split(delim, line)
                 term([i] + line)
index 135c869a45b4c4800cbb7e704ddb1fa2e4717e56..9f6e534809c26bac2561a73e676605e157640e71 100644 (file)
@@ -11,7 +11,6 @@ def run(interp, line):
         [(module, args)] = re.findall('([a-z][a-zA-Z_0-9]*)\((.*)\)$', line)
     except ValueError:
         print 'Error: failed to parse post command.'
-        print '    %s' % line
         print
         return
 
index 6de168b2548fc3fefe5d28a898f69708a8e4b958..1d557d18736dce345324ba9772083342f84cd74d 100644 (file)
@@ -1,5 +1,6 @@
 import pylab as pl
 from collections import defaultdict
+from stdlib import topython
 
 class draw(object):
     """
@@ -46,24 +47,26 @@ class draw(object):
             for item in frame[t]:
                 fn = item. fn
 
+                args = map(topython, item.args)
+
                 if fn == 'title/1':
-                    [title] = item.args
+                    [title] = args
                     ax.set_title(title)
 
                 elif fn == 'xlim/2':
-                    [a,b] = item.args
+                    [a,b] = args
                     ax.set_xlim(a,b)
 
                 elif fn == 'ylim/2':
-                    [a,b] = item.args
+                    [a,b] = args
                     ax.set_ylim(a,b)
 
                 elif fn == 'line/2':
-                    [(a,b), (c,d)] = item.args
+                    [(a,b), (c,d)] = args
                     ax.plot([a,c], [b,d], color='b', alpha=0.5)
 
                 elif fn == 'text/2':
-                    (s,(x,y)) = item.args
+                    (s,(x,y)) = args
                     ax.text(x,y,s)
 
                 else:
index 454dfb0df12211e5b4db0d05a500f96c7c7ffdc8..5bbaf944db62770443e5f295004d3d5fa0681404 100644 (file)
@@ -1,5 +1,6 @@
 from heapq import heapify, heappush, heappop
 
+
 class prioritydict(dict):
     """Dictionary that can be used as a priority queue.
 
index cb5800dc81927180b28d7353ea84a44b7cb5b10c..cda363fdd17e045bf2d822ddb573569fd05a793e 100644 (file)
@@ -347,15 +347,12 @@ class REPL(cmd.Cmd, object):
             if len(mod) == 2:
                 [cmd, sub] = mod
                 if cmd in ('load', 'post'):
-                    try:
-                        m = get_module(cmd, sub)
+                    m = get_module(cmd, sub)
+                    if m:
                         print m.__doc__
-                    except (ImportError, KeyError, AttributeError):
-                        print 'No help available for "%s %s"' % (cmd, sub)
-                        return
                     else:
-                        return
-        print 'Error: Did not understand help command.'
+                        print 'No help available for "%s %s"' % (cmd, sub)
+                    return
 
     def do_load(self, line):
         """
index 5bcbc158b5db6ab446c2294c8dc2f856dc3433bb..807ad70208360138fec91c9a9189372091c908f5 100644 (file)
@@ -1,7 +1,7 @@
 import re, os
 from term import Term, Cons, Nil, MapsTo
 from collections import Counter
-from utils import pretty, pretty_print, true, false, null, isbool
+from utils import true, false, null, isbool
 from math import log, exp, sqrt
 from random import random as _random
 from glob import glob
index 3d4a28d6b0a4257d7c3fe42780b227779d8c3afd..63bd66bfa3f0abda794b0e4814ead2cc10936173 100644 (file)
@@ -149,17 +149,17 @@ def subst(term, v):
 #        raise KeyboardInterrupt
 
 
-class ddict(dict):
-    """
-    Default Dict where the default function gets the key as an argument, unlike
-    collections.defaultdict.
-    """
-    def __init__(self, f):
-        self.f = f
-        super(ddict, self).__init__()
-    def __missing__(self, x):
-        self[x] = y = self.f(x)
-        return y
+#class ddict(dict):
+#    """
+#    Default Dict where the default function gets the key as an argument, unlike
+#    collections.defaultdict.
+#    """
+#    def __init__(self, f):
+#        self.f = f
+#        super(ddict, self).__init__()
+#    def __missing__(self, x):
+#        self[x] = y = self.f(x)
+#        return y
 
 
 def parse_sexpr(e):
@@ -192,35 +192,35 @@ def parse_sexpr(e):
     return es
 
 
-def pretty_print(t):
-    print pretty(t)
-
-def pretty(t, initialindent=0):
-    "Pretty print tree as a tabbified s-expression."
-    f = StringIO()
-    out = f.write
-    def pp(t, indent=initialindent, indentme=True):
-        if indentme:
-            out(' '*indent)
-        if isinstance(t, basestring):                    # base case
-            return out('%s' % t)
-        if len(t) == 1:
-            if t[0]:
-                pp('%s' % t[0], indent, indentme)
-            return
-        label, children = t[0], t[1:]
-        label = '%s' % label
-        assert isinstance(label, basestring)
-        out('(%s ' % label)
-        n = len(children)
-        for i, child in enumerate(children):
-            pp(child, indent + len(label) + 2, i != 0)   # first child already indented
-            if i != n-1:                                 # no newline after last child
-                out('\n')
-        out(')')
-    pp(t)
-    out('\n')
-    return f.getvalue()
+#def pretty_print(t):
+#    print pretty(t)
+#
+#def pretty(t, initialindent=0):
+#    "Pretty print tree as a tabbified s-expression."
+#    f = StringIO()
+#    out = f.write
+#    def pp(t, indent=initialindent, indentme=True):
+#        if indentme:
+#            out(' '*indent)
+#        if isinstance(t, basestring):                    # base case
+#            return out('%s' % t)
+#        if len(t) == 1:
+#            if t[0]:
+#                pp('%s' % t[0], indent, indentme)
+#            return
+#        label, children = t[0], t[1:]
+#        label = '%s' % label
+#        assert isinstance(label, basestring)
+#        out('(%s ' % label)
+#        n = len(children)
+#        for i, child in enumerate(children):
+#            pp(child, indent + len(label) + 2, i != 0)   # first child already indented
+#            if i != n-1:                                 # no newline after last child
+#                out('\n')
+#        out(')')
+#    pp(t)
+#    out('\n')
+#    return f.getvalue()
 
 
 class ANF(namedtuple('ANF', 'span ruleix agg head evals unifs result')):
index bbdd513aa69cd2e6a2a0c6026951b924b2462bd3..e25ba41a005f6ad939c5714a91d82bfc4c1e2629 100644 (file)
 | goal(S) += phrase(S, "ROOT", 0, sentence_length(S)).
 
 
-% Let's demonstrate what happens with bad filename.
-> load xxx = tsv("path/does/not/exist")
-file `path/does/not/exist` does not exist.
-> load xxx = matrix("path/does/not/exist", astype=str)
-file `path/does/not/exist` does not exist.
-> load xxx = sexpr("path/does/not/exist")
-file `path/does/not/exist` does not exist.
-
-% what if we pass in nonsense
-> load xxx = qweopr/;""
-
-Error: failed to parse load command.
-    xxx = qweopr/;""
-
-> load xxx = yyy()
-
-did not recognize loader 'yyy'
-
-
-> load xxx = tsv(")
-
-Syntax error: EOL while scanning string literal (<string>, line 1)
-
-
-
 > load rules_tsv = tsv("test/repl/data/english.gr")
   *ignore*
 > load token = matrix("test/repl/data/english.sen", astype=str)
index 14c733595e1fd563131f08be2b70c4e8654ee1bd..d0bc5697087e1b47cecd543df23fb89b0bc3ed9f 100644 (file)
@@ -18,3 +18,5 @@ Solution
 a.
 b.
 c.
+
+> post dump_solution("solution.txt")
\ No newline at end of file
index 82af3970970a63519760355c8d72dc0f49c3d7b4..967058994da406fdb699b2b17aa41c140bbde6fc 100644 (file)
@@ -119,3 +119,78 @@ no items matching `xxxx`.
 > help vquery
 
 See query.
+
+
+> help load tsv
+
+Load tab-delimited files.
+    > load row = tsv("test/repl/data/english.gr")
+    > sol
+    row/4
+    =====
+    row(0,"0","S","NP VP")      = true.
+    row(1,"1.58","ROOT","S .")  = true.
+    row(2,"1.58","ROOT","S !")  = true.
+    row(3,"1.58","ROOT","VP !") = true.
+    row(4,"3.81","VP","V")      = true.
+    row(5,"3.81","VP","V NP")   = true.
+    row(6,"1.49","VP","V VP")   = true.
+       ...
+
+> load row = tsv("test/repl/data/english.gr")
+
+  *ignore*
+
+
+> help load doesnotexist
+
+No help available for "load doesnotexist"
+
+
+
+
+
+
+
+% Let's demonstrate what happens with bad filename.
+> load xxx = tsv("path/does/not/exist")
+file `path/does/not/exist` does not exist.
+> load xxx = matrix("path/does/not/exist", astype=str)
+file `path/does/not/exist` does not exist.
+> load xxx = sexpr("path/does/not/exist")
+file `path/does/not/exist` does not exist.
+
+% what if we pass in nonsense
+> load xxx = qweopr/;""
+
+Error: failed to parse load command.
+
+> load xxx = yyy()
+
+did not recognize loader 'yyy'
+
+
+> load xxx = tsv(")
+
+Syntax error: EOL while scanning string literal (<string>, line 1)
+
+
+%"
+
+
+
+% Let's demonstrate what happens with bad filename.
+> post doesnotexist
+
+Error: failed to parse post command.
+
+> post doesnotexist()
+
+did not recognize post-processor 'doesnotexist'
+
+> post draw_circuit(")
+
+Syntax error: EOL while scanning string literal (<string>, line 1)
+
+
+%"
\ No newline at end of file