Stefano Cossu 5 rokov pred
rodič
commit
0009146b12

+ 1 - 5
lakesuperior/model/graph/graph.pyx

@@ -7,8 +7,6 @@ from lakesuperior import env
 from libc.string cimport memcpy
 from libc.stdlib cimport free
 
-from cymem.cymem cimport Pool
-
 cimport lakesuperior.cy_include.collections as cc
 cimport lakesuperior.model.structures.callbacks as cb
 cimport lakesuperior.model.structures.keyset as kset
@@ -51,7 +49,7 @@ cdef class Graph:
     """
 
     def __cinit__(
-        self, store, size_t ct=0, str uri=None, set data=set()
+        self, store=None, size_t ct=0, str uri=None, set data=set()
     ):
         """
         Initialize the graph, optionally from Python/RDFlib data.
@@ -71,8 +69,6 @@ cdef class Graph:
             instances.
         """
 
-        self.pool = Pool()
-
         if not store:
             store = env.app_globals.rdf_store
         # Initialize empty data set.

+ 3 - 3
lakesuperior/model/ldp/ldp_factory.py

@@ -16,7 +16,7 @@ from lakesuperior.dictionaries.namespaces import ns_collection as nsc
 from lakesuperior.exceptions import (
         IncompatibleLdpTypeError, InvalidResourceError, ResourceExistsError,
         ResourceNotExistsError, TombstoneError)
-from lakesuperior.model.graph.graph import Imr
+from lakesuperior.model.graph.graph import Graph
 
 
 LDP_NR_TYPE = nsc['ldp'].NonRDFSource
@@ -37,7 +37,7 @@ class LdpFactory:
             raise InvalidResourceError(uid)
         if rdfly.ask_rsrc_exists(uid):
             raise ResourceExistsError(uid)
-        rsrc = Ldpc(uid, provided_imr=Imr(uri=nsc['fcres'][uid]))
+        rsrc = Ldpc(uid, provided_imr=Graph(uri=nsc['fcres'][uid]))
 
         return rsrc
 
@@ -107,7 +107,7 @@ class LdpFactory:
         else:
             data = set()
 
-        provided_imr = Imr(uri=uri, data=data)
+        provided_imr = Graph(uri=uri, data=data)
         #logger.debug('Provided graph: {}'.format(
         #        pformat(set(provided_imr))))
 

+ 7 - 7
lakesuperior/model/ldp/ldpr.py

@@ -26,7 +26,7 @@ from lakesuperior.dictionaries.srv_mgd_terms import (
 from lakesuperior.exceptions import (
     InvalidResourceError, RefIntViolationError, ResourceNotExistsError,
     ServerManagedTermError, TombstoneError)
-from lakesuperior.model.graph.graph import Graph as SimpleGraph, Imr
+from lakesuperior.model.graph.graph import Graph as Graph
 from lakesuperior.store.ldp_rs.rsrc_centric_layout import VERS_CONT_LABEL
 from lakesuperior.toolbox import Toolbox
 
@@ -233,7 +233,7 @@ class Ldpr(metaclass=ABCMeta):
         :param v: New set of triples to populate the IMR with.
         :type v: set or rdflib.Graph
         """
-        self._imr = Imr(self.uri, data=set(data))
+        self._imr = Graph(uri=self.uri, data=set(data))
 
 
     @imr.deleter
@@ -266,8 +266,8 @@ class Ldpr(metaclass=ABCMeta):
         """
         Set resource metadata.
         """
-        if not isinstance(rsrc, Imr):
-            raise TypeError('Provided metadata is not an Imr object.')
+        if not isinstance(rsrc, Graph):
+            raise TypeError('Provided metadata is not a Graph object.')
         self._metadata = rsrc
 
 
@@ -292,7 +292,7 @@ class Ldpr(metaclass=ABCMeta):
             ):
                 out_trp.add(t)
 
-        return Imr(uri = self.uri, data=out_trp)
+        return Graph(uri=self.uri, data=out_trp)
 
 
     @property
@@ -304,7 +304,7 @@ class Ldpr(metaclass=ABCMeta):
             try:
                 self._version_info = rdfly.get_version_info(self.uid)
             except ResourceNotExistsError as e:
-                self._version_info = Imr(uri=self.uri)
+                self._version_info = Graph(uri=self.uri)
 
         return self._version_info
 
@@ -582,7 +582,7 @@ class Ldpr(metaclass=ABCMeta):
 
         ver_gr = rdfly.get_imr(
             self.uid, ver_uid=ver_uid, incl_children=False)
-        self.provided_imr = Imr(uri=self.uri)
+        self.provided_imr = Graph(uri=self.uri)
 
         for t in ver_gr:
             if not self._is_trp_managed(t):

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

@@ -6,7 +6,6 @@ import rdflib
 from cython.parallel import prange
 from rdflib.graph import DATASET_DEFAULT_GRAPH_ID as RDFLIB_DEFAULT_GRAPH_URI
 
-from lakesuperior.model.graph.graph import Imr
 from lakesuperior.store.base_lmdb_store import (
         KeyExistsError, KeyNotFoundError, LmdbError)
 from lakesuperior.store.base_lmdb_store cimport _check
@@ -1112,8 +1111,6 @@ cdef class LmdbTriplestore(BaseLmdbStore):
     ) except *:
         """
         Get a list of all contexts.
-
-        :rtype: Iterator(lakesuperior.model.graph.graph.Imr)
         """
         cdef:
             size_t ct

+ 6 - 4
lakesuperior/store/ldp_rs/rsrc_centric_layout.py

@@ -24,7 +24,7 @@ from lakesuperior.dictionaries.srv_mgd_terms import  srv_mgd_subjects, \
 from lakesuperior.globals import ROOT_RSRC_URI
 from lakesuperior.exceptions import (InvalidResourceError,
         ResourceNotExistsError, TombstoneError, PathSegmentError)
-from lakesuperior.model.graph.graph import Graph, Imr
+from lakesuperior.model.graph.graph import Graph
 
 
 META_GR_URI = nsc['fcsystem']['meta']
@@ -291,7 +291,7 @@ class RsrcCentricLayout:
         if not incl_children:
             contexts.remove(nsc['fcstruct'][uid])
 
-        imr = Imr(uri=nsc['fcres'][uid])
+        imr = Graph(self.store, uri=nsc['fcres'][uid])
 
         for ctx in contexts:
             gr = self.store.triple_keys((None, None, None), ctx)
@@ -299,7 +299,9 @@ class RsrcCentricLayout:
 
         # Include inbound relationships.
         if incl_inbound and len(imr):
-            gr = Graph({*self.get_inbound_rel(nsc['fcres'][uid])})
+            gr = Graph(
+                self.store, data={*self.get_inbound_rel(nsc['fcres'][uid])}
+            )
             imr |= gr
 
         if strict:
@@ -375,7 +377,7 @@ class RsrcCentricLayout:
         # URI with the subject URI. But the concepts of data and metadata in
         # Fedora are quite fluid anyways...
 
-        vmeta = Imr(uri=nsc['fcres'][uid])
+        vmeta = Graph(self.store, uri=nsc['fcres'][uid])
 
         #Get version graphs proper.
         for vtrp in self.store.triple_keys(

+ 60 - 60
tests/0_data_structures/test_graph.py

@@ -4,7 +4,7 @@ from shutil import rmtree
 
 from rdflib import Graph, Namespace, URIRef
 
-from lakesuperior.model.graph.graph import SimpleGraph, Imr
+from lakesuperior.model.graph.graph import Graph
 from lakesuperior.store.ldp_rs.lmdb_store import LmdbStore
 
 
@@ -49,7 +49,7 @@ class TestGraphInit:
         """
         Test creation of an empty graph.
         """
-        gr = SimpleGraph()
+        gr = Graph()
 
         assert len(gr) == 0
 
@@ -58,7 +58,7 @@ class TestGraphInit:
         """
         Test creation using a Python set.
         """
-        gr = SimpleGraph(data=set(trp))
+        gr = Graph(data=set(trp))
 
         assert len(gr) == 6
 
@@ -91,7 +91,7 @@ class TestGraphOps:
         """
         Test the length of a graph with and without duplicates.
         """
-        gr = SimpleGraph()
+        gr = Graph()
         assert len(gr) == 0
 
         gr.add((trp[0],))
@@ -111,7 +111,7 @@ class TestGraphOps:
         """
         Test operations with duplicate triples.
         """
-        gr = SimpleGraph()
+        gr = Graph()
         #import pdb; pdb.set_trace()
 
         gr.add((trp[0],))
@@ -123,7 +123,7 @@ class TestGraphOps:
         """
         Test adding and removing triples.
         """
-        gr = SimpleGraph()
+        gr = Graph()
 
         gr.add(trp)
         gr.remove(trp[0])
@@ -147,8 +147,8 @@ class TestGraphOps:
         """
         Test graph union.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -164,8 +164,8 @@ class TestGraphOps:
         """
         Test graph in-place union.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -181,8 +181,8 @@ class TestGraphOps:
         """
         Test graph addition.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -198,8 +198,8 @@ class TestGraphOps:
         """
         Test graph in-place addition.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -215,8 +215,8 @@ class TestGraphOps:
         """
         Test graph addition.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -245,8 +245,8 @@ class TestGraphOps:
         """
         Test graph in-place addition.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -266,8 +266,8 @@ class TestGraphOps:
         """
         Test graph intersextion.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -285,8 +285,8 @@ class TestGraphOps:
         """
         Test graph intersextion.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -304,8 +304,8 @@ class TestGraphOps:
         """
         Test graph intersextion.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -323,8 +323,8 @@ class TestGraphOps:
         """
         Test graph intersextion.
         """
-        gr1 = SimpleGraph()
-        gr2 = SimpleGraph()
+        gr1 = Graph()
+        gr2 = Graph()
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -340,15 +340,15 @@ class TestGraphOps:
 
 
 @pytest.mark.usefixtures('trp')
-class TestImrOps:
+class TestNamedGraphOps:
     """
-    Test various graph operations.
+    Test various operations on a named graph.
     """
     def test_len(self, trp):
         """
         Test the length of a graph with and without duplicates.
         """
-        imr = Imr(uri='http://example.edu/imr01')
+        imr = Graph(uri='http://example.edu/imr01')
         assert len(imr) == 0
 
         imr.add((trp[0],))
@@ -368,7 +368,7 @@ class TestImrOps:
         """
         Test operations with duplicate triples.
         """
-        imr = Imr(uri='http://example.edu/imr01')
+        imr = Graph(uri='http://example.edu/imr01')
         #import pdb; pdb.set_trace()
 
         imr.add((trp[0],))
@@ -380,7 +380,7 @@ class TestImrOps:
         """
         Test adding and removing triples.
         """
-        imr = Imr(uri='http://example.edu/imr01')
+        imr = Graph(uri='http://example.edu/imr01')
 
         imr.add(trp)
         imr.remove(trp[0])
@@ -404,8 +404,8 @@ class TestImrOps:
         """
         Test graph union.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -423,8 +423,8 @@ class TestImrOps:
         """
         Test graph in-place union.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -442,8 +442,8 @@ class TestImrOps:
         """
         Test graph addition.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -461,8 +461,8 @@ class TestImrOps:
         """
         Test graph in-place addition.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -480,8 +480,8 @@ class TestImrOps:
         """
         Test graph addition.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -514,8 +514,8 @@ class TestImrOps:
         """
         Test graph in-place addition.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -537,8 +537,8 @@ class TestImrOps:
         """
         Test graph intersextion.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -558,8 +558,8 @@ class TestImrOps:
         """
         Test graph intersextion.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -579,8 +579,8 @@ class TestImrOps:
         """
         Test graph intersextion.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -600,8 +600,8 @@ class TestImrOps:
         """
         Test graph intersextion.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = Imr(uri='http://example.edu/imr02')
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph(uri='http://example.edu/imr02')
 
         gr1.add(trp[0:4])
         gr2.add(trp[2:6])
@@ -628,8 +628,8 @@ class TestHybridOps:
         """
         Test hybrid IMR + graph union.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = SimpleGraph()
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph()
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -640,12 +640,12 @@ class TestHybridOps:
         assert trp[0] in gr3
         assert trp[4] in gr3
 
-        assert isinstance(gr3, Imr)
+        assert isinstance(gr3, Graph)
         assert gr3.uri == URIRef('http://example.edu/imr01')
 
         gr4 = gr2 | gr1
 
-        assert isinstance(gr4, SimpleGraph)
+        assert isinstance(gr4, Graph)
 
         assert gr3 == gr4
 
@@ -654,8 +654,8 @@ class TestHybridOps:
         """
         Test IMR + graph in-place union.
         """
-        gr1 = Imr(uri='http://example.edu/imr01')
-        gr2 = SimpleGraph()
+        gr1 = Graph(uri='http://example.edu/imr01')
+        gr2 = Graph()
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -673,8 +673,8 @@ class TestHybridOps:
         """
         Test graph + IMR in-place union.
         """
-        gr1 = SimpleGraph()
-        gr2 = Imr(uri='http://example.edu/imr01')
+        gr1 = Graph()
+        gr2 = Graph(uri='http://example.edu/imr01')
 
         gr1.add(trp[0:3])
         gr2.add(trp[2:6])
@@ -685,4 +685,4 @@ class TestHybridOps:
         assert trp[0] in gr1
         assert trp[4] in gr1
 
-        assert isinstance(gr1, SimpleGraph)
+        assert isinstance(gr1, Graph)

+ 5 - 5
tests/1_store/test_lmdb_store.py

@@ -8,7 +8,7 @@ from rdflib.graph import DATASET_DEFAULT_GRAPH_ID as RDFLIB_DEFAULT_GRAPH_URI
 from rdflib.namespace import RDF, RDFS
 
 from lakesuperior.store.ldp_rs.lmdb_store import LmdbStore
-from lakesuperior.model.graph.graph import Imr
+from lakesuperior.model.graph.graph import Graph
 
 
 @pytest.fixture(scope='class')
@@ -784,11 +784,11 @@ class TestContext:
             res_no_ctx = store.triples(trp3)
             res_ctx = store.triples(trp3, gr2_uri)
             for res in res_no_ctx:
-                assert Imr(uri=gr_uri) in res[1]
-                assert Imr(uri=gr2_uri) in res[1]
+                assert Graph(uri=gr_uri) in res[1]
+                assert Graph(uri=gr2_uri) in res[1]
             for res in res_ctx:
-                assert Imr(uri=gr_uri) in res[1]
-                assert Imr(uri=gr2_uri) in res[1]
+                assert Graph(uri=gr_uri) in res[1]
+                assert Graph(uri=gr2_uri) in res[1]
 
 
     def test_delete_from_ctx(self, store):

+ 2 - 2
tests/2_api/test_resource_api.py

@@ -14,7 +14,7 @@ from lakesuperior.exceptions import (
         TombstoneError)
 from lakesuperior.globals import RES_CREATED, RES_UPDATED
 from lakesuperior.model.ldp.ldpr import Ldpr
-from lakesuperior.model.graph.graph import SimpleGraph, Imr
+from lakesuperior.model.graph.graph import Graph
 
 
 @pytest.fixture(scope='module')
@@ -67,7 +67,7 @@ class TestResourceCRUD:
         The ``dcterms:title`` property should NOT be included.
         """
         gr = rsrc_api.get_metadata('/')
-        assert isinstance(gr, SimpleGraph)
+        assert isinstance(gr, Graph)
         assert len(gr) == 9
         assert gr[gr.uri : nsc['rdf'].type : nsc['ldp'].Resource ]
         assert not gr[