about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMunyoki Kilyungi <me@bonfacemunyoki.com>2026-01-13 15:29:01 +0300
committerBonfaceKilz <me@bonfacemunyoki.com>2026-01-13 16:45:27 +0300
commit7b7ebc32aa3bed12a7cac154d2df0937d4eb76fe (patch)
tree1f2de0a8674ee0a59b2c0000fe8568b744907772
parenta235fa0e5f81b7aa8bf26488a4288016a5d6c7a6 (diff)
downloadgenenetwork3-7b7ebc32aa3bed12a7cac154d2df0937d4eb76fe.tar.gz
Minor API cleanup around JSON-LD framing and compation.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn3/api/metadata.py3
-rw-r--r--gn3/db/rdf/__init__.py18
2 files changed, 16 insertions, 5 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index e272c0d..012c9f3 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -88,7 +88,8 @@ CONSTRUCT {
     }
     __result = query_frame_and_compact(
         _query, _context,
-        current_app.config.get("SPARQL_ENDPOINT")
+        current_app.config.get("SPARQL_ENDPOINT"),
+        options = {"graph": False}
     )
     return __result | retrieve_metadata(
         (Path(
diff --git a/gn3/db/rdf/__init__.py b/gn3/db/rdf/__init__.py
index f0ac494..d60d81a 100644
--- a/gn3/db/rdf/__init__.py
+++ b/gn3/db/rdf/__init__.py
@@ -50,6 +50,7 @@ BASE_CONTEXT = {
 }
 
 DATASET_CONTEXT = {
+    "id": "@id",
     "accessRights": "dct:accessRights",
     "accessionId": "dct:identifier",
     "acknowledgement": "gnt:hasAcknowledgement",
@@ -177,18 +178,27 @@ def sparql_query(query: str, endpoint: str, format_type="json-ld") -> dict:
     return sparql.queryAndConvert()["results"]["bindings"]  # type: ignore
 
 
-def query_frame_and_compact(query: str, context: dict, endpoint: str) -> dict:
+def query_frame_and_compact(
+        query: str, context: dict,
+        endpoint: str, options: dict | None = None
+) -> dict:
     """Frame and then compact the results given a context"""
+    if options is None:
+        options = {"graph": True}
     results = sparql_query(query, endpoint)
     return jsonld.compact(
-        jsonld.frame(results, context), context, options={"graph": True}
+        jsonld.frame(results, context), context, options=options
     )
 
 
-def query_and_compact(query: str, context: dict, endpoint: str) -> dict:
+def query_and_compact(
+        query: str, context: dict, endpoint: str, options: dict | None = None
+) -> dict:
     """Compact the results given a context"""
+    if options is None:
+        options = {"graph": True}
     results = sparql_query(query, endpoint)
-    return jsonld.compact(results, context, options={"graph": True})
+    return jsonld.compact(results, context, options=options)
 
 
 def query_and_frame(query: str, context: dict, endpoint: str) -> dict: