Strabon

view scripts/strabon @ 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 a1e2561b7c2c 49d07fd6367e
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 running the main classes of Strabon. The main classes of Strabon comprises
15 # QueryOp, , UpdateOp, StoreOp, and DescribeOp.
16 #
17 # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
18 #
20 # command name
21 CMD="$(basename ${0})"
23 # absolute directory name of this command
24 LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26 RUNTIME="${LOC}/../runtime"
28 # runtime package
29 PKG="eu.earthobservatory.runtime"
31 # the underlying database to use (one of `postgis' or `monetdb')
32 DATABASE="postgis"
34 # the main class to run
35 CLASS=
37 # the hostname at which the database runs
38 HOST="localhost"
40 # the port at which the database listens
41 PORT=
43 # the database name to connect to
44 DB="strabon"
46 # the username for the database connection
47 DBUSER=
49 # the password for the database connection
50 DBPASS=
52 # the query to run
53 QUERY=
55 # the RDF format of the files to store (defaults to ntriples)
56 FORMAT="ntriples"
58 # true to force deletion of locked table, false otherwise
59 FORCE_DELETE="false"
61 # the URI of the named graph into which the RDF files shall be stored
62 NAMED_GRAPH=
64 # true when inference is enabled
65 INFERENCE=
67 # predefined queries
68 QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}"
69 QUERY_GETALL="SELECT * WHERE {?s ?p ?o}"
70 QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
71 QUERY_HOTSPOT_SIZE="SELECT (COUNT(*) as ?C) WHERE {?h <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://teleios.di.uoa.gr/ontologies/noaOntology.owl#Hotspot>}"
72 QUERY_EXPORT="CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}"
74 # debug option for log4j configuration:
75 #-Dlog4j.debug
76 #-Dlog4j.configuration=\"${RUNTIME}/log4j.properties\"
78 # further options for java
79 JAVA_OPTS=
81 # base max memory memory
82 BASE_MEMORY=1024
84 # more memory
85 MORE_MEMORY="-Xms512M -Xmx1024M"
87 # much more memory
88 MMORE_MEMORY="-Xms8192M -Xmx16384M"
90 # flag for not setting the memory limit more than once
91 MEMORY_INCREASED=false
93 # just print what shall be executed
94 DEBUG=false
96 # if true, DEBUG has been set in command line,
97 # so it must not be overidden
98 DEBUG_SAVE=false
100 # Filename containing the prefixes to be included in SPARQL queries
101 PREFIXES_FILE="${LOC}/prefixes.sparql"
103 # configuration file for the Strabon connection
104 STRABON_CONF="${HOME}/.strabon"
106 function help() {
107 echo "Usage: ${CMD} [OPTIONS] COMMAND ARGS"
108 echo
109 echo "Interface to execute the main classes of Strabon, such as QueryOp, StoreOp, UpdateOp, DescribeOp, etc."
110 echo
111 echo " COMMAND : one of \`query', \`update', \`store', \`describe', or \`help'"
112 echo " ARGS : arguments according to selected command"
113 echo
114 echo "OPTIONS can be any of the following (variable names and values are case sensitive)"
115 echo " -d : don't run, just print what shall be executed"
116 echo " Variable for configuration file: \`DEBUG'"
117 echo " Values: \`true' or \`false'"
118 echo " -m : use more memory \`${MORE_MEMORY}' (useful in \"out of memory exceptions\")"
119 echo " -M : use much more memory \`${MMORE_MEMORY}' (useful in \"out of memory exceptions\")"
120 echo " -MM MULT : use MULT * ${BASE_MEMORY} MB of memory (useful in \"out of memory exceptions\")"
121 echo " -i : include URI prefixes in the SPARQL query. Prefixes are taken from file"
122 echo " \`prefixes.sparql'"
123 echo " -e DATABASE : the database engine to connect (one of \`postgis' (default) or \`monetdb')"
124 echo " Variable for configuration file: \`DATABASE'"
125 echo " Values: \`postgis' or \`monetdb'"
126 echo " -db DB : the database to connect to (defaults to \`${DB}')"
127 echo " Variable for configuration file: \`DB'"
128 echo " -p PORT : the port to use for the database connection"
129 echo " : (defaults to 5432 for postgis and 50000 for monetdb)"
130 echo " Variable for configuration file: \`PORT'"
131 echo " -h HOSTNAME : the hostname to use for the database connection (defaults to \`${HOST}')"
132 echo " Variable for configuration file: \`HOST'"
133 echo " -u USERNAME : the username for the database connection"
134 echo " (defaults to \`postgres' for postgis and \`monetdb' for monetdb)"
135 echo " Variable for configuration file: \`DBUSER'"
136 echo " -pass PASS : the password for the database connection"
137 echo " (defaults to \`postgres' for postgis and \`monetdb' for monetdb)"
138 echo " Variable for configuration file: \`DBPASS'"
139 echo " -c FILE : configuration file to use for the connection (defaults to \`${STRABON_CONF}')."
140 echo " If the default configuration file exists, it is read. Options specified in the"
141 echo " command line override their values already set by the configuration file."
142 }
144 function help_query() {
145 echo "Usage: ${CMD} query [OPTIONS] SPARQL_QUERY [RESULT_FORMAT]"
146 echo
147 echo "Execute a SPARQL query on Strabon."
148 echo
149 echo " SPARQL_QUERY : the SPARQL query to execute or an alias name such as the following:"
150 echo " size: returns the number of triples"
151 echo " all: returns all triples"
152 echo " hotspots: returns the number of hotspots"
153 echo " RESULT_FORMAT : the format of the result. Possible values are \`???' (default), \`xml'"
154 echo " \`html', \`kml', \`kmz', or \`geojson'"
155 echo
156 echo "OPTIONS can be one of the following"
157 echo " --force-delete : forces deletion of \"locked\" table (e.g., when Strabon has been"
158 echo " ungracefully shutdown)"
159 }
161 function help_update() {
162 echo "Usage: ${CMD} update SPARQL_UPDATE"
163 echo
164 echo "Execute a SPARQL Update query on Strabon."
165 echo
166 echo " SPARQL_UPDATE : the SPARQL update query to execute or an alias name such as the"
167 echo " the following:"
168 echo " clear: deletes all triples"
169 }
171 function help_store() {
172 echo "Usage: ${CMD} store [OPTIONS] FILE..."
173 echo
174 echo "Store RDF documents in Strabon."
175 echo
176 echo " FILE : the file containing the RDF document to store. It can be a filename or a URL,"
177 echo " (i.e., file:///tmp/file.nt, http://www.example.org/file.nt,"
178 echo " ftp://www.example.org/file.nt, etc.)."
179 echo
180 echo "OPTIONS can be one of the following"
181 echo " -f FORMAT : the RDF format of the files to store. The format can be one of the following:"
182 echo " \`ntriples' (default), \`n3', \`rdfxml', \`turtle', or \`nquads'."
183 echo " -g NAMED_GRAPH : the URI of the named graph into which the RDF files shall be stored"
184 echo " (defaults to the default graph)."
185 echo " --inference : enables inference."
186 }
188 function help_describe() {
189 echo "Usage: ${CMD} describe DESCRIBE_QUERY [RESULT_FORMAT]"
190 echo
191 echo "Execute a SPARQL DESCRIBE query on Strabon."
192 echo
193 echo " DESCRIBE_QUERY : the SPARQL DESCRIBE query to execute or an alias name such as the following:"
194 echo " export: returns all triples stored in the database"
195 echo " RESULT_FORMAT : the format of the result. Possible values are \`N-Triples', "
196 echo " \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
197 echo " (defaults to N-Triples)"
198 }
200 # read configuration script first
201 if test -e "${STRABON_CONF}"; then
202 . ${STRABON_CONF}
203 fi
205 if ${DEBUG}; then
206 echo "${CMD}: debug is ON (from configuration file ${STRABON_CONF})"
207 fi
209 # read script options
210 while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
211 case "${1}" in
212 --help)
213 help
214 exit 0
215 ;;
216 -d)
217 shift
218 if ! ${DEBUG}; then
219 echo "${CMD}: debug is ON"
220 fi
221 DEBUG=true
222 DEBUG_SAVE=true
223 ;;
224 -m)
225 if ! ${MEMORY_INCREASED}; then
226 JAVA_OPTS="${JAVA_OPTS} ${MORE_MEMORY}"
227 MEMORY_INCREASED=true
228 else
229 echo "${CMD}: memory has already been increased; option \`${1}' will be ignored."
230 fi
231 shift
232 ;;
233 -M)
234 if ! ${MEMORY_INCREASED}; then
235 JAVA_OPTS="${JAVA_OPTS} ${MMORE_MEMORY}"
236 MEMORY_INCREASED=true
237 else
238 echo "${CMD}: memory has already been increased; option \`${1}' will be ignored."
239 fi
240 shift
241 ;;
242 -MM)
243 shift
244 if ! test $# -gt 1; then
245 help
246 exit 1
247 fi
248 MULT=${1}
250 if ! ${MEMORY_INCREASED}; then
251 JAVA_OPTS="${JAVA_OPTS} -Xms512M -Xmx$((${MULT}*${BASE_MEMORY}))M"
252 MEMORY_INCREASED=true
253 else
254 echo "${CMD}: memory has already been increased; option \`${1}' will be ignored."
255 fi
256 shift
257 ;;
258 -i)
259 shift
260 PREFIXES="$(cat ${PREFIXES_FILE})
261 "
262 ;;
263 -e)
264 shift
265 if ! test $# -gt 1; then
266 help
267 exit 1
268 fi
270 DATABASE=${1}
271 case "${DATABASE}" in
272 monetdb|postgis)
273 shift
274 ;;
275 postgis)
276 shift
277 ;;
278 *)
279 echo "${CMD}: invalid database engine"
280 echo "${CMD}: valid database engines are \`postgis' or \`monetdb'"
281 exit 2
282 ;;
283 esac
284 ;;
285 -db)
286 shift
287 if ! test $# -gt 1; then
288 help
289 exit 1
290 fi
291 DB="${1}"
292 shift
293 ;;
294 -p)
295 shift
296 if ! test $# -gt 1; then
297 help
298 exit 1
299 fi
300 PORT=${1}
301 shift
302 ;;
303 -h)
304 shift
305 if ! test $# -gt 1; then
306 help
307 exit 1
308 fi
309 HOST=${1}
310 shift
311 ;;
312 -u)
313 shift
314 if ! test $# -gt 1; then
315 help
316 exit 1
317 fi
318 DBUSER=${1}
319 shift
320 ;;
321 -pass)
322 shift
323 if ! test $# -gt 1; then
324 help
325 exit 1
326 fi
327 DBPASS=${1}
328 shift
329 ;;
330 -c)
331 shift
332 if ! test $# -gt 1; then
333 help
334 exit 1
335 fi
337 STRABON_CONF="${1}"
338 if ! test -e "${STRABON_CONF}"; then
339 echo "${CMD}: configuration file \"${1}\" does not exist"
340 exit 1
341 else
342 # if true, then debug has been set ON in command line
343 if $DEBUG; then
344 echo "${CMD}: Reading configuration file \"${STRABON_CONF}\""
345 fi
347 . ${STRABON_CONF}
349 if $DEBUG_SAVE; then
350 # restore debug value set on command line
351 DEBUG=true
352 fi
353 shift
354 fi
355 ;;
356 -*)
357 echo "${CMD}: unknown option \"${1}\""
358 help
359 exit 1
360 ;;
361 esac
362 done
364 # set defaults
365 case "${DATABASE}" in
366 postgis)
367 if test -z "${PORT}";
368 then
369 PORT=5432
370 fi
372 if test -z "${DBUSER}";
373 then
374 DBUSER="postgres"
375 fi
377 if test -z "${DBPASS}";
378 then
379 DBPASS="postgres"
380 fi
381 ;;
382 monetdb)
383 if test -z "${PORT}";
384 then
385 PORT=50000
386 fi
388 if test -z "${DBUSER}";
389 then
390 DBUSER="monetdb"
391 fi
393 if test -z "${DBPASS}";
394 then
395 DBPASS="monetdb"
396 fi
397 ;;
398 esac
400 # print configuration/options
401 if ${DEBUG}; then
402 echo "${CMD}: printing database connection details"
403 echo " Database Engine : ${DATABASE}"
404 echo " Database Name : ${DB}"
405 echo " Hostname : ${HOST}"
406 echo " Port : ${PORT}"
407 echo " Username : ${DBUSER}"
408 echo " Password : ${DBPASS}"
409 fi
411 # determine command to execute
412 case "${1}" in
413 help)
414 shift
415 if test $# -ge 1; then
416 case "${1}" in
417 query)
418 help_query
419 ;;
420 update)
421 help_update
422 ;;
423 store)
424 help_store
425 ;;
426 describe)
427 help_describe
428 ;;
429 *)
430 help
431 ;;
432 esac
433 exit 1
434 fi
435 help
436 exit 0
437 ;;
438 query)
439 CLASS="QueryOp"
440 shift
441 if ! test $# -ge 1; then
442 help_query
443 exit 1
444 fi
446 # check whether force deletion of locked table has been specified
447 if test "${1}" = "--force-delete"; then
448 shift
449 FORCE_DELETE="true"
450 fi
452 QUERY="${1}"
453 shift
455 # check for predefined queries
456 case "${QUERY}" in
457 size)
458 QUERY="${QUERY_SIZE}"
459 ;;
460 hotspots)
461 QUERY="${QUERY_HOTSPOT_SIZE}"
462 ;;
463 all)
464 QUERY="${QUERY_GETALL}"
465 ;;
466 esac
468 # check for format of result
469 if test $# -gt 0; then
470 RESULT_FORMAT="${1}"
471 shift
472 case "${RESULT_FORMAT}" in
473 [xX][mM][lL]|[hH][tT][mM][lL]|[kK][mM][lL]|[kK][mM][zZ]|[gG][eE][oO][jJ][sS][oO][nN]|[tT][sS][vV]|[eE][xX][pP])
474 ;;
475 *)
476 echo "${CMD}: invalid result format \"${RESULT_FORMAT}\""
477 echo "${CMD}: valid formats are \`???' (default), \`xml', \`html', \`kml', \`kmz', or \`geojson'"
478 exit 2
479 ;;
480 esac
481 fi
482 ;;
483 update)
484 CLASS="UpdateOp"
485 shift
486 if ! test $# -eq 1; then
487 help_update
488 exit 1
489 fi
490 QUERY="${1}"
492 # check for predefined queries
493 case "${QUERY}" in
494 clear)
495 QUERY="${QUERY_DELETEALL}"
496 ;;
497 esac
498 ;;
499 store)
500 CLASS="StoreOp"
501 shift
502 if ! test $# -ge 1; then
503 help_store
504 exit 1
505 fi
507 while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
508 # check whether format is specified
509 if test "${1}" = "-f"; then
510 shift
511 if ! test $# -ge 1; then
512 echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', \`turtle', or \`nquads')"
513 exit 2
514 else
515 FORMAT="${1}"
516 case "${FORMAT}" in
517 [nN][tT][rR][iI][pP][lL][eE][sS]|[nN]3|[rR][dD][fF][xX][mM][lL]|[tT][uU][rR][tT][lL][eE]|[nN][qQ][uU][aA][dD][sS])
518 shift
519 ;;
520 *)
521 echo "${CMD}: invalid RDF format \"${FORMAT}\"."
522 echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'"
523 exit 2
524 ;;
525 esac
526 fi
527 fi
529 # check whether a named graph is specified
530 if test "${1}" = "-g"; then
531 shift
532 if ! test $# -ge 1; then
533 echo "${CMD}: Option -g requires a URI argument"
534 exit 2
535 else
536 NAMED_GRAPH="-g ${1}"
537 shift
538 fi
539 fi
541 # check whether inference is enabled
542 if test "${1}" = "--inference"; then
543 shift
544 INFERENCE="-i true"
545 fi
547 done
549 # if no files are given
550 if ! test $# -ge 1; then
551 help_store
552 exit 1
553 fi
555 # do not make an assignment of the files to QUERY
556 # handle the case of storing multiple files afterwards
557 # QUERY="${@}"
558 ;;
559 describe)
560 CLASS="DescribeOp"
561 shift
562 if ! test $# -ge 1; then
563 help_describe
564 exit 1
565 fi
566 QUERY="${1}"
567 shift
569 # check for predefined queries
570 case "${QUERY}" in
571 export)
572 QUERY="${QUERY_EXPORT}"
573 ;;
574 esac
576 # check for format of result
577 if test $# -gt 0; then
578 RESULT_FORMAT="${1}"
579 shift
580 case "${RESULT_FORMAT}" in
581 N-Triples|RDF/XML|N3|TURTLE|TRIG|TRIX|BinaryRDF)
582 ;;
583 *)
584 echo "${CMD}: invalid result format \"${RESULT_FORMAT}\""
585 echo "${CMD}: valid formats are \`N-Triples', \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
586 exit 2
587 ;;
588 esac
589 fi
590 ;;
591 "")
592 help
593 exit 1
594 ;;
595 *)
596 help
597 echo
598 echo "${CMD}: unknown command \"${1}\"."
599 exit 1
600 ;;
601 esac
603 # compile command to execute
604 if test "${CLASS}" = "StoreOp"; then
605 STRABON_EXEC=
606 for file in "${@}"; do
607 # check whether a relative path was given
608 if ! test "${file:0:7}" == "file://" -o "${file:0:7}" == "http://" -o "${file:0:1}" == "/"; then
609 file="$(pwd)/${file}"
610 fi
612 STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\" -f ${FORMAT} ${NAMED_GRAPH} ${INFERENCE});
613 "
614 done
615 elif test "${CLASS}" = "QueryOp"; then
616 STRABON_EXEC="(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${PREFIXES}${QUERY}\" ${FORCE_DELETE} ${RESULT_FORMAT})"
617 else
618 STRABON_EXEC="(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${PREFIXES}${QUERY}\" ${RESULT_FORMAT})"
619 fi
621 # execute command or debug
622 if ${DEBUG}; then
623 echo "${CMD}: printing command for execution"
624 echo "${STRABON_EXEC}"
625 else
626 eval "${STRABON_EXEC}"
627 fi