Strabon

view scripts/archive/v2/endpoint @ 965:69a0a785ef8f

added new "constants" module with artifactId "spatial-temporal-constants" and moved GeoConstants there
author Babis Nikolaou <charnik@di.uoa.gr>
date Tue Apr 02 13:27:01 2013 +0300 (2013-04-02)
parents 088dc9156bb8
children
line source
1 #!/bin/bash
2 #
3 # Script for executing SPARQL queries and SPARQL Update queries
4 # as well as storing RDF triples on a Strabon Endpoint.
5 #
6 # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
7 #
9 # this command
10 CMD="$(basename ${0})"
12 function help() {
13 echo "Usage: ${CMD} [OPTIONS] COMMAND ENDPOINT ARGS"
14 echo
15 echo "Execute SPARQL and SPARQL Update queries as well as store RDF triples on a Strabon endpoint."
16 echo
17 echo " COMMAND : one of query, queryfile, update, store, or help"
18 echo " ENDPOINT : the URL of the Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint)"
19 echo " ARGS : arguments according to selected command"
20 echo
21 echo "OPTIONS can be any of the following"
22 echo " -d : don't run, just print what shall be executed"
23 }
25 function help_query() {
26 echo "Usage: ${CMD} query ENDPOINT SPARQL_QUERY [RESULT_FORMAT]"
27 echo
28 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
29 echo " SPARQL_QUERY : the SPARQL query to execute or the alias name corresponding to a"
30 echo " predefined query such as:"
31 echo " \`size': SELECT (count(*) as ?c) WHERE {?s ?p ?o}"
32 echo " RESULT_FORMAT : the format of the result. Possible values are \`KMLMAP\, \`GEOJSON', "
33 echo " \`HTML', \`KMZMAP', \`XML' (default), or \`KML'."
34 }
36 function help_queryfile() {
37 echo "Usage: ${CMD} queryfile ENDPOINT SPARQL_QUERY_FILE [RESULT_FORMAT]"
38 echo
39 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
40 echo " SPARQL_QUERY_FILE : the file that contain the SPARQL query to execute"
41 echo " RESULT_FORMAT : the format of the result. Possible values are \`KMLMAP\, \`GEOJSON', "
42 echo " \`HTML', \`KMZMAP', \`XML' (default), or \`KML'."
43 }
45 function help_update() {
46 echo "Usage: ${CMD} update ENDPOINT SPARQL_QUERY"
47 echo
48 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
49 echo " SPARQL_QUERY : the SPARQL update query to execute or the alias name corresponding to a"
50 echo " predefined query such as:"
51 echo " \`clear': DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
52 }
54 function help_store() {
55 echo "Usage: ${CMD} store ENDPOINT FORMAT -t TRIPLES|-u TRIPLES_URL"
56 echo
57 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
58 echo " FORMAT : the RDF format of the input (one of RDF/XML, N-Triples, Turtle, N3, TriX, TriG, or BinaryRDF)"
59 echo " TRIPLES : the RDF triples to store"
60 echo " TRIPLES_URL : the URL containing the RDF triples to store"
61 }
63 CURL_OPTS="-w HTTP_CODE='%{http_code}\n' -H \"Content-Type:application/x-www-form-urlencoded\" -H \"Accept:text/xml\""
65 # if set to 1, then only the command to be executed is printed
66 DEBUG=0
68 case "${1}" in
69 -d)
70 shift
71 DEBUG=1
72 ;;
73 esac
75 case "${1}" in
76 help)
77 shift
78 if test $# -eq 1; then
79 case "${1}" in
80 query)
81 help_query
82 ;;
83 queryfile)
84 help_queryfile
85 ;;
86 update)
87 help_update
88 ;;
89 store)
90 help_store
91 ;;
92 *)
93 help
94 ;;
95 esac
96 exit 1
97 fi
98 help
99 exit 0
100 ;;
101 query)
102 shift
103 if ! test $# -ge 2; then
104 help_query
105 exit 1
106 fi
107 URL="${1}/Query"
108 QUERY="${2}"
110 shift
111 shift
112 # predefined queries
113 case "${QUERY}" in
114 size)
115 QUERY="SELECT (count(*) as ?c) WHERE {?s ?p ?o}"
116 ;;
117 esac
119 # set default format
120 FORMAT="XML"
121 if test $# -eq 1; then
122 FORMAT="${1}"
123 fi
125 case "${FORMAT}" in
126 [Kk][Mm][Ll][Mm][Aa][Pp]|[Gg][Ee][Oo][Jj][Ss][Oo][Nn]|[Hh][Tt][Mm][Ll]|[Kk][mM][Zz][Mm][Aa][Pp]|[Xx][Mm][Ll]|[Kk][Mm][Ll])
127 shift
128 ;;
129 *)
130 echo "${CMD}: unknown format \"${FORMAT}\"."
131 echo "${CMD}: possible values are \`KMLMAP\, \`GEOJSON' \`HTML', \`KMZMAP', \`XML' (default), or \`KML'"
132 exit 2
133 ;;
134 esac
136 EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
137 ;;
138 queryfile)
139 shift
140 if ! test $# -ge 2; then
141 help_queryfile
142 exit 1
143 fi
145 if [ ! -f ${2} ];
146 then
147 echo "${CMD}: File not found."
148 exit 2
149 fi
151 URL="${1}/Query"
152 QUERY=`cat ${2} | sed 's/\"/\\\"/g'`
154 shift
155 shift
157 # set default format
158 FORMAT="XML"
159 if test $# -eq 1; then
160 FORMAT="${1}"
161 fi
163 case "${FORMAT}" in
164 [Kk][Mm][Ll][Mm][Aa][Pp]|[Gg][Ee][Oo][Jj][Ss][Oo][Nn]|[Hh][Tt][Mm][Ll]|[Kk][mM][Zz][Mm][Aa][Pp]|[Xx][Mm][Ll]|[Kk][Mm][Ll])
165 shift
166 ;;
167 *)
168 echo "${CMD}: unknown format \"${FORMAT}\"."
169 echo "${CMD}: possible values are \`KMLMAP\, \`GEOJSON' \`HTML', \`KMZMAP', \`XML' (default), or \`KML'"
170 exit 2
171 ;;
172 esac
174 EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
175 ;;
177 update)
178 shift
179 if ! test $# -eq 2; then
180 help_update
181 exit 1
182 fi
183 URL="${1}/Update"
184 QUERY="${2}"
186 # predefined queries
187 case "${QUERY}" in
188 clear)
189 QUERY="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
190 ;;
191 esac
193 EXEC="curl ${CURL_OPTS} --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
194 ;;
195 store)
196 shift
197 if ! test $# -eq 4; then
198 help_store
199 exit 1
200 fi
201 URL="${1}/Store"
202 FORMAT="${2}"
203 case "${3}" in
204 -t)
205 TRIPLES="${4}"
206 EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode data='${TRIPLES}' ${URL}"
207 ;;
208 -u)
209 URL_TRIPLES="${4}"
210 EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode url='${URL_TRIPLES}' -d fromurl='' ${URL}"
211 ;;
212 *)
213 help_store
214 exit 1
215 ;;
216 esac
217 ;;
218 *)
219 help
220 echo
221 echo "${CMD}: unknown command \"${1}\"."
222 exit 1
223 ;;
224 esac
226 # execute or debug
227 if test $DEBUG -eq 1; then
228 echo "${CMD}: Debug is ON"
229 echo "${CMD}: Printing command for execution"
230 echo " $EXEC"
231 else
232 eval ${EXEC}
233 fi