1. March Liu
  2. Socrates

Commits

March Liu  committed 6ed78eb

modify a function named error
meta: subject is type;
debug Storage.parsePredicateExpression method.

  • Participants
  • Parent commits d3b772f
  • Branches default

Comments (0)

Files changed (2)

File src/socrates/core.py

View file
             res = engine.execute(types)
 
             for r in res:
-                if r.name != 'string':
+                if r.name not in ('string', 'subject'):
                     self.registeType(r.name, storage=r.storage,)
 
     def __del__(self):
         else:
             sid = self.sequence()
         pid = self.get_predicate_id_by_name(pname)
-        SegmentType = self.registed_type[tnames[0][0]]
+        SegmentType = self.registed_type[tnames[0]]
         segment = SegmentType(sid, pid, obj)
         self.Session.add(segment)
         if autocommit:
         pname, tnames = self.parsePredicateExpression(predicate_segment)
         pid = self.get_predicate_id_by_name(pname)
         for tname in tnames:
-            SegmentType = self.registed_type[tnames[0][0]]
+            SegmentType = self.registed_type[tnames[0]]
             for row in self.Session.query(SegmentType).filter(SegmentType.predicate_id==pid).filter(SegmentType.obj==obj):
                 yield row
         self.Session.commit()
             objType = self.Session.query(subjects.obj).\
                 filter(subjects.subject_id==pid).\
                 filter(subjects.predicate_id==meta.OBJTYPE).scalar() 
-            tnames = self.Session.query(strings.obj).\
-                filter(strings.subject_id==objType).\
-                filter(strings.predicate_id==meta.NAME).all()
+            tnames = tuple(row.obj for row in self.Session.query(strings.obj).\
+                               filter(strings.subject_id==objType).\
+                               filter(strings.predicate_id==meta.NAME).all())
         return pname, tnames
 
     def get_type_id_by_name(self, name):
 >>> print storage.get_predicate_id_by_name("name")==meta.NAME
 True
         """
-        if name == 'subject':
-            re = meta.SUBJECT
-        else:
-            SegmentString = self.registed_type['string']
-            SegmentSubject = self.registed_type['subject']
-            re = self.Session.query(SegmentSubject.subject_id,).\
-                filter(SegmentSubject.predicate_id==meta.IS).\
-                filter(SegmentSubject.obj==meta.TYPE).\
-                filter(select([SegmentString.obj], 
-                              and_(SegmentString.subject_id==SegmentSubject.subject_id,
-                                   SegmentString.predicate_id==meta.NAME)).as_scalar()==name).scalar()
+        SegmentString = self.registed_type['string']
+        SegmentSubject = self.registed_type['subject']
+        re = self.Session.query(SegmentSubject.subject_id,).\
+            filter(SegmentSubject.predicate_id==meta.IS).\
+            filter(SegmentSubject.obj==meta.TYPE).\
+            filter(select([SegmentString.obj], 
+                          and_(SegmentString.subject_id==SegmentSubject.subject_id,
+                               SegmentString.predicate_id==meta.NAME)).as_scalar()==name).scalar()
         #session.close()
         return re
 

File src/socrates/meta.py

View file
 
 ** relation
 
- - subject is subject
+ - subject is type
  - predicate is subject
  - is is predicate
  - is objType subject
         session.execute(subjects.insert().values(subject_id=sequence()))
     session.flush()
 
-    update(SUBJECT, SUBJECT, IS, SUBJECT)
+    update(SUBJECT, SUBJECT, IS, TYPE)
     name(SUBJECT, 'subject')
     storage(SUBJECT, 'segment_subject')