diff options
author | Munyoki Kilyungi | 2023-10-24 10:27:23 +0300 |
---|---|---|
committer | BonfaceKilz | 2023-10-27 13:45:32 +0300 |
commit | 17d137ff33fa704b6a148331997135a5abcd0b8b (patch) | |
tree | 78f14777e9fef1997c2e2c4592c65978d57d1070 | |
parent | ddc020ada152997abefe65b6ac162ebc6b971e89 (diff) | |
download | genenetwork3-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>
-rw-r--r-- | gn3/api/metadata.py | 1 | ||||
-rw-r--r-- | gn3/db/rdf.py | 47 |
2 files changed, 0 insertions, 48 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py index 435199b..84c1e72 100644 --- a/gn3/api/metadata.py +++ b/gn3/api/metadata.py @@ -12,7 +12,6 @@ from flask import current_app from pyld import jsonld from SPARQLWrapper import JSON, JSONLD, SPARQLWrapper -from gn3.db.rdf import sparql_query from gn3.db.rdf import RDF_PREFIXES, PREFIXES 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),) |