Browse Source

Module shuffle:

* Move lakesuperior.model.graph to lakesuperior.model.rdf
* Move lakesuperior.model.structures.callbacks to lakesuperior.model.callbacks.
Stefano Cossu 5 năm trước cách đây
mục cha
commit
f92fafd009

+ 0 - 0
lakesuperior/model/graph/__init__.pxd → lakesuperior/model/__init__.pxd


+ 0 - 0
lakesuperior/model/structures/callbacks.pxd → lakesuperior/model/callbacks.pxd


+ 0 - 0
lakesuperior/model/structures/callbacks.pyx → lakesuperior/model/callbacks.pyx


+ 1 - 1
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 Graph
+from lakesuperior.model.rdf.graph import Graph
 
 
 LDP_NR_TYPE = nsc['ldp'].NonRDFSource

+ 1 - 1
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 Graph
+from lakesuperior.model.rdf.graph import Graph as Graph
 from lakesuperior.store.ldp_rs.rsrc_centric_layout import VERS_CONT_LABEL
 from lakesuperior.toolbox import Toolbox
 

+ 0 - 0
lakesuperior/model/graph/__init__.py → lakesuperior/model/rdf/__init__.pxd


+ 0 - 0
lakesuperior/model/rdf/__init__.py


+ 2 - 2
lakesuperior/model/graph/graph.pxd → lakesuperior/model/rdf/graph.pxd

@@ -5,7 +5,7 @@ from cymem.cymem cimport Pool
 cimport lakesuperior.cy_include.collections as cc
 
 from lakesuperior.model.base cimport Key, TripleKey
-from lakesuperior.model.graph.triple cimport BufferTriple
+from lakesuperior.model.rdf.triple cimport BufferTriple
 from lakesuperior.model.structures.keyset cimport Keyset
 from lakesuperior.store.ldp_rs cimport lmdb_triplestore
 
@@ -16,7 +16,7 @@ ctypedef void (*lookup_callback_fn_t)(
 
 cdef class Graph:
     cdef:
-        lmdb_triplestore.LmdbTriplestore store
+        readonly lmdb_triplestore.LmdbTriplestore store
         public Keyset keys
         public object uri
 

+ 12 - 14
lakesuperior/model/graph/graph.pyx → lakesuperior/model/rdf/graph.pyx

@@ -8,12 +8,12 @@ from libc.string cimport memcpy
 from libc.stdlib cimport free
 
 cimport lakesuperior.cy_include.collections as cc
-cimport lakesuperior.model.structures.callbacks as cb
+cimport lakesuperior.model.callbacks as cb
 cimport lakesuperior.model.structures.keyset as kset
 
 from lakesuperior.model.base cimport Key, TripleKey
-from lakesuperior.model.graph cimport term
-from lakesuperior.model.graph.triple cimport BufferTriple
+from lakesuperior.model.rdf cimport term
+from lakesuperior.model.rdf.triple cimport BufferTriple
 from lakesuperior.model.structures.hash cimport term_hash_seed32
 from lakesuperior.model.structures.keyset cimport Keyset
 
@@ -70,7 +70,8 @@ cdef class Graph:
         """
         self.uri = rdflib.URIRef(uri) if uri else None
 
-        self.store = store or env.app_globals.rdf_store
+        self.store = store if store is not None else env.app_globals.rdf_store
+        logger.debug(f'Assigned store at {self.store.env_path}')
 
         # Initialize empty data set.
         if data:
@@ -310,19 +311,16 @@ cdef class Graph:
         :param iterable triples: iterable of 3-tuple triples.
         """
         cdef:
-            Key sk, pk, ok
-            TripleKey spok = [sk, pk, ok]
+            TripleKey spok
 
         for s, p, o in triples:
             logger.info(f'Adding {s} {p} {o} to store: {self.store}')
-            sk = self.store.to_key(s)
-            logger.info(f'sk: {sk}')
-            pk = self.store.to_key(p)
-            logger.info(f'pk: {pk}')
-            ok = self.store.to_key(o)
-            logger.info(f'ok: {ok}')
-
-            logger.info(f'spok: {sk} {pk} {ok}')
+            spok = [
+                self.store.to_key(s),
+                self.store.to_key(p),
+                self.store.to_key(o),
+            ]
+
             self.keys.add(&spok, True)
 
 

+ 0 - 0
lakesuperior/model/graph/term.pxd → lakesuperior/model/rdf/term.pxd


+ 0 - 0
lakesuperior/model/graph/term.pyx → lakesuperior/model/rdf/term.pyx


+ 1 - 1
lakesuperior/model/graph/triple.pxd → lakesuperior/model/rdf/triple.pxd

@@ -1,6 +1,6 @@
 #from lakesuperior.cy_include cimport cytpl as tpl
 from lakesuperior.model.base cimport Buffer
-from lakesuperior.model.graph.term cimport Term
+from lakesuperior.model.rdf.term cimport Term
 
 # Triple of Term structs.
 ctypedef struct Triple:

+ 0 - 0
lakesuperior/model/graph/triple.pyx → lakesuperior/model/rdf/triple.pyx


+ 1 - 1
lakesuperior/model/structures/keyset.pyx

@@ -3,7 +3,7 @@ import logging
 from libc.string cimport memcmp, memcpy
 from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free
 
-cimport lakesuperior.model.structures.callbacks as cb
+cimport lakesuperior.model.callbacks as cb
 
 from lakesuperior.model.base cimport NULL_TRP, TRP_KLEN, TripleKey
 

+ 2 - 5
lakesuperior/store/ldp_rs/lmdb_triplestore.pxd

@@ -1,11 +1,8 @@
 cimport lakesuperior.cy_include.collections as cc
 cimport lakesuperior.cy_include.cylmdb as lmdb
-cimport lakesuperior.cy_include.cytpl as tpl
 
-from lakesuperior.model.base cimport (
-    Key, DoubleKey, TripleKey, Buffer
-)
-from lakesuperior.model.graph.graph cimport Graph
+from lakesuperior.model.base cimport Key, DoubleKey, TripleKey, Buffer
+from lakesuperior.model.rdf.graph cimport Graph
 from lakesuperior.model.structures.keyset cimport Keyset
 from lakesuperior.store.base_lmdb_store cimport BaseLmdbStore
 

+ 6 - 10
lakesuperior/store/ldp_rs/lmdb_triplestore.pyx

@@ -3,15 +3,13 @@ import sys
 
 import rdflib
 
-from cython.parallel import prange
+#from cython.parallel import prange
 from rdflib.graph import DATASET_DEFAULT_GRAPH_ID as RDFLIB_DEFAULT_GRAPH_URI
 
 from lakesuperior.store.base_lmdb_store import (
         KeyExistsError, KeyNotFoundError, LmdbError)
-from lakesuperior.store.base_lmdb_store cimport _check
 
 from libc.stdlib cimport malloc, free
-from libc.string cimport memcpy
 
 cimport lakesuperior.cy_include.collections as cc
 cimport lakesuperior.cy_include.cylmdb as lmdb
@@ -21,14 +19,12 @@ from lakesuperior.model.base cimport (
     Key, DoubleKey, TripleKey, QuadKey,
     Buffer, buffer_dump
 )
-from lakesuperior.model.graph.graph cimport Graph
-from lakesuperior.model.graph.term cimport Term
-from lakesuperior.model.graph.triple cimport BufferTriple
-
 from lakesuperior.store.base_lmdb_store cimport (
-        BaseLmdbStore, data_v, dbi, key_v)
-from lakesuperior.model.graph.term cimport (
-        deserialize_to_rdflib, serialize_from_rdflib)
+        _check, BaseLmdbStore, data_v, dbi, key_v)
+from lakesuperior.model.rdf.graph cimport Graph
+from lakesuperior.model.rdf.term cimport (
+        Term, deserialize_to_rdflib, serialize_from_rdflib)
+from lakesuperior.model.rdf.triple cimport BufferTriple
 from lakesuperior.model.structures.hash cimport (
         HLEN_128 as HLEN, Hash128, hash128)
 

+ 1 - 1
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
+from lakesuperior.model.rdf.graph import Graph
 
 
 META_GR_URI = nsc['fcsystem']['meta']

+ 13 - 2
setup.py

@@ -87,6 +87,17 @@ extensions = [
         #extra_compile_args=['-fopenmp'],
         #extra_link_args=['-fopenmp']
     ),
+    Extension(
+        'lakesuperior.model.callbacks',
+        [
+            path.join('lakesuperior', 'model', f'callbacks.{ext}'),
+        ],
+        include_dirs=include_dirs,
+        extra_compile_args=['-g'],
+        extra_link_args=['-g'],
+        #extra_compile_args=['-fopenmp'],
+        #extra_link_args=['-fopenmp']
+    ),
     Extension(
         'lakesuperior.model.structures.*',
         [
@@ -120,7 +131,7 @@ extensions = [
         extra_link_args=['-g'],
     ),
     Extension(
-        'lakesuperior.model.graph.*',
+        'lakesuperior.model.rdf.*',
         [
             path.join(tpl_src_dir, 'tpl.c'),
             path.join(spookyhash_src_dir, 'context.c'),
@@ -130,7 +141,7 @@ extensions = [
             path.join(coll_src_dir, 'array.c'),
             path.join(coll_src_dir, 'hashtable.c'),
             path.join(coll_src_dir, 'hashset.c'),
-            path.join('lakesuperior', 'model', 'graph', f'*.{ext}'),
+            path.join('lakesuperior', 'model', 'rdf', f'*.{ext}'),
         ],
         include_dirs=include_dirs,
         #extra_compile_args=['-fopenmp'],

+ 5 - 3
tests/0_data_structures/test_graph.py

@@ -5,7 +5,7 @@ from shutil import rmtree
 
 from rdflib import Graph, Namespace, URIRef
 
-from lakesuperior.model.graph.graph import Graph
+from lakesuperior.model.rdf.graph import Graph
 from lakesuperior.store.ldp_rs.lmdb_store import LmdbStore
 
 
@@ -46,12 +46,14 @@ class TestGraphInit:
     """
     Test initialization of graphs with different base data sets.
     """
-    def test_empty(self):
+    def test_empty(self, store):
         """
         Test creation of an empty graph.
         """
-        gr = Graph()
+        with store.txn_ctx():
+            gr = Graph(store)
 
+        # len() should not need a DB transaction open.
         assert len(gr) == 0
 
 

+ 1 - 1
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 Graph
+from lakesuperior.model.rdf.graph import Graph
 
 
 @pytest.fixture(scope='class')

+ 1 - 1
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 Graph
+from lakesuperior.model.rdf.graph import Graph
 
 
 @pytest.fixture(scope='module')