aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPjotr Prins2023-07-25 14:11:09 +0200
committerPjotr Prins2023-07-25 14:11:09 +0200
commit161969e8dd9f87e309f9a6720726b6b88833b20f (patch)
tree48d0072fb7e8f411434538d73d66a360b1a703ff
parentaf062b396a820066d6f63a960b21da052fd0ea65 (diff)
downloadgenenetwork3-161969e8dd9f87e309f9a6720726b6b88833b20f.tar.gz
wd-qurey
-rwxr-xr-xgn3-guile/web/webserver.scm39
1 files changed, 38 insertions, 1 deletions
diff --git a/gn3-guile/web/webserver.scm b/gn3-guile/web/webserver.scm
index 28efb3b..ef15091 100755
--- a/gn3-guile/web/webserver.scm
+++ b/gn3-guile/web/webserver.scm
@@ -31,7 +31,10 @@
"https://genenetwork.org")
(define (gn-sparql-endpoint-url)
- (string-append "https://sparql.genenetwork.org/sparql"))
+ "https://sparql.genenetwork.org/sparql")
+
+(define (wd-sparql-endpoint-url)
+ "https://query.wikidata.org/sparql")
(define (prefix)
"Build the API URL including version"
@@ -72,6 +75,13 @@
response-body) "UTF-8"))
+(define (sparql-exec2 endpoint-url query)
+ "Execute raw SPARQL query returning response as a UTF8 string"
+ (bytevector->string (receive (response-status response-body)
+ (http-request (string-append endpoint-url "?query=" (uri-encode query) ""))
+
+ response-body) "UTF-8"))
+
(define (unpack field response)
"Helper to get nested JSON field from SPARQL response"
(cdr (assoc field response)))
@@ -108,8 +118,35 @@ l
;; (("http://genenetwork.org/menuName" "Drosophila") ("http://genenetwork.org/name" "Drosophila") ("http://genenetwork.org/binomialName" "Drosophila melanogaster"))
(scm->json (map (lambda (i) (cons (car i) (car (cdr i)))) l))
;; {"http://genenetwork.org/menuName":"Drosophila","http://genenetwork.org/name":"Drosophila","http://genenetwork.org/binomialName":"Drosophila melanogaster"}
+
+
+curl -G https://query.wikidata.org/sparql -H "Accept: application/json; charset=utf-8" --data-urlencode query="SELECT DISTINCT * where {
+ wd:Q158695 wdt:P225 ?o .
+} limit 5"
+{
+ "head" : {
+ "vars" : [ "o" ]
+ },
+ "results" : {
+ "bindings" : [ {
+ "o" : {
+ "type" : "literal",
+ "value" : "Arabidopsis thaliana"
+ }
+ } ]
+ }
+}
!#
+(define (sparql-wd-species-info species)
+ (sparql-exec2 (wd-sparql-endpoint-url) "
+SELECT DISTINCT * where {
+ wd:Q158695 wdt:P225 ?o .
+} limit 100
+
+"
+ ))
+
(define (sparql-species)
(sparql-scm (gn-sparql-endpoint-url) "
PREFIX gn: <http://genenetwork.org/>