From 5111b97fc058915f6dc38061fb4d2011d731657f Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Mon, 2 Sep 2024 19:17:47 +0300 Subject: Enforce array type to "categories" and "pmids" fields. Signed-off-by: Munyoki Kilyungi --- gn3/db/rdf/wiki.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'gn3/db') diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py index a208b74..d8fd8c8 100644 --- a/gn3/db/rdf/wiki.py +++ b/gn3/db/rdf/wiki.py @@ -143,4 +143,19 @@ CONSTRUCT { query, WIKI_CONTEXT, sparql_uri ) + data = results.get("data") + for result in data: + categories = result.get("categories") + if categories and isinstance(categories, str): + result["categories"] = [categories] + else: + result["categories"] = [] + pmids = result.get("pubmed_ids") + if pmids and isinstance(pmids, str): + result["pubmed_ids"] = [pmids] + elif pmids: + result["pubmed_ids"] = [int(pmid) for pmid in pmids] + else: + result["pubmed_ids"] = [] + result["version"] = int(result["version"]) return results -- cgit v1.2.3