<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,6 @@
 from __future__ import division
 import networkx as nx, numpy as np, tempfile
-from string import ascii_letters
+from string import ascii_letters,digits
 from collections import namedtuple
 
 ##############################
@@ -12,8 +12,8 @@ Single # for descriptions of what I'm doing inside source code, and what variabl
 
 
 SYMBOL_LIST = [] #list of pairs (char, bounds) where bounds = (xmin, xmax, ymin, ymax)
-HUGE = 9999
-SUPERHUGE = 999999999
+HUGE = 1e10
+SUPERHUGE = 1e20
 
 Symbol = namedtuple(&quot;Symbol&quot;,&quot;char bounds&quot;)
 Parse = namedtuple(&quot;Parse&quot;,&quot;tree score&quot;)
@@ -31,12 +31,7 @@ class memoized:
         else:
             object = self.cache[args] = self.fn(*args)
             return object
-        
-    def __repr__(self):
-        &quot;&quot;&quot;Return the function's docstring.&quot;&quot;&quot;
-        return self.fn.__doc__
-        
-
+                
 
 def parse_score(rule,bounds1, nonterminal1, bounds2, nonterminal2):
     &quot;&quot;&quot;computes score just from that particular parse&quot;&quot;&quot;
@@ -44,17 +39,14 @@ def parse_score(rule,bounds1, nonterminal1, bounds2, nonterminal2):
     return np.dot(features(rule,bounds1,bounds2),weights(rule))
 
 def features(rule,bounds1,bounds2):
+    &quot;return list of feature functions for rule&quot;
     xmin1,xmax1,ymin1,ymax1 = bounds1
     xmin2,xmax2,ymin2,ymax2 = bounds2
     xmin,xmax,ymin,ymax = bounding_box([bounds1,bounds2])
     return [feature(xmin,xmax,ymin,ymax,xmin1,xmax1,ymin1,ymax1,xmin2,xmax2,ymin2,ymax2)
             for feature in FEATURES[rule]]
         
-CHARACTERS = [char for char in ascii_letters] + [str(i) for i in range(10)] + [&quot;+&quot;,&quot;-&quot;,&quot;=&quot;]
-
-
-
-
+CHARACTERS = list(ascii_letters) + list(digits) + [&quot;+&quot;,&quot;-&quot;,&quot;=&quot;]
 
 def test_parse():
     
@@ -76,15 +68,16 @@ def test_parse():
     
     
 def parse_expr(char_bound_list):
+    &quot;top level parse function, applied to list of pairs (char, bound_box)&quot;
     global SYMBOL_LIST
     SYMBOL_LIST = [Symbol(char,bounds) for (char,bounds) in char_bound_list]
     return subset2parse(&quot;Expr&quot;,tuple(range(len(char_bound_list))))
 
 @memoized
 def subset2parse(nonterminal,symbol_ind_list):
+    &quot;recursive parsing function&quot;
     best_rule, best_tree, best_score = None, None, -HUGE
     
-    
     if len(symbol_ind_list) == 1:
         return SYMBOL_LIST[symbol_ind_list[0]].char,0
     
@@ -96,10 +89,6 @@ def subset2parse(nonterminal,symbol_ind_list):
                 tree2,score2 = subset2parse(nt2,comp)
                 cum_score = (score1 + score2 + 
                              parse_score(rule,subset_bounds(subset),nt1,subset_bounds(comp),nt2))
-                print rule,nt1,nt2
-                print cum_score
-                print symbol_ind_list
-
                 
                 if cum_score &gt; best_score:
                     best_rule = rule
@@ -110,6 +99,7 @@ def subset2parse(nonterminal,symbol_ind_list):
     return Parse(best_tree,best_score)
 
 def tex_combine(rule,tree1,tree2):
+    &quot;use appropriate latex syntax to combine subexpressions&quot;
     return TEX_OPS[rule](tree1,tree2)
 
 TEX_OPS = dict(
@@ -147,6 +137,8 @@ SupFeats =   [LL1,BB1,TT1,R1L2,TT2,Bigger12,RR2]
 SubFeats = [LL1,BB1,TT1,R1L2,Bigger12,BB2,RR2]
 
 
+# Each feature function is generated from the following template, which has a fixed set of inputs
+# %s is replaced by a string expression that evaluates to a boolean
 feat_template = &quot;&quot;&quot;
 def _feat(xmin,xmax,ymin,ymax,xmin1,xmax1,ymin1,ymax1,xmin2,xmax2,ymin2,ymax2):
     height = ymax-ymin
@@ -155,13 +147,13 @@ def _feat(xmin,xmax,ymin,ymax,xmin1,xmax1,ymin1,ymax1,xmin2,xmax2,ymin2,ymax2):
     return %s
 &quot;&quot;&quot;
 
-
-
 def str2feat(math_expr):
+    &quot;Makes feature function from string expression&quot;
     exec(feat_template%math_expr)
     return _feat
 
 def makefeats(li):
+    &quot;Turns list of feature strings into list of feature functions&quot;
     return map(str2feat,li)
 
 FEATURES = dict(
@@ -174,18 +166,21 @@ def line2rule(string):
     pieces = string.split()
     return Replacement(pieces[0],pieces[2],pieces[3:])
 
-
 RULES = [(rep.left,(rep.op,rep.rightlist[0],rep.rightlist[1])) for rep in map(line2rule,PRETTY_GRAMMAR)]
 
 @memoized
 def replacements2(nonterminal):
+    &quot;&quot;&quot;Return a list of triples (operator,right1,right2) for every replacement rule with
+    two items on RHS&quot;&quot;&quot;
     return [(op,right1,right2) for (left,(op,right1,right2)) in RULES if left == nonterminal]
-        
+
 def subset_bounds(symbol_ind_list):
+    &quot;Get bounds of a list of symbol indices&quot;
     return bounding_box([SYMBOL_LIST[i].bounds for i in symbol_ind_list])
 
 @memoized
 def subsets(tup):
+    &quot;All subsets of elements of tuples&quot;
     if tup == (): return ((),)
     else:
         later = subsets(tup[1:])
@@ -193,7 +188,8 @@ def subsets(tup):
 
 @memoized    
 def subsets_and_comps(tup):
-    return tuple((ss,tuple(el for el in tup if el not in ss)) for ss in subsets(tup) if increasing(0,len(ss),len(tup)))
+    &quot;a list of pairs subset,complement for all proper subsets of tup&quot;
+    return [(ss,tuple(el for el in tup if el not in ss)) for ss in subsets(tup) if increasing(0,len(ss),len(tup))]
     
 def increasing(a,b,c):
     return a&lt;b and b&lt;c</diff>
      <filename>layout-parse.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>965e44692dbccd1a11dcf6f5dfe3e0e5e9cba8ed</id>
    </parent>
  </parents>
  <author>
    <name>John Schulman</name>
    <email>schulmannerism@gmail.com</email>
  </author>
  <url>http://github.com/joschu/wyoming/commit/6eb4b1eab8310bb9bbb7da0f6777e3f7de9f9d90</url>
  <id>6eb4b1eab8310bb9bbb7da0f6777e3f7de9f9d90</id>
  <committed-date>2009-11-08T11:31:00-08:00</committed-date>
  <authored-date>2009-11-08T11:31:00-08:00</authored-date>
  <message>added docstrings</message>
  <tree>8e34c13999bccc459b97e6bb167bbc8e5cd54564</tree>
  <committer>
    <name>John Schulman</name>
    <email>schulmannerism@gmail.com</email>
  </committer>
</commit>
