Commits

March Liu committed de56883

debug

Comments (0)

Files changed (2)

src/socrates/core.py

 
             for r in res:
                 if r.name not in ('string', 'subject'):
-                    self.registeType(r.name, storage=r.storage,)
+                    self.registeType(r.name.encode('utf-8'), storage=r.storage.encode('utf-8'),)
 
     def __del__(self):
         self.close()
         #session.close()
         return re
 
+    def querySegments(self, queryExpr):
+        """
+Subject 只依赖 Id, Predicate 可以由谓词表达式决定。当前可以只针对宾语允许接受 
+SQLALchemy 形式的查询表达式。另一方面,应该使查询构造尽量接近 SQLAlchemy 的方式。
+目前而言可以先不考虑联接查询等复杂查询功能的实现,能实现到对每子句的过滤就可以了。
+例如:
+>> storage = Storage("sqlite://", create=True)
+>> storage.query(expr.predicate=prdExpr).filter("==xxx").filter("@@'text'").all()
+>> storage.query(expr.obj==xxx).filter("~ 'regex'").one()
+>> storage.query(expr.obj!=xxx).filter("prdexpr > :day").params(day=today).all()
+        """
+
+    def querySubjects(self, queryExpr):
+        """
+当前版本直接封装 querySegments。可以 union (select subject_id from segment_xxx),然后 distinct。
+        """
+        pass
+
     def get_predicate_id_by_name(self, name):
         """
 >>> storage = Storage("sqlite://", create=True)

src/socrates/types.py

 #!/usr/bin/env python
 # -*- coding:utf-8 -*-
 from socrates import meta
+from socrates.parser.prdparser.parse import ExprParser as PrdExprParser
 
 class Subject(object):
     def __init__(self, storage, segments):
         self.__storage = storage
         self.segments = segments
         self.subject_id=segments[0].subject_id
-        self.prdexprpaser = Prdexprpaser()
+        self.prdexprpaser = PrdExprParser()
     def write(self, prdexpr, obj):
         segment = self.__storage.writeSegment(self.subject_id, prdexpr, obj)
         self.segments.append(segment)