Strabon

view scripts/endpoint @ 132:6945f58b1619

Added geojson support. more tests will follow
author Manos Karpathiotakis <mk@di.uoa.gr>
date Tue May 08 17:36:10 2012 +0300 (2012-05-08)
parents b22762ef9795
children d7b2fb010f7a
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 function help() {
10 echo "Usage: `basename ${0}` [OPTIONS] COMMAND ENDPOINT ARGS"
11 echo
12 echo "Execute SPARQL and SPARQL Update queries as well as store RDF triples on a Strabon endpoint."
13 echo
14 echo " COMMAND : one of query, update, store, or help"
15 echo " ENDPOINT : the URL of the Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint)"
16 echo " ARGS : arguments according to selected command"
17 echo
18 echo "OPTIONS can be any of the following"
19 echo " -d : don't run, just print what shall be executed"
20 }
22 function help_query() {
23 echo "Usage: `basename ${0}` query ENDPOINT SPARQL_QUERY"
24 echo
25 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
26 echo " SPARQL_QUERY : the SPARQL query to execute"
27 }
29 function help_update() {
30 echo "Usage: `basename ${0}` update ENDPOINT SPARQL_QUERY"
31 echo
32 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
33 echo " SPARQL_QUERY : the SPARQL update query to execute"
34 }
36 function help_store() {
37 echo "Usage: `basename ${0}` store ENDPOINT FORMAT -t TRIPLES|-u TRIPLES_URL"
38 echo
39 echo " ENDPOINT : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
40 echo " FORMAT : the RDF format of the input (one of RDF/XML, N-Triples, Turtle, N3, TriX, TriG, or BinaryRDF)"
41 echo " TRIPLES : the RDF triples to store"
42 echo " TRIPLES_URL : the URL containing the RDF triples to store"
43 }
45 CURL_OPTS="-w HTTP_CODE='%{http_code}\n' -H \"Content-Type:application/x-www-form-urlencoded\" -H \"Accept:text/xml\""
47 # if set to 1, then only the command to be executed is printed
48 DEBUG=0
50 case "${1}" in
51 -d)
52 shift
53 DEBUG=1
54 ;;
55 esac
57 case "${1}" in
58 help)
59 shift
60 if test $# -eq 1; then
61 case "${1}" in
62 query)
63 help_query
64 ;;
65 update)
66 help_update
67 ;;
68 store)
69 help_store
70 ;;
71 *)
72 help
73 ;;
74 esac
75 exit 1
76 fi
77 help
78 exit 0
79 ;;
80 query)
81 shift
82 if ! test $# -eq 2; then
83 help_query
84 exit 1
85 fi
86 URL="${1}/Query"
87 QUERY="${2}"
89 # TODO: make it an argument
90 FORMAT="XML"
92 CMD="curl ${CURL_OPTS} -d \"format=${FORMAT}\" --data-urlencode \"SPARQLQuery=${QUERY}\" ${URL}"
93 ;;
94 update)
95 shift
96 if ! test $# -eq 2; then
97 help_update
98 exit 1
99 fi
100 URL="${1}/Update"
101 QUERY="${2}"
103 CMD="curl ${CURL_OPTS} --data-urlencode \"SPARQLQuery=${QUERY}\" ${URL}"
104 ;;
105 store)
106 shift
107 if ! test $# -eq 4; then
108 help_store
109 exit 1
110 fi
111 URL="${1}/Store"
112 FORMAT="${2}"
113 case "${3}" in
114 -t)
115 TRIPLES="${4}"
116 CMD="curl ${CURL_OPTS} -d \"format=${FORMAT}\" --data-urlencode \"data=${TRIPLES}\" ${URL}"
117 ;;
118 -u)
119 URL_TRIPLES="${4}"
120 CMD="curl ${CURL_OPTS} -d \"format=${FORMAT}\" --data-urlencode \"url=${URL_TRIPLES}\" -d \"fromurl=\" ${URL}"
121 ;;
122 *)
123 help_store
124 exit 1
125 ;;
126 esac
127 ;;
128 *)
129 help
130 echo
131 echo "ERROR: Unknown command \"${1}\"."
132 exit 1
133 ;;
134 esac
136 # execute or debug
137 if test $DEBUG -eq 1; then
138 echo "`basename ${0}`: Debug is ON"
139 echo "`basename ${0}`: Printing command for execution"
140 echo " $CMD"
141 else
142 eval ${CMD}
143 fi