Strabon

view scripts/strabon @ 238:d34c1c13c48c

added comments
author Babis Nikolaou <charnik@di.uoa.gr>
date Sun Jun 03 15:46:18 2012 +0300 (2012-06-03)
parents 7f8b766725fc
children 612a0ddbb147
line source
1 #!/bin/bash
2 #
3 # Script for running the main classes of Strabon. The main classes of Strabon comprises
4 # QueryOp, , UpdateOp, and StoreOp.
5 #
6 # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
7 #
9 # command name
10 CMD="$(basename ${0})"
12 # absolute directory name of this command
13 LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15 RUNTIME="${LOC}/../runtime"
17 function help() {
18 echo "Usage: ${CMD} [OPTIONS] COMMAND ARGS"
19 echo
20 echo "Interface to execute the main classes of Strabon, such as QueryOp, StoreOp, UpdateOp, etc."
21 echo
22 echo " COMMAND : one of \`query', \`update', \`store', or \`help'"
23 echo " ARGS : arguments according to selected command"
24 echo
25 echo "OPTIONS can be any of the following"
26 echo " -d : don't run, just print what shall be executed"
27 #echo " -c FILE : configuration file to use for the connection. It defaults to \`${HOME}/.strabon'."
28 }
30 function help_query() {
31 echo "Usage: ${CMD} query SPARQL_QUERY"
32 echo
33 echo "Execute a SPARQL query on Strabon."
34 echo
35 echo " SPARQL_QUERY : the SPARQL query to execute or an alias name such as the following:"
36 echo " size: returns the number of triples"
37 }
39 function help_update() {
40 echo "Usage: ${CMD} update SPARQL_UPDATE"
41 echo
42 echo "Execute a SPARQL Update query on Strabon."
43 echo
44 echo " SPARQL_UPDATE : the SPARQL update query to execute or an alias name such as the"
45 echo " the following:"
46 echo " clear: deletes all triples"
47 }
49 function help_store() {
50 echo "Usage: ${CMD} store [OPTIONS] FILE..."
51 echo
52 echo "Store RDF documents in Strabon."
53 echo
54 echo " FILE : the file containing the RDF document to store. It can be a filename or a URL,"
55 echo " (i.e., file:///tmp/file.nt, http://www.example.org/file.nt,"
56 echo " ftp://www.example.org/file.nt, etc.)."
57 echo
58 echo "OPTIONS can be one of the following"
59 echo " -f FORMAT : the RDF format of the files to store. The format can be one of the following:"
60 echo " \`ntriples' (default), \`n3', \`rdfxml', or \`turtle'."
61 }
63 # runtime package
64 PKG="eu.earthobservatory.runtime"
66 # the underlying database to use (one of postgis or monetdb)
67 DATABASE="postgis"
69 # the main class to run
70 CLASS="QueryOp"
72 # the hostname at which the database runs
73 HOST="localhost"
75 # the port at which the database listens
76 PORT=5432
78 # the database name to connect to
79 DB="endpoint"
80 DB="strabon"
82 # the username for the database connection
83 DBUSER="charnik"
85 # the password for the database connection
86 DBPASS="charnik"
88 # the query to run
89 QUERY=
91 # the RDF format of the files to store (defaults to ntriples)
92 FORMAT=
94 # predefined queries
95 QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}"
96 QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
98 # debug option for log4j configuration:
99 #-Dlog4j.debug
100 #-Dlog4j.configuration=\"${RUNTIME}/log4j.properties\"
102 # just print what shall be executed
103 DEBUG=0
105 # configuration file for the Strabon connection
106 STRABON_CONF="${HOME}/.strabon"
108 # read script options
109 case "${1}" in
110 -d)
111 shift
112 DEBUG=1
113 ;;
114 -c)
115 shift
116 if ! test $# -gt 1; then
117 help
118 exit 1
119 fi
120 STRABON_CONF="${1}"
121 if ! test -e "${STRABON_CONF}"; then
122 echo "${CMD}: configuration file \"${1}\" does not exist."
123 exit 1
124 fi
125 shift
126 ;;
127 esac
129 # determine command to execute
130 case "${1}" in
131 help)
132 shift
133 if test $# -ge 1; then
134 case "${1}" in
135 query)
136 help_query
137 ;;
138 update)
139 help_update
140 ;;
141 store)
142 help_store
143 ;;
144 *)
145 help
146 ;;
147 esac
148 exit 1
149 fi
150 help
151 exit 0
152 ;;
153 query)
154 CLASS="QueryOp"
155 shift
156 if ! test $# -eq 1; then
157 help_query
158 exit 1
159 fi
160 QUERY="${1}"
162 # check for predefined queries
163 case "${QUERY}" in
164 size)
165 QUERY="${QUERY_SIZE}"
166 ;;
167 esac
168 ;;
169 update)
170 CLASS="UpdateOp"
171 shift
172 if ! test $# -eq 1; then
173 help_update
174 exit 1
175 fi
176 QUERY="${1}"
178 # check for predefined queries
179 case "${QUERY}" in
180 clear)
181 QUERY="${QUERY_DELETEALL}"
182 ;;
183 esac
184 ;;
185 store)
186 CLASS="StoreOp"
187 shift
188 if ! test $# -ge 1; then
189 help_store
190 exit 1
191 fi
192 # check whether format is specified
193 if test "${1}" = "-f"; then
194 shift
195 if ! test $# -ge 1; then
196 echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', or \`turtle')."
197 exit 2
198 else
199 FORMAT="${1}"
200 case "${FORMAT}" in
201 ntriples|n3|rdfxml|turtle)
202 shift
203 ;;
204 *)
205 echo "${CMD}: invalid RDF format \"${FORMAT}\"."
206 echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'."
207 exit 2
208 ;;
209 esac
210 fi
211 fi
212 # if no files are given
213 if ! test $# -ge 1; then
214 help_store
215 exit 1
216 fi
217 # do not make an assignment of the files to QUERY
218 # handle the case of storing multiple files afterwards
219 # QUERY="${@}"
220 ;;
221 *)
222 help
223 echo
224 echo "${CMD}: unknown command \"${1}\"."
225 exit 1
226 ;;
227 esac
229 # compile command to execute
230 if test "${CLASS}" = "StoreOp"; then
231 STRABON_EXEC=
232 for file in "${@}"; do
233 STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\" ${FORMAT});
234 "
235 done
236 else
237 STRABON_EXEC="(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${QUERY}\")"
238 fi
240 # execute command or debug
241 if test ${DEBUG} -eq 1; then
242 echo "${CMD}: Debug is ON"
243 echo "${CMD}: Printing command for execution"
244 echo "${STRABON_EXEC}"
245 else
246 eval ${STRABON_EXEC}
247 fi