Explorar o código

Move Query API.

Stefano Cossu %!s(int64=6) %!d(string=hai) anos
pai
achega
1f43980619
Modificáronse 4 ficheiros con 33 adicións e 22 borrados
  1. 9 2
      doc/notes/TODO
  2. 21 0
      lakesuperior/api/query.py
  3. 3 3
      lakesuperior/endpoints/query.py
  4. 0 17
      lakesuperior/query.py

+ 9 - 2
doc/notes/TODO

@@ -85,11 +85,18 @@
 
 # Alpha 7
 
-- [W] Refactor for Python API
-- [ ] Complete messaging
+- [D] Refactor for Python API
+  - [D] Main structure
+  - [D] LDP
+  - [D] Admin
+  - [D] Query
+- [ ] Align logger variable
+- [ ] CLI prototype
+- [ ] Update documentation
 
 # Alpha 8
 
+- [ ] Complete messaging
 - [ ] Term query API
 - [ ] Better management of versions
 - [ ] Complete revert to version and resurrect

+ 21 - 0
lakesuperior/api/query.py

@@ -0,0 +1,21 @@
+import logging
+
+from lakesuperior.dictionaries.namespaces import ns_collection as nsc
+from lakesuperior.dictionaries.namespaces import ns_mgr as nsm
+from lakesuperior.env import env
+
+
+logger = logging.getLogger(__name__)
+rdfly = env.app_globals.rdfly
+
+
+def sparql_query(qry_str):
+    '''
+    Send a SPARQL query to the triplestore.
+
+    @param qry_str (str) SPARQL query string. SPARQL 1.1 Query Language
+    (https://www.w3.org/TR/sparql11-query/) is supported.
+
+    @return rdflib.query.QueryResult
+    '''
+    return rdfly.raw_query(qry_str)

+ 3 - 3
lakesuperior/endpoints/query.py

@@ -5,7 +5,7 @@ from rdflib.plugin import PluginException
 
 from lakesuperior.env import env
 from lakesuperior.dictionaries.namespaces import ns_mgr as nsm
-from lakesuperior.query import QueryEngine
+from lakesuperior.api import query as query_api
 from lakesuperior.store.ldp_rs.lmdb_store import LmdbStore, TxnManager
 
 # Query endpoint. raw SPARQL queries exposing the underlying layout can be made
@@ -44,7 +44,7 @@ def sparql():
     '''
     Perform a direct SPARQL query on the underlying triplestore.
 
-    @param q SPARQL query string.
+    @param qry SPARQL query string.
     '''
     accept_mimetypes = {
         'text/csv': 'csv',
@@ -56,7 +56,7 @@ def sparql():
     else:
         logger.debug('Query: {}'.format(request.form['query']))
         with TxnManager(rdf_store) as txn:
-            qres = QueryEngine().sparql_query(request.form['query'])
+            qres = query_api.sparql_query(request.form['query'])
 
             match = request.accept_mimetypes.best_match(accept_mimetypes.keys())
             if match:

+ 0 - 17
lakesuperior/query.py

@@ -1,17 +0,0 @@
-from flask import current_app, g
-
-from lakesuperior.dictionaries.namespaces import ns_collection as nsc
-from lakesuperior.dictionaries.namespaces import ns_mgr as nsm
-
-class QueryEngine:
-    '''
-    Handle both simple term-based and full-fledged SPARQL queries.
-    '''
-
-    def sparql_query(self, qry):
-        '''
-        Send a SPARQL query to the triplestore.
-
-        The returned value may be different.
-        '''
-        return current_app.rdfly.raw_query(qry)