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