Strabon

changeset 268:76fbd580acdb

added result format options (KML, GEOJSON, etc.). However, did not manage to get an answer different than XML. Someone should check it.
author Babis Nikolaou <charnik@di.uoa.gr>
date Sat Jun 09 18:00:32 2012 +0300 (2012-06-09)
parents e9480d82ab2f
children 7c16c1e29945
files scripts/endpoint
line diff
     1.1 --- a/scripts/endpoint	Sat Jun 09 17:47:19 2012 +0300
     1.2 +++ b/scripts/endpoint	Sat Jun 09 18:00:32 2012 +0300
     1.3 @@ -6,8 +6,11 @@
     1.4  # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
     1.5  #
     1.6  
     1.7 +# this command
     1.8 +CMD="$(basename ${0})"
     1.9 +
    1.10  function help() {
    1.11 -	echo "Usage: `basename ${0}` [OPTIONS] COMMAND ENDPOINT ARGS"
    1.12 +	echo "Usage: ${CMD} [OPTIONS] COMMAND ENDPOINT ARGS"
    1.13  	echo
    1.14  	echo "Execute SPARQL and SPARQL Update queries as well as store RDF triples on a Strabon endpoint."
    1.15  	echo
    1.16 @@ -20,16 +23,18 @@
    1.17  }
    1.18  
    1.19  function help_query() {
    1.20 -	echo "Usage: `basename ${0}` query ENDPOINT SPARQL_QUERY"
    1.21 +	echo "Usage: ${CMD} query ENDPOINT SPARQL_QUERY [RESULT_FORMAT]"
    1.22  	echo
    1.23 -	echo "	ENDPOINT     : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
    1.24 -	echo "	SPARQL_QUERY : the SPARQL query to execute or the alias name corresponding to a"
    1.25 -	echo "		       predefined query such as:"
    1.26 +	echo "	ENDPOINT	: the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
    1.27 +	echo "	SPARQL_QUERY	: the SPARQL query to execute or the alias name corresponding to a"
    1.28 +	echo "			  predefined query such as:"
    1.29  	echo "				\`size': SELECT (count(*) as ?c) WHERE {?s ?p ?o}"
    1.30 +	echo "	RESULT_FORMAT	: the format of the result. Possible values are \`KMLMAP\, \`GEOJSON', "
    1.31 +	echo "			  \`HTML', \`KMZMAP', \`XML' (default), or \`KML'."
    1.32  }
    1.33  
    1.34  function help_update() {
    1.35 -	echo "Usage: `basename ${0}` update ENDPOINT SPARQL_QUERY"
    1.36 +	echo "Usage: ${CMD} update ENDPOINT SPARQL_QUERY"
    1.37  	echo
    1.38  	echo "	ENDPOINT     : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
    1.39  	echo "	SPARQL_QUERY : the SPARQL update query to execute or the alias name corresponding to a"
    1.40 @@ -38,7 +43,7 @@
    1.41  }
    1.42  
    1.43  function help_store() {
    1.44 -	echo "Usage: `basename ${0}` store ENDPOINT FORMAT -t TRIPLES|-u TRIPLES_URL"
    1.45 +	echo "Usage: ${CMD} store ENDPOINT FORMAT -t TRIPLES|-u TRIPLES_URL"
    1.46  	echo
    1.47  	echo "	ENDPOINT    : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
    1.48  	echo "	FORMAT	    : the RDF format of the input (one of RDF/XML, N-Triples, Turtle, N3, TriX, TriG, or BinaryRDF)"
    1.49 @@ -83,13 +88,15 @@
    1.50  		;;
    1.51  	query)
    1.52  		shift
    1.53 -		if ! test $# -eq 2; then
    1.54 +		if ! test $# -ge 2; then
    1.55  			help_query
    1.56  			exit 1
    1.57  		fi
    1.58  		URL="${1}/Query"
    1.59  		QUERY="${2}"
    1.60  
    1.61 +		shift
    1.62 +		shift
    1.63  		# predefined queries
    1.64  		case "${QUERY}" in
    1.65  			size)
    1.66 @@ -97,10 +104,24 @@
    1.67  				;;
    1.68  		esac
    1.69  
    1.70 -		# TODO: make it an argument
    1.71 +		# set default format
    1.72  		FORMAT="XML"
    1.73 +		if test $# -eq 1; then
    1.74 +			FORMAT="${1}"
    1.75 +		fi
    1.76  
    1.77 -		CMD="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.78 +		case "${FORMAT}" in
    1.79 +			[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])
    1.80 +				shift
    1.81 +				;;
    1.82 +			*)
    1.83 +				echo "${CMD}: unknown format \"${FORMAT}\"."
    1.84 +				echo "${CMD}: possible values are \`KMLMAP\, \`GEOJSON' \`HTML', \`KMZMAP', \`XML' (default), or \`KML'"
    1.85 +				exit 2
    1.86 +				;;
    1.87 +		esac
    1.88 +
    1.89 +		EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.90  		;;
    1.91  	update)
    1.92  		shift
    1.93 @@ -118,7 +139,7 @@
    1.94  				;;
    1.95  		esac
    1.96  
    1.97 -		CMD="curl ${CURL_OPTS} --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.98 +		EXEC="curl ${CURL_OPTS} --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.99  		;;
   1.100  	store)
   1.101  		shift
   1.102 @@ -131,11 +152,11 @@
   1.103  		case "${3}" in
   1.104  			-t)
   1.105  				TRIPLES="${4}"
   1.106 -				CMD="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode data='${TRIPLES}' ${URL}"
   1.107 +				EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode data='${TRIPLES}' ${URL}"
   1.108  				;;
   1.109  			-u)
   1.110  				URL_TRIPLES="${4}"
   1.111 -				CMD="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode url='${URL_TRIPLES}' -d fromurl='' ${URL}"
   1.112 +				EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode url='${URL_TRIPLES}' -d fromurl='' ${URL}"
   1.113  				;;
   1.114  			 *)
   1.115  				help_store
   1.116 @@ -146,17 +167,17 @@
   1.117  	*) 
   1.118  		help
   1.119  		echo
   1.120 -		echo "ERROR: Unknown command \"${1}\"."
   1.121 +		echo "${CMD}: unknown command \"${1}\"."
   1.122  		exit 1
   1.123  		;;
   1.124  esac
   1.125  
   1.126  # execute or debug
   1.127  if test $DEBUG -eq 1; then
   1.128 -	echo "`basename ${0}`: Debug is ON"
   1.129 -	echo "`basename ${0}`: Printing command for execution"	
   1.130 -	echo "	$CMD"
   1.131 +	echo "${CMD}: Debug is ON"
   1.132 +	echo "${CMD}: Printing command for execution"	
   1.133 +	echo "	$EXEC"
   1.134  else
   1.135 -	eval ${CMD}
   1.136 +	eval ${EXEC}
   1.137  fi
   1.138