Strabon

changeset 493:1cf4692447d2

added "-i" option to endpoint script for including prefixes in SPARQL queries
author Babis Nikolaou <charnik@di.uoa.gr>
date Mon Jul 23 15:11:51 2012 +0300 (2012-07-23)
parents 23a9e69cb926
children b51a8e33b86b
files scripts/endpoint
line diff
     1.1 --- a/scripts/endpoint	Mon Jul 23 14:30:44 2012 +0300
     1.2 +++ b/scripts/endpoint	Mon Jul 23 15:11:51 2012 +0300
     1.3 @@ -6,9 +6,15 @@
     1.4  # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
     1.5  #
     1.6  
     1.7 +# absolute directory name of this command
     1.8 +LOC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
     1.9 +
    1.10  # this command
    1.11  CMD="$(basename ${0})"
    1.12  
    1.13 +# Filename containing the prefixes to be included in SPARQL queries
    1.14 +PREFIXES_FILE="${LOC}/prefixes.sparql"
    1.15 +
    1.16  function help() {
    1.17  	echo "Usage: ${CMD} [OPTIONS] COMMAND ENDPOINT ARGS"
    1.18  	echo
    1.19 @@ -20,6 +26,8 @@
    1.20  	echo 
    1.21  	echo "OPTIONS can be any of the following"
    1.22  	echo "	-d	 : don't run, just print what shall be executed"
    1.23 +	echo "	-i	 : include URI prefixes in the SPARQL query. Prefixes are taken from file"
    1.24 +	echo "		  \`prefixes.sparql'"
    1.25  }
    1.26  
    1.27  function help_query() {
    1.28 @@ -79,6 +87,11 @@
    1.29  		shift
    1.30  		DEBUG=1
    1.31  		;;
    1.32 +	-i)
    1.33 +		shift
    1.34 +		PREFIXES="$(cat ${PREFIXES_FILE})
    1.35 +"
    1.36 +		;;
    1.37  esac
    1.38  
    1.39  case "${1}" in
    1.40 @@ -154,8 +167,7 @@
    1.41  			exit 1
    1.42  		fi
    1.43  
    1.44 -		if [ ! -f ${2} ];
    1.45 -		then
    1.46 +		if ! test -f ${2}; then
    1.47  			echo "${CMD}: File not found."
    1.48  			exit 2
    1.49  		fi
    1.50 @@ -183,7 +195,7 @@
    1.51  				;;
    1.52  		esac
    1.53  
    1.54 -		EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.55 +		EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${PREFIXES}${QUERY}' ${URL}"
    1.56  		;;
    1.57  
    1.58  	update)
    1.59 @@ -202,7 +214,7 @@
    1.60  				;;
    1.61  		esac
    1.62  
    1.63 -		EXEC="curl ${CURL_OPTS} --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.64 +		EXEC="curl ${CURL_OPTS} --data-urlencode SPARQLQuery='${PREFIXES}${QUERY}' ${URL}"
    1.65  		;;
    1.66  	store)
    1.67  		shift
    1.68 @@ -256,7 +268,7 @@
    1.69  				;;
    1.70  		esac
    1.71  
    1.72 -		EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${QUERY}' ${URL}"
    1.73 +		EXEC="curl ${CURL_OPTS} -d format='${FORMAT}' --data-urlencode SPARQLQuery='${PREFIXES}${QUERY}' ${URL}"
    1.74  		;;
    1.75  	*) 
    1.76  		help