Strabon

view scripts/strabon @ 934:ee65be1e0648

Modified the version of each artifact from xx.xx.xx-SNAPSHOT to xx.xx.xx-BranchName-SNAPSHOT.
As a result, each branch produces its own artifacts that are independent from the artifacts produced by different branches.

NOTE: After updating the source code of Strabon to the current revision, you need to update the eclipse projects to use the new pom.xml files.
author Kostis Kyzirakos <kkyzir@di.uoa.gr>
date Wed Mar 27 12:24:59 2013 +0200 (2013-03-27)
parents 0a6878442590 215b5e9647ca
children a1e2561b7c2c
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 # the URI of the named graph into which the RDF files shall be stored
59 NAMED_GRAPH=
61 # predefined queries
62 QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}"
63 QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
64 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>}"
65 QUERY_EXPORT="CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}"
67 # debug option for log4j configuration:
68 #-Dlog4j.debug
69 #-Dlog4j.configuration=\"${RUNTIME}/log4j.properties\"
71 # further options for java
72 JAVA_OPTS=
74 # base max memory memory
75 BASE_MEMORY=1024
77 # more memory
78 MORE_MEMORY="-Xms512M -Xmx1024M"
80 # much more memory
81 MMORE_MEMORY="-Xms8192M -Xmx16384M"
83 # flag for not setting the memory limit more than once
84 MEMORY_INCREASED=false
86 # just print what shall be executed
87 DEBUG=false
89 # if true, DEBUG has been set in command line,
90 # so it must not be overidden
91 DEBUG_SAVE=false
93 # Filename containing the prefixes to be included in SPARQL queries
94 PREFIXES_FILE="${LOC}/prefixes.sparql"
96 # configuration file for the Strabon connection
97 STRABON_CONF="${HOME}/.strabon"
99 function help() {
100 echo "Usage: ${CMD} [OPTIONS] COMMAND ARGS"
101 echo
102 echo "Interface to execute the main classes of Strabon, such as QueryOp, StoreOp, UpdateOp, DescribeOp, etc."
103 echo
104 echo " COMMAND : one of \`query', \`update', \`store', \`describe', or \`help'"
105 echo " ARGS : arguments according to selected command"
106 echo
107 echo "OPTIONS can be any of the following (variable names and values are case sensitive)"
108 echo " -d : don't run, just print what shall be executed"
109 echo " Variable for configuration file: \`DEBUG'"
110 echo " Values: \`true' or \`false'"
111 echo " -m : use more memory \`${MORE_MEMORY}' (useful in \"out of memory exceptions\")"
112 echo " -M : use much more memory \`${MMORE_MEMORY}' (useful in \"out of memory exceptions\")"
113 echo " -MM MULT : use MULT * ${BASE_MEMORY} MB of memory (useful in \"out of memory exceptions\")"
114 echo " -i : include URI prefixes in the SPARQL query. Prefixes are taken from file"
115 echo " \`prefixes.sparql'"
116 echo " -e DATABASE : the database engine to connect (one of \`postgis' (default) or \`monetdb')"
117 echo " Variable for configuration file: \`DATABASE'"
118 echo " Values: \`postgis' or \`monetdb'"
119 echo " -db DB : the database to connect to (defaults to \`${DB}')"
120 echo " Variable for configuration file: \`DB'"
121 echo " -p PORT : the port to use for the database connection"
122 echo " : (defaults to 5432 for postgis and 50000 for monetdb)"
123 echo " Variable for configuration file: \`PORT'"
124 echo " -h HOSTNAME : the hostname to use for the database connection (defaults to \`${HOST}')"
125 echo " Variable for configuration file: \`HOST'"
126 echo " -u USERNAME : the username for the database connection"
127 echo " (defaults to \`postgres' for postgis and \`monetdb' for monetdb)"
128 echo " Variable for configuration file: \`DBUSER'"
129 echo " -pass PASS : the password for the database connection"
130 echo " (defaults to \`postgres' for postgis and \`monetdb' for monetdb)"
131 echo " Variable for configuration file: \`DBPASS'"
132 echo " -c FILE : configuration file to use for the connection (defaults to \`${STRABON_CONF}')."
133 echo " If the default configuration file exists, it is read. Options specified in the"
134 echo " command line override their values already set by the configuration file."
135 }
137 function help_query() {
138 echo "Usage: ${CMD} query SPARQL_QUERY [RESULT_FORMAT]"
139 echo
140 echo "Execute a SPARQL query on Strabon."
141 echo
142 echo " SPARQL_QUERY : the SPARQL query to execute or an alias name such as the following:"
143 echo " size: returns the number of triples"
144 echo " hotspots: returns the number of hotspots"
145 echo " RESULT_FORMAT : the format of the result. Possible values are \`???' (default), \`xml'"
146 echo " \`html', \`kml', \`kmz', or \`geojson'"
147 }
149 function help_update() {
150 echo "Usage: ${CMD} update SPARQL_UPDATE"
151 echo
152 echo "Execute a SPARQL Update query on Strabon."
153 echo
154 echo " SPARQL_UPDATE : the SPARQL update query to execute or an alias name such as the"
155 echo " the following:"
156 echo " clear: deletes all triples"
157 }
159 function help_store() {
160 echo "Usage: ${CMD} store [OPTIONS] FILE..."
161 echo
162 echo "Store RDF documents in Strabon."
163 echo
164 echo " FILE : the file containing the RDF document to store. It can be a filename or a URL,"
165 echo " (i.e., file:///tmp/file.nt, http://www.example.org/file.nt,"
166 echo " ftp://www.example.org/file.nt, etc.)."
167 echo
168 echo "OPTIONS can be one of the following"
169 echo " -f FORMAT : the RDF format of the files to store. The format can be one of the following:"
170 echo " \`ntriples' (default), \`n3', \`rdfxml', \`turtle', or \`nquads'."
171 echo " -g NAMED_GRAPH : the URI of the named graph into which the RDF files shall be stored"
172 echo " (defaults to the default graph)."
173 }
175 function help_describe() {
176 echo "Usage: ${CMD} describe DESCRIBE_QUERY [RESULT_FORMAT]"
177 echo
178 echo "Execute a SPARQL DESCRIBE query on Strabon."
179 echo
180 echo " DESCRIBE_QUERY : the SPARQL DESCRIBE query to execute or an alias name such as the following:"
181 echo " export: returns all triples stored in the database"
182 echo " RESULT_FORMAT : the format of the result. Possible values are \`N-Triples', "
183 echo " \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
184 echo " (defaults to N-Triples)"
185 }
187 # read configuration script first
188 if test -e "${STRABON_CONF}"; then
189 . ${STRABON_CONF}
190 fi
192 if ${DEBUG}; then
193 echo "${CMD}: debug is ON (from configuration file ${STRABON_CONF})"
194 fi
196 # read script options
197 while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
198 case "${1}" in
199 --help)
200 help
201 exit 0
202 ;;
203 -d)
204 shift
205 if ! ${DEBUG}; then
206 echo "${CMD}: debug is ON"
207 fi
208 DEBUG=true
209 DEBUG_SAVE=true
210 ;;
211 -m)
212 if ! ${MEMORY_INCREASED}; then
213 JAVA_OPTS="${JAVA_OPTS} ${MORE_MEMORY}"
214 MEMORY_INCREASED=true
215 else
216 echo "${CMD}: memory has already been increased; option \`${1}' will be ignored."
217 fi
218 shift
219 ;;
220 -M)
221 if ! ${MEMORY_INCREASED}; then
222 JAVA_OPTS="${JAVA_OPTS} ${MMORE_MEMORY}"
223 MEMORY_INCREASED=true
224 else
225 echo "${CMD}: memory has already been increased; option \`${1}' will be ignored."
226 fi
227 shift
228 ;;
229 -MM)
230 shift
231 if ! test $# -gt 1; then
232 help
233 exit 1
234 fi
235 MULT=${1}
237 if ! ${MEMORY_INCREASED}; then
238 JAVA_OPTS="${JAVA_OPTS} -Xms512M -Xmx$((${MULT}*${BASE_MEMORY}))M"
239 MEMORY_INCREASED=true
240 else
241 echo "${CMD}: memory has already been increased; option \`${1}' will be ignored."
242 fi
243 shift
244 ;;
245 -i)
246 shift
247 PREFIXES="$(cat ${PREFIXES_FILE})
248 "
249 ;;
250 -e)
251 shift
252 if ! test $# -gt 1; then
253 help
254 exit 1
255 fi
257 DATABASE=${1}
258 case "${DATABASE}" in
259 monetdb|postgis)
260 shift
261 ;;
262 postgis)
263 shift
264 ;;
265 *)
266 echo "${CMD}: invalid database engine"
267 echo "${CMD}: valid database engines are \`postgis' or \`monetdb'"
268 exit 2
269 ;;
270 esac
271 ;;
272 -db)
273 shift
274 if ! test $# -gt 1; then
275 help
276 exit 1
277 fi
278 DB="${1}"
279 shift
280 ;;
281 -p)
282 shift
283 if ! test $# -gt 1; then
284 help
285 exit 1
286 fi
287 PORT=${1}
288 shift
289 ;;
290 -h)
291 shift
292 if ! test $# -gt 1; then
293 help
294 exit 1
295 fi
296 HOST=${1}
297 shift
298 ;;
299 -u)
300 shift
301 if ! test $# -gt 1; then
302 help
303 exit 1
304 fi
305 DBUSER=${1}
306 shift
307 ;;
308 -pass)
309 shift
310 if ! test $# -gt 1; then
311 help
312 exit 1
313 fi
314 DBPASS=${1}
315 shift
316 ;;
317 -c)
318 shift
319 if ! test $# -gt 1; then
320 help
321 exit 1
322 fi
324 STRABON_CONF="${1}"
325 if ! test -e "${STRABON_CONF}"; then
326 echo "${CMD}: configuration file \"${1}\" does not exist"
327 exit 1
328 else
329 # if true, then debug has been set ON in command line
330 if $DEBUG; then
331 echo "${CMD}: Reading configuration file \"${STRABON_CONF}\""
332 fi
334 . ${STRABON_CONF}
336 if $DEBUG_SAVE; then
337 # restore debug value set on command line
338 DEBUG=true
339 fi
340 shift
341 fi
342 ;;
343 -*)
344 echo "${CMD}: unknown option \"${1}\""
345 help
346 exit 1
347 ;;
348 esac
349 done
351 # set defaults
352 case "${DATABASE}" in
353 postgis)
354 if test -z "${PORT}";
355 then
356 PORT=5432
357 fi
359 if test -z "${DBUSER}";
360 then
361 DBUSER="postgres"
362 fi
364 if test -z "${DBPASS}";
365 then
366 DBPASS="postgres"
367 fi
368 ;;
369 monetdb)
370 if test -z "${PORT}";
371 then
372 PORT=50000
373 fi
375 if test -z "${DBUSER}";
376 then
377 DBUSER="monetdb"
378 fi
380 if test -z "${DBPASS}";
381 then
382 DBPASS="monetdb"
383 fi
384 ;;
385 esac
387 # print configuration/options
388 if ${DEBUG}; then
389 echo "${CMD}: printing database connection details"
390 echo " Database Engine : ${DATABASE}"
391 echo " Database Name : ${DB}"
392 echo " Hostname : ${HOST}"
393 echo " Port : ${PORT}"
394 echo " Username : ${DBUSER}"
395 echo " Password : ${DBPASS}"
396 fi
398 # determine command to execute
399 case "${1}" in
400 help)
401 shift
402 if test $# -ge 1; then
403 case "${1}" in
404 query)
405 help_query
406 ;;
407 update)
408 help_update
409 ;;
410 store)
411 help_store
412 ;;
413 describe)
414 help_describe
415 ;;
416 *)
417 help
418 ;;
419 esac
420 exit 1
421 fi
422 help
423 exit 0
424 ;;
425 query)
426 CLASS="QueryOp"
427 shift
428 if ! test $# -ge 1; then
429 help_query
430 exit 1
431 fi
432 QUERY="${1}"
433 shift
435 # check for predefined queries
436 case "${QUERY}" in
437 size)
438 QUERY="${QUERY_SIZE}"
439 ;;
440 hotspots)
441 QUERY="${QUERY_HOTSPOT_SIZE}"
442 ;;
443 esac
445 # check for format of result
446 if test $# -gt 0; then
447 RESULT_FORMAT="${1}"
448 shift
449 case "${RESULT_FORMAT}" in
450 [xX][mM][lL]|[hH][tT][mM][lL]|[kK][mM][lL]|[kK][mM][zZ]|[gG][eE][oO][jJ][sS][oO][nN]|[tT][sS][vV])
451 ;;
452 *)
453 echo "${CMD}: invalid result format \"${RESULT_FORMAT}\""
454 echo "${CMD}: valid formats are \`???' (default), \`xml', \`html', \`kml', \`kmz', or \`geojson'"
455 exit 2
456 ;;
457 esac
458 fi
459 ;;
460 update)
461 CLASS="UpdateOp"
462 shift
463 if ! test $# -eq 1; then
464 help_update
465 exit 1
466 fi
467 QUERY="${1}"
469 # check for predefined queries
470 case "${QUERY}" in
471 clear)
472 QUERY="${QUERY_DELETEALL}"
473 ;;
474 esac
475 ;;
476 store)
477 CLASS="StoreOp"
478 shift
479 if ! test $# -ge 1; then
480 help_store
481 exit 1
482 fi
484 while test $# -gt 0 -a "X${1:0:1}" == "X-"; do
485 # check whether format is specified
486 if test "${1}" = "-f"; then
487 shift
488 if ! test $# -ge 1; then
489 echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', \`turtle', or \`nquads')"
490 exit 2
491 else
492 FORMAT="${1}"
493 case "${FORMAT}" in
494 [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])
495 shift
496 ;;
497 *)
498 echo "${CMD}: invalid RDF format \"${FORMAT}\"."
499 echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'"
500 exit 2
501 ;;
502 esac
503 fi
504 fi
506 # check whether a named graph is specified
507 if test "${1}" = "-g"; then
508 shift
509 if ! test $# -ge 1; then
510 echo "${CMD}: Option -g requires a URI argument"
511 exit 2
512 else
513 NAMED_GRAPH="-g ${1}"
514 shift
515 fi
516 fi
518 done
520 # if no files are given
521 if ! test $# -ge 1; then
522 help_store
523 exit 1
524 fi
526 # do not make an assignment of the files to QUERY
527 # handle the case of storing multiple files afterwards
528 # QUERY="${@}"
529 ;;
530 describe)
531 CLASS="DescribeOp"
532 shift
533 if ! test $# -ge 1; then
534 help_describe
535 exit 1
536 fi
537 QUERY="${1}"
538 shift
540 # check for predefined queries
541 case "${QUERY}" in
542 export)
543 QUERY="${QUERY_EXPORT}"
544 ;;
545 esac
547 # check for format of result
548 if test $# -gt 0; then
549 RESULT_FORMAT="${1}"
550 shift
551 case "${RESULT_FORMAT}" in
552 N-Triples|RDF/XML|N3|TURTLE|TRIG|TRIX|BinaryRDF)
553 ;;
554 *)
555 echo "${CMD}: invalid result format \"${RESULT_FORMAT}\""
556 echo "${CMD}: valid formats are \`N-Triples', \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
557 exit 2
558 ;;
559 esac
560 fi
561 ;;
562 "")
563 help
564 exit 1
565 ;;
566 *)
567 help
568 echo
569 echo "${CMD}: unknown command \"${1}\"."
570 exit 1
571 ;;
572 esac
574 # compile command to execute
575 if test "${CLASS}" = "StoreOp"; then
576 STRABON_EXEC=
577 for file in "${@}"; do
578 # check whether a relative path was given
579 if ! test "${file:0:7}" == "file://" -o "${file:0:7}" == "http://" -o "${file:0:1}" == "/"; then
580 file="$(pwd)/${file}"
581 fi
583 STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\" -f ${FORMAT} ${NAMED_GRAPH});
584 "
585 done
586 else
587 STRABON_EXEC="(cd ${RUNTIME} && java ${JAVA_OPTS} -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${PREFIXES}${QUERY}\" ${RESULT_FORMAT})"
588 fi
590 # execute command or debug
591 if ${DEBUG}; then
592 echo "${CMD}: printing command for execution"
593 echo "${STRABON_EXEC}"
594 else
595 eval "${STRABON_EXEC}"
596 fi