Strabon
view scripts/endpoint @ 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.
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 | 52396ec09aae |
children | da14a303bf2c |
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 executing SPARQL queries and SPARQL Update queries
15 # as well as storing RDF triples on a Strabon Endpoint.
16 #
17 # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
18 #
20 # absolute directory name of this command
21 LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23 # this command
24 CMD="$(basename ${0})"
26 # Filename containing the prefixes to be included in SPARQL queries
27 PREFIXES_FILE="${LOC}/prefixes.sparql"
29 function help() {
30 echo "Usage: ${CMD} [OPTIONS] COMMAND ENDPOINT ARGS"
31 echo
32 echo "Execute SPARQL and SPARQL Update queries as well as store RDF triples on a Strabon endpoint."
33 echo
34 echo " COMMAND : one of query, queryfile, update, store, describe, or help"
35 echo " ENDPOINT : the URL of the Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint)"
36 echo " ARGS : arguments according to selected command"
37 echo
38 echo "OPTIONS can be any of the following"
39 echo " -d : don't run, just print what shall be executed"
40 echo " -i : include URI prefixes in the SPARQL query. Prefixes are taken from file"
41 echo " \`prefixes.sparql'"
42 }
44 function help_query() {
45 echo "Usage: ${CMD} query ENDPOINT SPARQL_QUERY [RESULT_FORMAT]"
46 echo
47 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
48 echo " SPARQL_QUERY : the SPARQL query to execute or the alias name corresponding to a"
49 echo " predefined query such as:"
50 echo " \`size': SELECT (count(*) as ?c) WHERE {?s ?p ?o}"
51 echo " RESULT_FORMAT : the format of the result. Possible values are \`XML' (default), \`KML', \`KMZ', \`GeoJSON', \`HTML', or \`TSV'"
52 }
54 function help_queryfile() {
55 echo "Usage: ${CMD} queryfile ENDPOINT SPARQL_QUERY_FILE [RESULT_FORMAT]"
56 echo
57 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
58 echo " SPARQL_QUERY_FILE : the file that contain the SPARQL query to execute"
59 echo " RESULT_FORMAT : the format of the result. Possible values are \`KMLMAP\, \`GEOJSON', "
60 echo " \`HTML', \`KMZMAP', \`XML' (default), or \`KML'."
61 }
63 function help_update() {
64 echo "Usage: ${CMD} update ENDPOINT SPARQL_QUERY"
65 echo
66 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
67 echo " SPARQL_QUERY : the SPARQL update query to execute or the alias name corresponding to a"
68 echo " predefined query such as:"
69 echo " \`clear': DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
70 }
72 function help_store() {
73 echo "Usage: ${CMD} store ENDPOINT FORMAT -t TRIPLES|-u TRIPLES_URL"
74 echo
75 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
76 echo " FORMAT : the RDF format of the input (one of RDF/XML, N-Triples, Turtle, N3, TriX, TriG, BinaryRDF or N-Quads)"
77 echo " TRIPLES : the RDF triples to store"
78 echo " TRIPLES_URL : the URL containing the RDF triples to store"
79 }
81 function help_describe() {
82 echo "Usage: ${CMD} describe ENDPOINT DESCRIBE_QUERY [RESULT_FORMAT]"
83 echo
84 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
85 echo " DESCRIBE_QUERY : the SPARQL DESCRIBE query to execute"
86 echo " RESULT_FORMAT : the format of the result. Possible values are \`N-Triples' (default)"
87 echo " \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
88 }
90 CURL_OPTS="-w HTTP_CODE='%{http_code}\n' -H \"Content-Type:application/x-www-form-urlencoded\" -H \"Accept:text/xml\""
92 # if set to 1, then only the command to be executed is printed
93 DEBUG=0
94 # set default limit
95 MAXLIMIT=0
96 case "${1}" in
97 -d)
98 shift
99 DEBUG=1
100 ;;
101 -i)
102 shift
103 PREFIXES="$(cat ${PREFIXES_FILE})
104 "
105 ;;
106 -l)
107 MAXLIMIT="${2}"
108 shift
109 shift
110 ;;
111 esac
113 case "${1}" in
114 help)
115 shift
116 if test $# -eq 1; then
117 case "${1}" in
118 query)
119 help_query
120 ;;
121 queryfile)
122 help_queryfile
123 ;;
124 update)
125 help_update
126 ;;
127 store)
128 help_store
129 ;;
130 describe)
131 help_describe
132 ;;
133 *)
134 help
135 ;;
136 esac
137 exit 1
138 fi
139 help
140 exit 0
141 ;;
142 query)
143 shift
144 if ! test $# -ge 2; then
145 help_query
146 exit 1
147 fi
148 URL="${1}/Query"
149 QUERY="${2}"
151 shift
152 shift
153 # predefined queries
154 case "${QUERY}" in
155 size)
156 QUERY="SELECT (count(*) as ?c) WHERE {?s ?p ?o}"
157 ;;
158 esac
160 # set default format
161 FORMAT="XML"
162 if test $# -eq 1; then
163 FORMAT="${1}"
164 fi
166 case "${FORMAT}" in
167 [Xx][Mm][Ll])
168 MIME_TYPE="application/sparql-results+xml"
169 ;;
170 [Tt][sS][vV])
171 MIME_TYPE="text/tab-separated-values"
172 ;;
173 [Kk][Mm][Ll])
174 MIME_TYPE="application/vnd.google-earth.kml+xml"
175 ;;
176 [Kk][mM][Zz])
177 MIME_TYPE="application/vnd.google-earth.kmz"
178 ;;
179 [Hh][Tt][Mm][Ll])
180 MIME_TYPE="text/html"
181 ;;
182 [Gg][Ee][Oo][Jj][Ss][Oo][Nn])
183 MIME_TYPE="application/json"
184 ;;
185 *)
186 echo "${CMD}: unknown format \"${FORMAT}\"."
187 echo "${CMD}: possible values are \`KML', \`KMZ', \`GeoJSON', \`XML' (default), \`HTML', or \`TSV'"
188 exit 2
189 ;;
190 esac
192 EXEC="curl -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode query='${QUERY}' --data maxLimit='${MAXLIMIT}' ${URL}"
193 ;;
194 queryfile)
195 shift
196 if ! test $# -ge 2; then
197 help_queryfile
198 exit 1
199 fi
201 if ! test -f ${2}; then
202 echo "${CMD}: File not found."
203 exit 2
204 fi
206 URL="${1}/Query"
207 QUERY=`cat ${2} | sed 's/\"/\\\"/g'`
209 shift
210 shift
212 # set default format
213 FORMAT="XML"
214 if test $# -eq 1; then
215 FORMAT="${1}"
216 fi
218 case "${FORMAT}" in
219 [Xx][Mm][Ll])
220 MIME_TYPE="application/sparql-results+xml"
221 ;;
222 [Tt][sS][vV])
223 MIME_TYPE="text/tab-separated-values"
224 ;;
225 [Kk][Mm][Ll])
226 MIME_TYPE="application/vnd.google-earth.kml+xml"
227 ;;
228 [Kk][mM][Zz])
229 MIME_TYPE="application/vnd.google-earth.kmz"
230 ;;
231 [Hh][Tt][Mm][Ll])
232 MIME_TYPE="text/html"
233 ;;
234 [Gg][Ee][Oo][Jj][Ss][Oo][Nn])
235 MIME_TYPE="application/json"
236 ;;
237 *)
238 echo "${CMD}: unknown format \"${FORMAT}\"."
239 echo "${CMD}: possible values are \`KML', \`KMZ', \`GeoJSON', \`XML' (default), \`HTML', or \`TSV'"
240 exit 2
241 ;;
242 esac
244 EXEC="curl -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode query='${PREFIXES}${QUERY}' ${URL}"
245 ;;
247 update)
248 shift
249 if ! test $# -eq 2; then
250 help_update
251 exit 1
252 fi
253 URL="${1}/Update"
254 QUERY="${2}"
256 # predefined queries
257 case "${QUERY}" in
258 clear)
259 QUERY="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
260 ;;
261 esac
263 EXEC="curl -u endpoint:3ndpo1nt ${CURL_OPTS} --data-urlencode query='${PREFIXES}${QUERY}' ${URL}"
264 ;;
265 store)
266 shift
267 if ! test $# -eq 4; then
268 help_store
269 exit 1
270 fi
271 URL="${1}/Store"
272 FORMAT="${2}"
273 MIME_TYPE=
274 case "${FORMAT}" in
275 N-Triples)
276 MIME_TYPE="text/plain"
277 ;;
278 RDF/XML)
279 MIME_TYPE="application/rdf+xml"
280 ;;
281 N3)
282 MIME_TYPE="text/rdf+n3"
283 ;;
284 TURTLE)
285 MIME_TYPE="text/turtle"
286 ;;
287 TRIG)
288 MIME_TYPE="application/x-trig"
289 ;;
290 TRIX)
291 MIME_TYPE="application/trix"
292 ;;
293 BinaryRDF)
294 MIME_TYPE="application/x-binary-rdf"
295 ;;
296 N-Quads)
297 MIME_TYPE="text/x-nquads"
298 ;;
299 *)
300 echo "${CMD}: unknown format \"${FORMAT}\"."
301 echo "${CMD}: possible values are \`N-Triples' (default), \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', \`BinaryRDF' and \`N-Quads'"
302 exit 2
303 ;;
304 esac
306 case "${3}" in
307 -t)
308 TRIPLES="${4}"
309 EXEC="curl -u endpoint:3ndpo1nt -w '\nHTTP_CODE=%{http_code}\n' -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode data='${TRIPLES}' ${URL}"
310 ;;
311 -u)
313 URL_TRIPLES="${4}"
314 EXEC="curl -u endpoint:3ndpo1nt -w '\nHTTP_CODE=%{http_code}\n' -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode url='${URL_TRIPLES}' -d fromurl='' ${URL}"
315 ;;
316 *)
317 help_store
318 exit 1
319 ;;
320 esac
321 ;;
322 describe)
323 shift
324 if ! test $# -ge 2; then
325 help_describe
326 exit 1
327 fi
328 URL="${1}/Describe"
329 QUERY="${2}"
331 shift
332 shift
334 # set default format
335 FORMAT="N-Triples"
336 if test $# -eq 1; then
337 FORMAT="${1}"
338 fi
340 MIME_TYPE=
341 case "${FORMAT}" in
342 N-Triples)
343 MIME_TYPE="text/plain"
344 ;;
345 RDF/XML)
346 MIME_TYPE="application/rdf+xml"
347 ;;
348 N3)
349 MIME_TYPE="text/rdf+n3"
350 ;;
351 TURTLE)
352 MIME_TYPE="text/turtle"
353 ;;
354 TRIG)
355 MIME_TYPE="application/x-trig"
356 ;;
357 TRIX)
358 MIME_TYPE="application/trix"
359 ;;
360 BinaryRDF)
361 MIME_TYPE="application/x-binary-rdf"
362 ;;
363 *)
364 echo "${CMD}: unknown format \"${FORMAT}\"."
365 echo "${CMD}: possible values are \`N-Triples' (default), \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
366 exit 2
367 ;;
368 esac
370 EXEC="curl -H 'Content-Type:application/x-www-form-urlencoded' -H 'Accept:${MIME_TYPE}' --data-urlencode query='${PREFIXES}${QUERY}' ${URL}"
371 ;;
372 *)
373 help
374 echo
375 echo "${CMD}: unknown command \"${1}\"."
376 exit 1
377 ;;
378 esac
380 # execute or debug
381 if test $DEBUG -eq 1; then
382 echo "${CMD}: Debug is ON"
383 echo "${CMD}: Printing command for execution"
384 echo " $EXEC"
385 else
386 eval "${EXEC}"
387 fi