aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-09-10 11:19:55 +0300
committerBonfaceKilz2024-09-11 10:30:57 +0300
commit3c17971ca54260f8a436dd9f3a0db8d5d42b4418 (patch)
tree7f8902e6916d9693742a9fced810a8d677e2b84a /gn3
parenta7d9165a7ca1e6b9e7fdeb6fba61ebf335c6a0d3 (diff)
downloadgenenetwork3-3c17971ca54260f8a436dd9f3a0db8d5d42b4418.tar.gz
Update SPARQL queries to fetch from graph with a default value.
This makes testing easier since tests will be run against a different graph. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3')
-rw-r--r--gn3/db/rdf/wiki.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py
index 7d0b3f3..feda5bd 100644
--- a/gn3/db/rdf/wiki.py
+++ b/gn3/db/rdf/wiki.py
@@ -50,7 +50,9 @@ def __sanitize_result(result: dict) -> dict:
return result
-def get_wiki_entries_by_symbol(symbol: str, sparql_uri: str) -> dict:
+def get_wiki_entries_by_symbol(
+ symbol: str, sparql_uri: str, graph: str = "<http://genenetwork.org>"
+) -> dict:
"""Fetch all the Wiki entries using the symbol"""
# This query uses a sub-query to fetch the latest comment by the
# version id.
@@ -71,7 +73,7 @@ CONSTRUCT {
gnt:hasVersion ?max ;
dct:created ?created ;
dct:identifier ?id_ .
-} WHERE {
+} FROM $graph WHERE {
?symbolId rdfs:label ?symbolName .
?comment rdfs:label ?text_ ;
gnt:symbol ?symbolId ;
@@ -110,6 +112,7 @@ CONSTRUCT {
"""
).substitute(
prefix=RDF_PREFIXES,
+ graph=graph,
symbol=symbol,
)
results = query_frame_and_compact(query, WIKI_CONTEXT, sparql_uri)
@@ -121,7 +124,9 @@ CONSTRUCT {
return results
-def get_comment_history(comment_id: int, sparql_uri: str) -> dict:
+def get_comment_history(
+ comment_id: int, sparql_uri: str, graph: str = "<http://genenetwork.org>"
+) -> dict:
"""Get all the historical data for a given id"""
query = Template(
"""
@@ -139,7 +144,7 @@ CONSTRUCT {
gnt:belongsToCategory ?category ;
gnt:hasVersion ?version ;
dct:created ?created .
-} WHERE {
+} FROM $graph WHERE {
?symbolId rdfs:label ?symbolName .
?comment rdf:type gnc:GNWikiEntry ;
rdfs:label ?text_ ;
@@ -169,7 +174,7 @@ CONSTRUCT {
BIND (COALESCE(?category_, "") AS ?category) .
}
"""
- ).substitute(prefix=RDF_PREFIXES, comment_id=comment_id)
+ ).substitute(prefix=RDF_PREFIXES, graph=graph, comment_id=comment_id)
results = query_frame_and_compact(query, WIKI_CONTEXT, sparql_uri)
data = [__sanitize_result(result) for result in results.get("data", {})]
# See note above in the doc-string