Ver código fonte

Adapt some higher-level model methods to SimpleGraph.

Stefano Cossu 5 anos atrás
pai
commit
ff64547d75

+ 1 - 2
lakesuperior/model/ldp/ldpr.py

@@ -422,8 +422,7 @@ class Ldpr(metaclass=ABCMeta):
 
         remove_trp = {
             (self.uri, pred, None) for pred in self.delete_preds_on_replace}
-        add_trp = set(
-            self.provided_imr | self._containment_rel(create))
+        add_trp = {*self.provided_imr} | self._containment_rel(create)
 
         self.modify(ev_type, remove_trp, add_trp)
 

+ 1 - 1
lakesuperior/store/ldp_rs/lmdb_triplestore.pxd

@@ -63,7 +63,7 @@ cdef class LmdbTriplestore(BaseLmdbStore):
     cpdef void _remove_graph(self, object gr_uri) except *
     cpdef tuple all_namespaces(self)
     cpdef tuple all_contexts(self, triple=*)
-    cpdef SimpleGraph graph_lookup(self, triple_pattern, context=*)
+    cpdef SimpleGraph graph_lookup(self, triple_pattern, context=*, uri=*)
 
     cdef:
         void _add_graph(self, Buffer *pk_gr) except *

+ 11 - 3
lakesuperior/store/ldp_rs/lmdb_triplestore.pyx

@@ -696,15 +696,19 @@ cdef class LmdbTriplestore(BaseLmdbStore):
             self._cur_close(cur)
 
 
-    cpdef SimpleGraph graph_lookup(self, triple_pattern, context=None):
+    cpdef SimpleGraph graph_lookup(
+            self, triple_pattern, context=None, uri=None
+    ):
         """
-        Create a SimpleGraph instance from "borrowed" buffers from the store.
+        Create a SimpleGraph or Imr instance from buffers from the store.
 
         The instance is only valid within the LMDB transaction that created it.
 
         :param tuple triple_pattern: 3 RDFLib terms
         :param context: Context graph, if available.
         :type context: rdflib.Graph or None
+        :param str uri: URI for the resource. If provided, the resource
+            returned will be an Imr, otherwise a SimpleGraph.
 
         :rtype: Iterator
         :return: Generator over triples and contexts in which each result has
@@ -718,7 +722,11 @@ cdef class LmdbTriplestore(BaseLmdbStore):
         cdef:
             unsigned char* spok
             size_t cur = 0
-            SimpleGraph gr = SimpleGraph()
+            Buffer* buffers
+            BufferTriple* btrp
+            SimpleGraph gr
+
+        gr = Imr(uri=uri) if uri else SimpleGraph()
 
         logger.debug(
                 'Getting triples for: {}, {}'.format(triple_pattern, context))

+ 11 - 7
lakesuperior/store/ldp_rs/rsrc_centric_layout.py

@@ -332,10 +332,11 @@ class RsrcCentricLayout:
         logger.debug('Getting metadata for: {}'.format(uid))
         if ver_uid:
             uid = self.snapshot_uid(uid, ver_uid)
-        imr = Imr(
-                uri=nsc['fcres'][uid],
-                lookup=((None, None, None), nsc['fcadmin'][uid]),
-                store=self.store)
+        imr = self.store.graph_lookup(
+            (None, None, None),
+            context=nsc['fcadmin'][uid],
+            uri=nsc['fcres'][uid]
+        )
 
         if strict:
             self._check_rsrc_status(imr)
@@ -354,9 +355,11 @@ class RsrcCentricLayout:
         # graph. If multiple user-provided graphs will be supported, this
         # should use another query to get all of them.
         uri = nsc['fcres'][uid]
-        userdata = Imr(
-                uri=uri, lookup=((uri, None, None),nsc['fcmain'][uid]),
-                store=self.store)
+        userdata = self.store.graph_lookup(
+            (None, None, None),
+            context=nsc['fcmain'][uid],
+            uri=uri
+        )
 
         return userdata
 
@@ -671,6 +674,7 @@ class RsrcCentricLayout:
         """
         Check if a resource is not existing or if it is a tombstone.
         """
+        #import pdb; pdb.set_trace()
         uid = self.uri_to_uid(imr.uri)
         if not len(imr):
             raise ResourceNotExistsError(uid)