Strabon

view scripts/endpoint @ 1459:0825ee10ae10

changed the tests of the temporal relation functions in order to be compliant with the
way the spatial tests are organized by grouping the functions.
Also, since the bug with the time zones has not been solved, I removed the time zone
information from the test dataset. Finally, I added the results for some of the queries
which had empty results in the .srx file.
author Stella Giannakopoulou <sgian@di.uoa.gr>
date Thu Jan 22 13:24:43 2015 +0200 (2015-01-22)
parents 8b8c2efcc293 866bf84309ae
children
line source
1 #!/bin/bash
3 #
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 #
8 # Copyright (C) 2010, 2011, 2012, Pyravlos Team
9 #
10 # http://www.strabon.di.uoa.gr/
11 #
13 #
14 # Script for executing SPARQL queries and SPARQL Update queries
15 # as well as storing RDF triples on a Strabon Endpoint.
16 #
17 # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
18 # Author: Panayiotis Smeros <psmeros@di.uoa.gr>
19 #
21 # absolute directory name of this command
22 LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24 # this command
25 CMD="$(basename ${0})"
27 # Filename containing the prefixes to be included in SPARQL queries
28 PREFIXES_FILE="${LOC}/prefixes.sparql"
30 function help() {
31 echo "Usage: ${CMD} [OPTIONS] COMMAND ENDPOINT ARGS"
32 echo
33 echo "Execute SPARQL and SPARQL Update queries as well as store RDF triples on a Strabon endpoint."
34 echo
35 echo " COMMAND : one of query, queryfile, update, store, describe, or help"
36 echo " ENDPOINT : the URL of the Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint)"
37 echo " ARGS : arguments according to selected command"
38 echo
39 echo "OPTIONS can be any of the following"
40 echo " -d : don't run, just print what shall be executed"
41 echo " -i : include URI prefixes in the SPARQL query. Prefixes are taken from file"
42 echo " \`prefixes.sparql'"
43 }
45 function help_query() {
46 echo "Usage: ${CMD} query ENDPOINT SPARQL_QUERY [RESULT_FORMAT]"
47 echo
48 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
49 echo " SPARQL_QUERY : the SPARQL query to execute or the alias name corresponding to a"
50 echo " predefined query such as:"
51 echo " \`size': SELECT (count(*) as ?c) WHERE {?s ?p ?o}"
52 echo " RESULT_FORMAT : the format of the result. Possible values are \`XML' (default), \`KML', \`KMZ', \`GeoJSON', \`HTML', or \`TSV'"
53 }
55 function help_queryfile() {
56 echo "Usage: ${CMD} queryfile ENDPOINT SPARQL_QUERY_FILE [RESULT_FORMAT]"
57 echo
58 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
59 echo " SPARQL_QUERY_FILE : the file that contain the SPARQL query to execute"
60 echo " RESULT_FORMAT : the format of the result. Possible values are \`KMLMAP\, \`GEOJSON', "
61 echo " \`HTML', \`KMZMAP', \`XML' (default), or \`KML'."
62 }
64 function help_update() {
65 echo "Usage: ${CMD} update ENDPOINT SPARQL_QUERY"
66 echo
67 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
68 echo " SPARQL_QUERY : the SPARQL update query to execute or the alias name corresponding to a"
69 echo " predefined query such as:"
70 echo " \`clear': DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
71 }
73 function help_store() {
74 echo "Usage: ${CMD} store ENDPOINT FORMAT [-g NAMED_GRAPH] [--inference] -t TRIPLES|-u TRIPLES_URL"
75 echo
76 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
77 echo " FORMAT : the RDF format of the input (one of RDF/XML, N-Triples, Turtle, N3, TriX, TriG, BinaryRDF or N-Quads)"
78 echo " TRIPLES : the RDF triples to store"
79 echo " TRIPLES_URL : the URL containing the RDF triples to store"
80 echo " NAMED_GRAPH : the URI of the named graph into which the RDF files shall be stored"
81 echo " (defaults to the default graph)."
82 echo " --inference : enables inference."
83 }
85 function help_describe() {
86 echo "Usage: ${CMD} describe ENDPOINT DESCRIBE_QUERY [RESULT_FORMAT]"
87 echo
88 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
89 echo " DESCRIBE_QUERY : the SPARQL DESCRIBE query to execute"
90 echo " RESULT_FORMAT : the format of the result. Possible values are \`N-Triples' (default)"
91 echo " \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
92 }
94 CURL_OPTS="-w HTTP_CODE='%{http_code}\n' -H \"Content-Type:application/x-www-form-urlencoded\" -H \"Accept:text/xml\""
96 # if set to 1, then only the command to be executed is printed
97 DEBUG=0
98 # set default limit
99 MAXLIMIT=0
100 while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
101 case "${1}" in
102 -d)
103 shift
104 DEBUG=1
105 ;;
106 -i)
107 shift
108 PREFIXES="$(cat ${PREFIXES_FILE})"
109 ;;
110 -l)
111 MAXLIMIT="${2}"
112 shift
113 shift
114 ;;
115 esac
116 done
118 case "${1}" in
119 help)
120 shift
121 if test $# -eq 1; then
122 case "${1}" in
123 query)
124 help_query
125 ;;
126 queryfile)
127 help_queryfile
128 ;;
129 update)
130 help_update
131 ;;
132 store)
133 help_store
134 ;;
135 describe)
136 help_describe
137 ;;
138 *)
139 help
140 ;;
141 esac
142 exit 1
143 fi
144 help
145 exit 0
146 ;;
147 query)
148 shift
149 if ! test $# -ge 2; then
150 help_query
151 exit 1
152 fi
153 URL="${1}/Query"
154 QUERY="${2}"
156 shift
157 shift
158 # predefined queries
159 case "${QUERY}" in
160 size)
161 QUERY="SELECT (count(*) as ?c) WHERE {?s ?p ?o}"
162 ;;
163 esac
165 # set default format
166 FORMAT="XML"
167 if test $# -eq 1; then
168 FORMAT="${1}"
169 fi
171 case "${FORMAT}" in
172 [Xx][Mm][Ll])
173 MIME_TYPE="application/sparql-results+xml"
174 ;;
175 [Tt][sS][vV])
176 MIME_TYPE="text/tab-separated-values"
177 ;;
178 [Kk][Mm][Ll])
179 MIME_TYPE="application/vnd.google-earth.kml+xml"
180 ;;
181 [Kk][mM][Zz])
182 MIME_TYPE="application/vnd.google-earth.kmz"
183 ;;
184 [Hh][Tt][Mm][Ll])
185 MIME_TYPE="text/html"
186 ;;
187 [Gg][Ee][Oo][Jj][Ss][Oo][Nn])
188 MIME_TYPE="application/json"
189 ;;
190 *)
191 echo "${CMD}: unknown format \"${FORMAT}\"."
192 echo "${CMD}: possible values are \`KML', \`KMZ', \`GeoJSON', \`XML' (default), \`HTML', or \`TSV'"
193 exit 2
194 ;;
195 esac
197 EXEC="curl -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode query='${PREFIXES}${QUERY}' --data maxLimit='${MAXLIMIT}' ${URL}"
198 ;;
199 queryfile)
200 shift
201 if ! test $# -ge 2; then
202 help_queryfile
203 exit 1
204 fi
206 if ! test -f ${2}; then
207 echo "${CMD}: File not found."
208 exit 2
209 fi
211 URL="${1}/Query"
212 QUERY=`cat ${2} | sed 's/\"/\\\"/g'`
214 shift
215 shift
217 # set default format
218 FORMAT="XML"
219 if test $# -eq 1; then
220 FORMAT="${1}"
221 fi
223 case "${FORMAT}" in
224 [Xx][Mm][Ll])
225 MIME_TYPE="application/sparql-results+xml"
226 ;;
227 [Tt][sS][vV])
228 MIME_TYPE="text/tab-separated-values"
229 ;;
230 [Kk][Mm][Ll])
231 MIME_TYPE="application/vnd.google-earth.kml+xml"
232 ;;
233 [Kk][mM][Zz])
234 MIME_TYPE="application/vnd.google-earth.kmz"
235 ;;
236 [Hh][Tt][Mm][Ll])
237 MIME_TYPE="text/html"
238 ;;
239 [Gg][Ee][Oo][Jj][Ss][Oo][Nn])
240 MIME_TYPE="application/json"
241 ;;
242 *)
243 echo "${CMD}: unknown format \"${FORMAT}\"."
244 echo "${CMD}: possible values are \`KML', \`KMZ', \`GeoJSON', \`XML' (default), \`HTML', or \`TSV'"
245 exit 2
246 ;;
247 esac
249 EXEC="curl -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode query='${PREFIXES}${QUERY}' ${URL}"
250 ;;
252 update)
253 shift
254 if ! test $# -eq 2; then
255 help_update
256 exit 1
257 fi
258 URL="${1}/Update"
259 QUERY="${2}"
261 # predefined queries
262 case "${QUERY}" in
263 clear)
264 QUERY="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
265 ;;
266 esac
268 EXEC="curl -u endpoint:3ndpo1nt ${CURL_OPTS} --data-urlencode query='${PREFIXES}${QUERY}' ${URL}"
269 ;;
270 store)
271 shift
272 if ! test $# -ge 4; then
273 help_store
274 exit 1
275 fi
276 URL="${1}/Store"
277 shift
278 FORMAT="${1}"
279 shift
280 MIME_TYPE=
281 case "${FORMAT}" in
282 N-Triples)
283 MIME_TYPE="text/plain"
284 ;;
285 RDF/XML)
286 MIME_TYPE="application/rdf+xml"
287 ;;
288 N3)
289 MIME_TYPE="text/rdf+n3"
290 ;;
291 TURTLE)
292 MIME_TYPE="text/turtle"
293 ;;
294 TRIG)
295 MIME_TYPE="application/x-trig"
296 ;;
297 TRIX)
298 MIME_TYPE="application/trix"
299 ;;
300 BinaryRDF)
301 MIME_TYPE="application/x-binary-rdf"
302 ;;
303 N-Quads)
304 MIME_TYPE="text/x-nquads"
305 ;;
306 *)
307 echo "${CMD}: unknown format \"${FORMAT}\"."
308 echo "${CMD}: possible values are \`N-Triples' (default), \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', \`BinaryRDF' and \`N-Quads'"
309 exit 2
310 ;;
311 esac
313 GRAPH=
314 case "${1}" in
315 -g)
316 shift
317 if [ "${1}" == "--inference" ]; then
318 help_store
319 exit 1
320 fi
321 if ! test $# -ge 3; then
322 help_store
323 exit 1
324 fi
325 GRAPH="-d graph=${1}"
326 shift
327 esac
329 INFERENCE=
330 case "${1}" in
331 --inference)
332 shift
333 if ! test $# -ge 2; then
334 help_store
335 exit 1
336 fi
337 INFERENCE="-d inference=true"
338 esac
340 case "${1}" in
341 -t)
342 shift
343 if ! test $# -eq 1; then
344 help_store
345 exit 1
346 fi
347 TRIPLES="${1}"
348 EXEC="curl -u endpoint:3ndpo1nt -w '\nHTTP_CODE=%{http_code}\n' -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode data='${TRIPLES}' ${GRAPH} ${INFERENCE} ${URL}"
349 ;;
350 -u)
351 shift
352 if ! test $# -eq 1; then
353 help_store
354 exit 1
355 fi
356 URL_TRIPLES="${1}"
357 EXEC="curl -u endpoint:3ndpo1nt -w '\nHTTP_CODE=%{http_code}\n' -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode url='${URL_TRIPLES}' -d fromurl='' ${GRAPH} ${INFERENCE} ${URL}"
358 ;;
359 *)
360 help_store
361 exit 1
362 ;;
363 esac
364 ;;
365 describe)
366 shift
367 if ! test $# -ge 2; then
368 help_describe
369 exit 1
370 fi
371 URL="${1}/Describe"
372 QUERY="${2}"
374 shift
375 shift
377 # set default format
378 FORMAT="N-Triples"
379 if test $# -eq 1; then
380 FORMAT="${1}"
381 fi
383 MIME_TYPE=
384 case "${FORMAT}" in
385 N-Triples)
386 MIME_TYPE="text/plain"
387 ;;
388 RDF/XML)
389 MIME_TYPE="application/rdf+xml"
390 ;;
391 N3)
392 MIME_TYPE="text/rdf+n3"
393 ;;
394 TURTLE)
395 MIME_TYPE="text/turtle"
396 ;;
397 TRIG)
398 MIME_TYPE="application/x-trig"
399 ;;
400 TRIX)
401 MIME_TYPE="application/trix"
402 ;;
403 BinaryRDF)
404 MIME_TYPE="application/x-binary-rdf"
405 ;;
406 *)
407 echo "${CMD}: unknown format \"${FORMAT}\"."
408 echo "${CMD}: possible values are \`N-Triples' (default), \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
409 exit 2
410 ;;
411 esac
413 EXEC="curl -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode query='${PREFIXES}${QUERY}' ${URL}"
414 ;;
415 *)
416 help
417 echo
418 echo "${CMD}: unknown command \"${1}\"."
419 exit 1
420 ;;
421 esac
423 # execute or debug
424 if test $DEBUG -eq 1; then
425 echo "${CMD}: Debug is ON"
426 echo "${CMD}: Printing command for execution"
427 echo " $EXEC"
428 else
429 eval "${EXEC}"
430 fi