summaryrefslogtreecommitdiff
path: root/example-sparql.scm
diff options
context:
space:
mode:
authorswedebugia <swedebugia@riseup.net>2018-12-10 22:59:09 +0100
committerswedebugia <swedebugia@riseup.net>2018-12-11 00:00:09 +0100
commit39e63b9b047fd8863ddaaeb627d9e93f2b3d34d2 (patch)
tree30d964370a7880aa1c1e403bdbfe22ecd1576e11 /example-sparql.scm
parentpre-release 0.1: (diff)
downloadguile-wikidata-39e63b9b047fd8863ddaaeb627d9e93f2b3d34d2.tar.gz
wikidata: Add rudimentary SPARQL support, split library in two parts,readme
update README, improve examples. 2 bugs exist: 1) the low-level api proc. does not honor language. 2) SPARQL LIMIT is not honored by the server.
Diffstat (limited to 'example-sparql.scm')
-rw-r--r--example-sparql.scm48
1 files changed, 48 insertions, 0 deletions
diff --git a/example-sparql.scm b/example-sparql.scm
new file mode 100644
index 0000000..4bfd75a
--- /dev/null
+++ b/example-sparql.scm
@@ -0,0 +1,48 @@
+;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
+;;; Copyright © 2018 swedebugia <swedebugia@riseup.net>
+;;;
+;;; This file is part of guile-wikidata.
+;;;
+;;; guile-wikidata is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; guile-wikidata is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with guile-wikidata. If not, see <http://www.gnu.org/licenses/>.
+
+;; The following step is not needed with Guix:
+;; We must add the (wikidata sparql) module to GNU Guile's load path
+;; before we can load it. This means we have to add the directory
+;; that leads to the sparql/ directory to the %load-path variable.
+; (add-to-load-path "/path/to/the/root/of/the/repository")
+
+;; We need the following modules to show the query.
+(use-modules (ice-9 format)
+ (wikidata sparql))
+
+;; Example query passed to the screen for you to eyeball
+(show-sparql
+ ;; FIXME why is LIMIT not honored?
+ (format #f "
+PREFIX wd: <http://www.wikidata.org/entity/>
+PREFIX wdt: <http://www.wikidata.org/prop/direct/>
+SELECT DISTINCT ?item
+WHERE \\{?item wdt:P31/wdt:P279* wd:Q19723451\\}
+LIMIT 10
+"))
+
+;; See more example queries at
+;; https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples
+
+;;; To generate SPARQL queries I recommend
+;;; https://query.wikidata.org/. It is excellent because it looks up
+;;; all the P- and Q-ids for you and generate the SPARQL for you to
+;;; insert above. :D
+
+