aboutsummaryrefslogtreecommitdiff
path: root/gn3/db/rdf
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-09-17 19:54:03 +0300
committerJohn Nduli Kilyungi2024-09-18 08:32:34 +0300
commit7e6cd434ceebc10d0c61d8d93a351a512ed74108 (patch)
treecc3b3d0913ea34ddcc9a9b9b1ec23bc7a16bcfc7 /gn3/db/rdf
parent32be08bebb6d43c6e446dec12526cd912727c6fb (diff)
downloadgenenetwork3-7e6cd434ceebc10d0c61d8d93a351a512ed74108.tar.gz
Pass in insert_dict instead of payload in "get_wiki_entries".
* gn3/api/metadata_api/wiki.py (edit_wiki) [insert_dict]: Add species, categories fields. [update_wiki_comment]: Pass in insert_dict, and get rid of redundant keys. Directly pass in sparql_auth's conf params instead of a dict. * gn3/db/rdf/wiki.py (get_next_comment_version): Get rid of redundant params. Use fields directly from insert_dict. Directly pass in sparql_auth's conf params instead of a dict. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db/rdf')
-rw-r--r--gn3/db/rdf/wiki.py52
1 files changed, 25 insertions, 27 deletions
diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py
index f19670a..f2030ca 100644
--- a/gn3/db/rdf/wiki.py
+++ b/gn3/db/rdf/wiki.py
@@ -186,11 +186,10 @@ CONSTRUCT {
def update_wiki_comment(
- comment_id: int,
- payload: dict,
- created: str,
- next_version: int,
- sparql_conf: dict,
+ insert_dict: dict,
+ sparql_user: str,
+ sparql_password: str,
+ sparql_auth_uri: str,
graph: str = "<http://genenetwork.org>",
) -> tuple[str, int]:
"""Update a wiki comment by inserting a comment with the same
@@ -220,7 +219,7 @@ looks like:
}
}
"""
- name = f"gn:wiki-{comment_id}-{next_version}"
+ name = f"gn:wiki-{insert_dict['Id']}-{insert_dict['versionId']}"
comment_triple = Template("""$name rdf:label '''$comment'''@en ;
rdf:type gnc:GNWikiEntry ;
gnt:symbol "$symbol" ;
@@ -228,31 +227,31 @@ dct:identifier "$comment_id"^^xsd:integer ;
dct:hasVersion "$next_version"^^xsd:integer ;
dct:created "$created"^^xsd:datetime .
""").substitute(
- comment=payload["comment"],
- name=name, symbol=payload['symbol'],
- comment_id=comment_id, next_version=next_version,
- created=created)
+ comment=insert_dict["comment"],
+ name=name, symbol=insert_dict['symbol'],
+ comment_id=insert_dict["Id"], next_version=insert_dict["versionId"],
+ created=insert_dict["createtime"])
using = ""
- if payload["email"]:
- comment_triple += f"{name} foaf:mbox <{payload['email']}> .\n"
- if payload["initial"]:
- comment_triple += f"{name} gnt:initial \"{payload['initial']}\" .\n"
- if payload["species"]:
+ if insert_dict["email"]:
+ comment_triple += f"{name} foaf:mbox <{insert_dict['email']}> .\n"
+ if insert_dict["initial"]:
+ comment_triple += f"{name} gnt:initial \"{insert_dict['initial']}\" .\n"
+ if insert_dict["species"]:
comment_triple += f"{name} gnt:belongsToSpecies ?speciesId .\n"
using = Template(
""" USING $graph WHERE { ?speciesId gnt:shortName "$species" . } """).substitute(
- graph=graph, species=payload["species"]
+ graph=graph, species=insert_dict["species"]
)
- if payload["reason"]:
- comment_triple += f"{name} gnt:reason \"{payload['reason']}\" .\n"
- if payload["web_url"]:
- comment_triple += f"{name} foaf:homepage <{payload['web_url']}> .\n"
- for pmid in payload["pubmed_ids"]:
+ if insert_dict["reason"]:
+ comment_triple += f"{name} gnt:reason \"{insert_dict['reason']}\" .\n"
+ if insert_dict["weburl"]:
+ comment_triple += f"{name} foaf:homepage <{insert_dict['weburl']}> .\n"
+ for pmid in insert_dict["PubMed_ID"].split():
comment_triple += f"{name} dct:references pubmed:{pmid} .\n"
- for category in payload["categories"]:
+ for category in insert_dict["categories"]:
comment_triple += f'{name} gnt:belongsToCategory "{category}".\n'
- res = update_rdf(
+ return update_rdf(
query=Template(
"""
$prefix
@@ -265,8 +264,7 @@ $comment_triple}
graph=graph,
comment_triple=comment_triple,
using=using),
- sparql_user=sparql_conf["sparql_user"],
- sparql_password=sparql_conf["sparql_password"],
- sparql_auth_uri=sparql_conf["sparql_auth_uri"],
+ sparql_user=sparql_user,
+ sparql_password=sparql_password,
+ sparql_auth_uri=sparql_auth_uri,
)
- return (res, 200)