[(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
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))
"""
Load tab-delimited files.
- > load row = tsv("test/repl/english.gr")
+ > load row = tsv("test/repl/data/english.gr")
> sol
row/4
=====
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)
[(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
import pylab as pl
from collections import defaultdict
+from stdlib import topython
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:
from heapq import heapify, heappush, heappop
+
class prioritydict(dict):
"""Dictionary that can be used as a priority queue.
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):
"""
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
# 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):
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')):
| 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)
a.
b.
c.
+
+> post dump_solution("solution.txt")
\ No newline at end of file
> 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