Strabon

changeset 237:7f8b766725fc

added RDF formats option to strabon script when storing files
author Babis Nikolaou <charnik@di.uoa.gr>
date Sun Jun 03 15:43:31 2012 +0300 (2012-06-03)
parents 54ffeb7810e0
children d34c1c13c48c
files scripts/strabon
line diff
     1.1 --- a/scripts/strabon	Sun Jun 03 15:20:44 2012 +0300
     1.2 +++ b/scripts/strabon	Sun Jun 03 15:43:31 2012 +0300
     1.3 @@ -22,9 +22,9 @@
     1.4  	echo "	COMMAND	 : one of \`query', \`update', \`store', or \`help'"
     1.5  	echo "	ARGS	 : arguments according to selected command"
     1.6  	echo
     1.7 -	echo "OPTIONS can be any of the following"
     1.8 +	echo "OPTIONS can be one of the following"
     1.9  	echo "	-d	 : don't run, just print what shall be executed"
    1.10 -	echo "	-c FILE	 : configuration file to use for the connection. It defaults to \`${HOME}/.strabon'."
    1.11 +	#echo "	-c FILE	 : configuration file to use for the connection. It defaults to \`${HOME}/.strabon'."
    1.12  }
    1.13  
    1.14  function help_query() {
    1.15 @@ -47,13 +47,17 @@
    1.16  }
    1.17  
    1.18  function help_store() {
    1.19 -	echo "Usage: ${CMD} store FILE..."
    1.20 +	echo "Usage: ${CMD} store [OPTIONS] FILE..."
    1.21  	echo
    1.22  	echo "Store RDF documents in Strabon."
    1.23  	echo
    1.24  	echo "	FILE	: the file containing the RDF document to store. It can be a filename or a URL,"
    1.25  	echo "		  (i.e., file:///tmp/file.nt, http://www.example.org/file.nt,"
    1.26  	echo "		  ftp://www.example.org/file.nt, etc.)."
    1.27 +	echo 
    1.28 +	echo "OPTIONS can be one of the following"
    1.29 +	echo "	-f FORMAT : the RDF format of the files to store. The format can be one of the following:"
    1.30 +	echo "		    \`ntriples' (default), \`n3', \`rdfxml', or \`turtle'."
    1.31  }
    1.32  
    1.33  # runtime package
    1.34 @@ -84,6 +88,9 @@
    1.35  # the query to run
    1.36  QUERY=
    1.37  
    1.38 +# the RDF format of the files to store (defaults to ntriples)
    1.39 +FORMAT=
    1.40 +
    1.41  # predefined queries
    1.42  QUERY_SIZE="SELECT (COUNT(*) as ?C) WHERE {?s ?p ?o}"
    1.43  QUERY_DELETEALL="DELETE {?s ?p ?o} WHERE {?s ?p ?o}"
    1.44 @@ -120,7 +127,7 @@
    1.45  case "${1}" in
    1.46  	help)
    1.47  		shift
    1.48 -		if test $# -eq 1; then
    1.49 +		if test $# -ge 1; then
    1.50  			case "${1}" in
    1.51  				query)
    1.52  					help_query
    1.53 @@ -179,14 +186,39 @@
    1.54  			help_store
    1.55  			exit 1
    1.56  		fi
    1.57 +		# check whether format is specified
    1.58 +		if test "${1}" = "-f"; then
    1.59 +			shift
    1.60 +			if ! test $# -ge 1; then
    1.61 +				echo "${CMD}: Option -f requires an RDF format (\`ntriples', \`n3', \`rdfxml', or \`turtle')."
    1.62 +				exit 2
    1.63 +			else
    1.64 +				FORMAT="${1}"
    1.65 +				case "${FORMAT}" in
    1.66 +					ntriples|n3|rdfxml|turtle)
    1.67 +						shift
    1.68 +						;;
    1.69 +					*)
    1.70 +						echo "${CMD}: invalid RDF format \"${FORMAT}\"."
    1.71 +						echo "${CMD}: valid RDF formats are \`ntriples', \`n3', \`rdfxml', or \`turtle'."
    1.72 +						exit 2
    1.73 +						;;
    1.74 +				esac
    1.75 +			fi
    1.76 +		fi
    1.77 +		# if no files are given
    1.78 +		if ! test $# -ge 1; then
    1.79 +			help_store
    1.80 +			exit 1
    1.81 +		fi
    1.82  		# do not make an assignment of the files to QUERY
    1.83 -		# handle the case afterwards
    1.84 +		# handle the case of storing multiple files afterwards
    1.85  		# QUERY="${@}"
    1.86  		;;
    1.87  	*) 
    1.88  		help
    1.89  		echo
    1.90 -		echo "${CMD}: Unknown command \"${1}\"."
    1.91 +		echo "${CMD}: unknown command \"${1}\"."
    1.92  		exit 1
    1.93  		;;
    1.94  esac
    1.95 @@ -194,7 +226,7 @@
    1.96  if test "${CLASS}" = "StoreOp"; then
    1.97  	STRABON_EXEC=
    1.98  	for file in "${@}"; do
    1.99 -		STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\");
   1.100 +		STRABON_EXEC="${STRABON_EXEC}(cd ${RUNTIME} && java -cp ./target/\*:. ${PKG}.${DATABASE}.${CLASS} ${HOST} ${PORT} ${DB} ${DBUSER} ${DBPASS} \"${file}\" ${FORMAT});
   1.101  "
   1.102  	done
   1.103  else