Strabon

changeset 92:1ab50d5a58c4

added scripts/ director (the one responsible for strabon, query.sh, and query2.sh could mv them there using hg mv), added endpoint script for querying, updating, and storing RDF triples on Strabon Endpoint from the commmand line
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Apr 04 23:50:44 2012 +0300 (2012-04-04)
parents c92abb8ed523
children 369029414139
files scripts/endpoint
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/endpoint	Wed Apr 04 23:50:44 2012 +0300
     1.3 @@ -0,0 +1,101 @@
     1.4 +#!/bin/bash
     1.5 +#
     1.6 +# Script for executing SPARQL queries and SPARQL Update queries 
     1.7 +# as well as storing RDF triples on a Strabon Endpoint.
     1.8 +#
     1.9 +# Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
    1.10 +#
    1.11 +
    1.12 +function help() {
    1.13 +	echo SYNOPSIS
    1.14 +	echo "	`basename ${0}` query|update|store ARGS"
    1.15 +}
    1.16 +
    1.17 +function help_query() {
    1.18 +	echo SYNOPSIS
    1.19 +	echo "	`basename ${0}` query URL SPARQL_QUERY"
    1.20 +	echo
    1.21 +	echo "	URL	     : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
    1.22 +	echo "	SPARQL_QUERY : the SPARQL query to execute"
    1.23 +}
    1.24 +
    1.25 +function help_update() {
    1.26 +	echo SYNOPSIS
    1.27 +	echo "	`basename ${0}` update URL SPARQL_QUERY"
    1.28 +	echo
    1.29 +	echo "	URL	     : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
    1.30 +	echo "	SPARQL_QUERY : the SPARQL update query to execute"
    1.31 +}
    1.32 +
    1.33 +function help_store() {
    1.34 +	echo SYNOPSIS
    1.35 +	echo "	`basename ${0}` store URL FORMAT -t TRIPLES|-u TRIPLES_URL  "
    1.36 +	echo
    1.37 +	echo "	URL	    : the URL of Strabon Endpoint (e.g., http://localhost:8080/StrabonEndpoint/)"
    1.38 +	echo "	FORMAT	    : the RDF format of the input (one of RDF/XML, N-Triples, Turtle, N3, TriX, TriG, or BinaryRDF)"
    1.39 +	echo "	TRIPLES	    : the RDF triples to store"
    1.40 +	echo "	TRIPLES_URL : the URL containing the RDF triples to store"
    1.41 +}
    1.42 +
    1.43 +CURL_OPTS="-w HTTP_CODE=%{http_code}\n -H \"Content-Type:application/x-www-form-urlencoded\" -H \"Accept:text/xml\""
    1.44 +
    1.45 +case "${1}" in
    1.46 +	help)
    1.47 +		help
    1.48 +		exit 0
    1.49 +		;;
    1.50 +	query)
    1.51 +		shift
    1.52 +		if ! test $# -eq 2; then
    1.53 +			help_query
    1.54 +			exit 1
    1.55 +		fi
    1.56 +		URL="${1}/Query"
    1.57 +		QUERY="${2}"
    1.58 +
    1.59 +		# TODO: make it an argument
    1.60 +		FORMAT="XML"
    1.61 +
    1.62 +		curl ${CURL_OPTS} -d "format=${FORMAT}" --data-urlencode "SPARQLQuery=${QUERY}" ${URL}
    1.63 +		;;
    1.64 +	update)
    1.65 +		shift
    1.66 +		if ! test $# -eq 2; then
    1.67 +			help_update
    1.68 +			exit 1
    1.69 +		fi
    1.70 +		URL="${1}/Update"
    1.71 +		QUERY="${2}"
    1.72 +		
    1.73 +		curl ${CURL_OPTS} --data-urlencode "SPARQLQuery=${QUERY}" ${URL}
    1.74 +		;;
    1.75 +	store)
    1.76 +		shift
    1.77 +		if ! test $# -eq 4; then
    1.78 +			help_store
    1.79 +			exit 1
    1.80 +		fi
    1.81 +		URL="${1}/Store"
    1.82 +		FORMAT="${2}"
    1.83 +		case "${3}" in
    1.84 +			-t)
    1.85 +				TRIPLES="${4}"
    1.86 +				curl ${CURL_OPTS} -d "format=${FORMAT}" --data-urlencode "data=${TRIPLES}" ${URL}
    1.87 +				;;
    1.88 +			-u)
    1.89 +				URL_TRIPLES="${4}"
    1.90 +				curl ${CURL_OPTS} -d "format=${FORMAT}" --data-urlencode "url=${URL_TRIPLES}" -d "fromurl=" ${URL}
    1.91 +				;;
    1.92 +			 *)
    1.93 +				help_store
    1.94 +				exit 1
    1.95 +				;;
    1.96 +		esac
    1.97 +		;;
    1.98 +	*) 
    1.99 +		echo "ERROR: Unknown command \"${1}\"."
   1.100 +		help
   1.101 +		exit 1
   1.102 +		;;
   1.103 +esac
   1.104 +