changeset 599:b50e4d43dd3e

curvecalc would make multiple subterms with the same empty name, and this would lose expressions Ignore-this: 73e9d0274e6af88d39dc70e91c1e7699
author drewp@bigasterisk.com
date Sun, 20 Jun 2010 21:09:45 +0000
parents 3842254f101e
children f61a7b03765e
files bin/curvecalc light9/Submaster.py
diffstat 2 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/bin/curvecalc	Sun Jun 20 21:09:28 2010 +0000
+++ b/bin/curvecalc	Sun Jun 20 21:09:45 2010 +0000
@@ -243,8 +243,7 @@
     def __init__(self, master, graph, st, **kw):
         self.subterm = st
         tk.Frame.__init__(self,master,bd=1,relief='raised',**kw)
-        l = tk.Label(self,
-                     text="sub %s" % graph.label(self.subterm.submaster.uri))
+        l = tk.Label(self, text="sub %s" % self.subterm.submaster.name)
         l.pack(side='left')
         sev=Subexprview(self,self.subterm.subexpr)
         sev.pack(side='left',fill='both',exp=1)
@@ -326,10 +325,16 @@
 
 def add_one_subterm(graph, subUri, curveset, subterms, master, expr=None):
     subname = graph.label(subUri)
+    print "%s's label is %s" % (subUri, subname)
+    if not subname: # fake sub, like for a chase
+        st = graph.subjects(L9['sub'], subUri).next()
+        subname = graph.label(st)
+        print "using parent subterm's name instead. parent %r, name %r" % (st, subname)
+    assert subname, "%s has no name" % subUri
     if expr is None:
         expr = '%s(t)' % subname
 
-    term = Subterm(Submaster.Submaster(graph=graph, sub=subUri),
+    term = Subterm(Submaster.Submaster(graph=graph, name=subname, sub=subUri),
                    Subexpr(curveset,expr))
     subterms.append(term)
 
@@ -384,6 +389,7 @@
     """rdf graph describing the subterms, readable by add_subterms_for_song"""
     graph = Graph()
     for subterm in subterms:
+        assert subterm.submaster.name, "submaster has no name"
         uri = URIRef(song + "/subterm/" + subterm.submaster.name)
         graph.add((song, L9['subterm'], uri))
         graph.add((uri, RDF.type, L9['Subterm']))
--- a/light9/Submaster.py	Sun Jun 20 21:09:28 2010 +0000
+++ b/light9/Submaster.py	Sun Jun 20 21:09:45 2010 +0000
@@ -40,7 +40,7 @@
         """
         if name is sub is leveldict is None:
             raise TypeError("more args are needed")
-        if sub is not None:
+        if sub is not None and name is None:
             name = graph.label(sub)
         if graph is not None:
             # old code was passing leveldict as second positional arg