Strabon

view scripts/strabon @ 237:7f8b766725fc

added RDF formats option to strabon script when storing files
author Babis Nikolaou <charnik@di.uoa.gr>
date Sun Jun 03 15:43:31 2012 +0300 (2012-06-03)
parents deddf369e10f
children d34c1c13c48c
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 one 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"
107 case "${1}" in
108 -d)
109 shift
110 DEBUG=1
111 ;;
112 -c)
113 shift
114 if ! test $# -gt 1; then
115 help
116 exit 1
117 fi
118 STRABON_CONF="${1}"
119 if ! test -e "${STRABON_CONF}"; then
120 echo "${CMD}: configuration file \"${1}\" does not exist."
121 exit 1
122 fi
123 shift
124 ;;
125 esac
127 case "${1}" in
128 help)
129 shift
130 if test $# -ge 1; then
131 case "${1}" in
132 query)
133 help_query
134 ;;
135 update)
136 help_update
137 ;;
138 store)
139 help_store
140 ;;
141 *)
142 help
143 ;;
144 esac
145 exit 1
146 fi
147 help
148 exit 0
149 ;;
150 query)
151 CLASS="QueryOp"
152 shift
153 if ! test $# -eq 1; then
154 help_query
155 exit 1
156 fi
157 QUERY="${1}"
159 # check for predefined queries
160 case "${QUERY}" in
161 size)
162 QUERY="${QUERY_SIZE}"
163 ;;
164 esac
165 ;;
166 update)
167 CLASS="UpdateOp"
168 shift
169 if ! test $# -eq 1; then
170 help_update
171 exit 1
172 fi
173 QUERY="${1}"
175 # check for predefined queries
176 case "${QUERY}" in
177 clear)
178 QUERY="${QUERY_DELETEALL}"
179 ;;
180 esac
181 ;;
182 store)
183 CLASS="StoreOp"
184 shift
185 if ! test $# -ge 1; then
186 help_store
187 exit 1
188 fi
189 # check whether format is specified
190 if test "${1}" = "-f"; then
191 shift
192 if ! test $# -ge 1; then
193 echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', or \`turtle')."
194 exit 2
195 else
196 FORMAT="${1}"
197 case "${FORMAT}" in
198 ntriples|n3|rdfxml|turtle)
199 shift
200 ;;
201 *)
202 echo "${CMD}: invalid RDF format \"${FORMAT}\"."
203 echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'."
204 exit 2
205 ;;
206 esac
207 fi
208 fi
209 # if no files are given
210 if ! test $# -ge 1; then
211 help_store
212 exit 1
213 fi
214 # do not make an assignment of the files to QUERY
215 # handle the case of storing multiple files afterwards
216 # QUERY="${@}"
217 ;;
218 *)
219 help
220 echo
221 echo "${CMD}: unknown command \"${1}\"."
222 exit 1
223 ;;
224 esac
226 if test "${CLASS}" = "StoreOp"; then
227 STRABON_EXEC=
228 for file in "${@}"; do
229 STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\" ${FORMAT});
230 "
231 done
232 else
233 STRABON_EXEC="(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${QUERY}\")"
234 fi
236 # execute or debug
237 if test ${DEBUG} -eq 1; then
238 echo "${CMD}: Debug is ON"
239 echo "${CMD}: Printing command for execution"
240 echo "${STRABON_EXEC}"
241 else
242 eval ${STRABON_EXEC}
243 fi