diff options
author | Munyoki Kilyungi | 2023-10-25 12:07:52 +0300 |
---|---|---|
committer | BonfaceKilz | 2023-10-27 13:45:32 +0300 |
commit | f56b525fb4b9fab72b5d39030e0e3c5abb321e56 (patch) | |
tree | c4248cab48e86f1e025cc7b019573b45c22b0cca /gn3 | |
parent | 4e226cea9651767c797e5ea055f7a7993b16b9f4 (diff) | |
download | genenetwork3-f56b525fb4b9fab72b5d39030e0e3c5abb321e56.tar.gz |
Implement "GET /metadata/group".
* gn3/api/metadata.py (groups): New end-point.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/api/metadata.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py index a374f03..193357a 100644 --- a/gn3/api/metadata.py +++ b/gn3/api/metadata.py @@ -1373,3 +1373,50 @@ CONSTRUCT { except (RemoteDisconnected, URLError): return jsonify({}) + +@metadata.route("/groups", methods=["GET"]) +def groups(): + """Fetch the list of groups""" + try: + sparql = SPARQLWrapper(current_app.config.get("SPARQL_ENDPOINT")) + sparql.setQuery(Template(""" +$prefix + +CONSTRUCT { + ?group ?predicate ?object . +} WHERE { + ?group ^skos:member gnc:Set ; + ?predicate ?object . + VALUES ?predicate { + rdfs:label skos:prefLabel + gnt:geneticType gnt:mappingMethod + gnt:code gnt:family + } + +} +""").substitute(prefix=RDF_PREFIXES)) + results = sparql.queryAndConvert() + results = json.loads( + results.serialize(format="json-ld") + ) + return jsonld.compact(results, { + "@context": { + "data": "@graph", + "type": "@type", + "id": "@id", + "skos": "http://www.w3.org/2004/02/skos/core#", + "gnt": "http://genenetwork.org/term/", + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "name": "rdfs:label", + "family": "gnt:family", + "shortName": "gnt:shortName", + "code": "gnt:code", + "mappingMethod": "gnt:mappingMethod", + "geneticType": "gnt:geneticType", + "fullName": "skos:prefLabel", + }, + }) + except (RemoteDisconnected, URLError): + return jsonify({}) + + |