diff options
| author | Munyoki Kilyungi <me@bonfacemunyoki.com> | 2026-01-13 15:29:01 +0300 |
|---|---|---|
| committer | BonfaceKilz <me@bonfacemunyoki.com> | 2026-01-13 16:45:27 +0300 |
| commit | 7b7ebc32aa3bed12a7cac154d2df0937d4eb76fe (patch) | |
| tree | 1f2de0a8674ee0a59b2c0000fe8568b744907772 | |
| parent | a235fa0e5f81b7aa8bf26488a4288016a5d6c7a6 (diff) | |
| download | genenetwork3-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.py | 3 | ||||
| -rw-r--r-- | gn3/db/rdf/__init__.py | 18 |
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: |
