March Liu avatar March Liu committed 1a915a8

found current code will gen black data

Comments (0)

Files changed (2)

src/socrates/core.py

         pid = self.get_predicate_id_by_name(name)
         if not pid:
             pid = self.sequence()
+            self.Session.execute(subjects.insert().values(subject_id=pid, predicate_id=meta.IS, obj=meta.PREDICATE))
+            self.Session.execute(strings.insert().values(subject_id=pid, predicate_id=meta.NAME, obj=name))
         objType = self.get_type_id_by_name(objtype_name)
         storid = self.Session.query(subjects.c.obj).\
             filter(subjects.c.subject_id==objType).\
             filter(subjects.c.predicate_id==meta.STORAGE).scalar()
-        self.Session.execute(subjects.insert().values(subject_id=pid, predicate_id=meta.IS, obj=meta.PREDICATE))
         self.Session.execute(subjects.insert().values(subject_id=pid, predicate_id=meta.OBJTYPE, obj=objType))
-        self.Session.execute(strings.insert().values(subject_id=pid, predicate_id=meta.NAME, obj=name))
         self.Session.commit()
         return pid
 
         if tname:
             tnames = (tname,)
         else:
-            subjects = self.registed_type['subject']
-            strings = self.registed_type['string']
+            Subject = self.registed_type['subject']
+            String = self.registed_type['string']
             pid = self.get_predicate_id_by_name(pname)
-            objType = self.Session.query(subjects.obj).\
-                filter(subjects.subject_id==pid).\
-                filter(subjects.predicate_id==meta.OBJTYPE).scalar() 
-            tnames = tuple(row.obj for row in self.Session.query(strings.obj).\
-                               filter(strings.subject_id==objType).\
-                               filter(strings.predicate_id==meta.NAME).all())
+            objTypes = self.Session.query(Subject).\
+                filter(Subject.subject_id==pid).\
+                filter(Subject.predicate_id==meta.OBJTYPE).all() 
+            tnames = tuple(self.Session.query(String.obj).\
+                               filter(String.subject_id==objType.obj).\
+                               filter(String.predicate_id==meta.NAME).scalar()
+                           for objType in objTypes)
         return pname, tnames
 
     def get_type_id_by_name(self, name):

src/socrates/types.py

         pid = self.__storage.get_predicate_id_by_name(pname)
         return [segment.object for segment in self.segments if segment.predicate_id==pid]
 
+    def count(self, pname):
+        pid = self.__storage.get_predicate_id_by_name(pname)
+        return len([segment.object for segment in self.segments if segment.predicate_id==pid])
+        
+
     pnames = property(lambda self:set(segment.predicate.name for segment in self.segments))
 
 class Predicate(Subject):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.