aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-08-30 07:52:08 +0300
committerBonfaceKilz2024-09-05 16:39:14 +0300
commit74337eb0c3df90215e029989ac01679f75dbd58a (patch)
tree7b8889605df9d2fdce513e489345123f927be0da /gn3/db
parentbdfd19d87e853fbcd2e590ec4346e5057c638cff (diff)
downloadgenenetwork3-74337eb0c3df90215e029989ac01679f75dbd58a.tar.gz
Add comment history.
* gn3/api/metadata_api/wiki.py: Import get_comment_history. (get_history): New end-point. * gn3/db/rdf/wiki.py: (get_comment_history): New function. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/rdf/wiki.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py
index b131ee7..b2235b9 100644
--- a/gn3/db/rdf/wiki.py
+++ b/gn3/db/rdf/wiki.py
@@ -91,3 +91,52 @@ CONSTRUCT {
if not data:
return results
return results
+
+
+def get_comment_history(comment_id: int, sparql_uri: str) -> dict:
+ """Get all the historical data for a given id"""
+ query = Template("""
+$prefix
+
+CONSTRUCT {
+ ?uid rdfs:label ?symbolName ;
+ gnt:reason ?reason ;
+ gnt:species ?species ;
+ dct:references ?pmid ;
+ foaf:homepage ?weburl ;
+ rdfs:comment ?comment ;
+ foaf:mbox ?email ;
+ gnt:initial ?usercode ;
+ gnt:belongsToCategory ?category ;
+ gnt:hasVersion ?versionId ;
+ rdf:type gnc:GNWikiEntry ;
+ dct:created ?created .
+} WHERE {
+ ?symbolId rdfs:label ?symbolName .
+ ?uid rdf:type gnc:GNWikiEntry ;
+ rdfs:comment ?comment ;
+ gnt:symbol ?symbolId ;
+ dct:created ?createTime ;
+ dct:hasVersion ?version ;
+ dct:identifier $comment_id ;
+ dct:identifier ?id_ .
+ OPTIONAL { ?uid gnt:reason ?reason } .
+ OPTIONAL {
+ ?uid gnt:belongsToSpecies ?speciesId .
+ ?speciesId gnt:shortName ?species .
+ } .
+ OPTIONAL { ?uid dct:references ?pubmedId . } .
+ OPTIONAL { ?uid foaf:homepage ?weburl . } .
+ OPTIONAL { ?uid gnt:initial ?usercode . } .
+ OPTIONAL { ?uid foaf:mbox ?email . } .
+ OPTIONAL { ?uid gnt:belongsToCategory ?category . } .
+ BIND (str(?version) AS ?versionId) .
+ BIND (str(?pubmedId) AS ?pmid) .
+ BIND (str(?createTime) AS ?created) .
+} ORDER BY DESC(?version) DESC(?createTime)
+""").substitute(prefix=RDF_PREFIXES, comment_id=comment_id)
+ results = query_frame_and_compact(
+ query, WIKI_CONTEXT,
+ sparql_uri
+ )
+ return results