aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-10-24 10:27:23 +0300
committerBonfaceKilz2023-10-27 13:45:32 +0300
commit17d137ff33fa704b6a148331997135a5abcd0b8b (patch)
tree78f14777e9fef1997c2e2c4592c65978d57d1070 /gn3/db
parentddc020ada152997abefe65b6ac162ebc6b971e89 (diff)
downloadgenenetwork3-17d137ff33fa704b6a148331997135a5abcd0b8b.tar.gz
Delete gn3.db.rdf.sparql_query.
* gn3/api/metadata.py: Remove sparql_query import. * gn3/db/rdf.py: Remove unused imports. (sparql_query): Delete. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/rdf.py47
1 files changed, 0 insertions, 47 deletions
diff --git a/gn3/db/rdf.py b/gn3/db/rdf.py
index 857e7c2..54458ac 100644
--- a/gn3/db/rdf.py
+++ b/gn3/db/rdf.py
@@ -3,15 +3,6 @@
This module is a collection of functions that handle SPARQL queries.
"""
-from typing import Tuple
-from string import Template
-from urllib.parse import unquote
-from urllib.parse import urlparse
-
-from SPARQLWrapper import JSON, SPARQLWrapper
-
-from gn3.monads import MonadicDict
-
PREFIXES = {
"dcat": "http://www.w3.org/ns/dcat#",
"dct": "http://purl.org/dc/terms/",
@@ -39,41 +30,3 @@ PREFIXES = {
RDF_PREFIXES = "\n".join([f"PREFIX {key}: <{value}>"for key, value in PREFIXES.items()])
-
-
-def sparql_query(
- sparql_conn: SPARQLWrapper, query: str,
-) -> Tuple[MonadicDict, ...]:
- """Run a SPARQL query and return the bound variables."""
- def __add_value_to_dict(key, value, my_dict):
- _values = set()
- if key in my_dict:
- if isinstance(my_dict[key], list):
- _values = set(my_dict[key])
- else:
- _values = set([my_dict[key]])
- _values.add(value)
- if _values:
- return list(_values)
- return value
-
- sparql_conn.setQuery(query)
- sparql_conn.setReturnFormat(JSON)
- parsed_response: dict = {}
- results = sparql_conn.queryAndConvert()["results"]["bindings"] # type: ignore
- if results:
- for result in results:
- if "s" in result: # A CONSTRUCT
- key = result["p"]["value"] # type: ignore
- value = result["o"]["value"] # type: ignore
- parsed_response[key] = __add_value_to_dict(
- key, value, parsed_response
- )
- elif "key" in result: # A SELECT
- parsed_response[
- result["key"] # type: ignore
- ] = __add_value_to_dict(
- result["key"], result["value"], # type: ignore
- parsed_response
- )
- return (MonadicDict(parsed_response),)