Strabon

changeset 480:7bad4b0576f9

introduced "describe" command to strabon script and made FORMAT argument of DescribeOp optional.
author Babis Nikolaou <charnik@di.uoa.gr>
date Fri Jul 20 15:12:53 2012 +0300 (2012-07-20)
parents ccc5a44197a9
children f5b680870bd5
files runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java scripts/strabon
line diff
     1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jul 20 14:50:10 2012 +0300
     1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jul 20 15:12:53 2012 +0300
     1.3 @@ -43,6 +43,8 @@
     1.4  import org.slf4j.Logger;
     1.5  import org.slf4j.LoggerFactory;
     1.6  
     1.7 +import eu.earthobservatory.utils.RDFHandlerFactory;
     1.8 +
     1.9  public abstract class Strabon {
    1.10  
    1.11  	private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.generaldb.Strabon.class);
    1.12 @@ -440,8 +442,7 @@
    1.13  		logger.info("[Strabon.describe] Executing DESCRIBE query:" + describeString);
    1.14  
    1.15  		try {
    1.16 -			RDFHandler rdfHandler = new NTriplesWriter(out);
    1.17 -			graphQuery.evaluate(rdfHandler);
    1.18 +			graphQuery.evaluate(RDFHandlerFactory.createRDFHandler(format, out));
    1.19  
    1.20  		} catch (Exception e) {
    1.21  			logger.error("[Strabon.describe]", e);
     2.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java	Fri Jul 20 14:50:10 2012 +0300
     2.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/DescribeOp.java	Fri Jul 20 15:12:53 2012 +0300
     2.3 @@ -14,8 +14,8 @@
     2.4  	 */
     2.5  	public static void main(String[] args) {
     2.6  
     2.7 -		if (args.length < 7) {
     2.8 -			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> <FORMAT>");
     2.9 +		if (args.length < 6) {
    2.10 +			System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> [<FORMAT>]");
    2.11  			System.err.println("       where <HOST>       is the postgis database host to connect to");
    2.12  			System.err.println("             <PORT>       is the port to connect to on the database host");		
    2.13  			System.err.println("             <DATABASE>   is the spatially enabled postgis database that Strabon will use as a backend, ");
    2.14 @@ -32,7 +32,10 @@
    2.15  		String user = args[3];
    2.16  		String passwd = args[4];		
    2.17  		String queryString = args[5];
    2.18 -		String format = args[6];
    2.19 +		String format = null;
    2.20 +		if (args.length == 7) {
    2.21 +			format = args[6];
    2.22 +		}
    2.23  		
    2.24  		Strabon strabon = null;
    2.25  		try {
     3.1 --- a/scripts/strabon	Fri Jul 20 14:50:10 2012 +0300
     3.2 +++ b/scripts/strabon	Fri Jul 20 15:12:53 2012 +0300
     3.3 @@ -1,7 +1,7 @@
     3.4  #!/bin/bash
     3.5  #
     3.6  # Script for running the main classes of Strabon. The main classes of Strabon comprises
     3.7 -# QueryOp, , UpdateOp, and StoreOp.
     3.8 +# QueryOp, , UpdateOp, StoreOp, and  DescribeOp.
     3.9  #
    3.10  # Author: Charalampos (Babis) Nikolaou <charnik@di.uoa.gr>
    3.11  #
    3.12 @@ -66,9 +66,9 @@
    3.13  function help() {
    3.14  	echo "Usage: ${CMD} [OPTIONS] COMMAND ARGS"
    3.15  	echo
    3.16 -	echo "Interface to execute the main classes of Strabon, such as QueryOp, StoreOp, UpdateOp, etc."
    3.17 +	echo "Interface to execute the main classes of Strabon, such as QueryOp, StoreOp, UpdateOp, DescribeOp, etc."
    3.18  	echo
    3.19 -	echo "	COMMAND	 : one of \`query', \`update', \`store', or \`help'"
    3.20 +	echo "	COMMAND	 : one of \`query', \`update', \`store', \`describe', or \`help'"
    3.21  	echo "	ARGS	 : arguments according to selected command"
    3.22  	echo
    3.23  	echo "OPTIONS can be any of the following (variable names and values are case sensitive)"
    3.24 @@ -104,7 +104,7 @@
    3.25  	echo "	SPARQL_QUERY	: the SPARQL query to execute or an alias name such as the following:"
    3.26  	echo "				size: returns the number of triples"
    3.27  	echo "				hotspots: returns the number of hotspots"
    3.28 -	echo "  RESULT_FROM	: the format of the result. Possible values are \`???' (default), \`xml'"
    3.29 +	echo "  RESULT_FORMAT	: the format of the result. Possible values are \`???' (default), \`xml'"
    3.30  	echo "			  \`html', \`kml', \`kmz', or \`geojson'"
    3.31  }
    3.32  
    3.33 @@ -132,6 +132,16 @@
    3.34  	echo "		    \`ntriples' (default), \`n3', \`rdfxml', or \`turtle'."
    3.35  }
    3.36  
    3.37 +function help_describe() {
    3.38 +	echo "Usage: ${CMD} describe DESCRIBE_QUERY [RESULT_FORMAT]"
    3.39 +	echo
    3.40 +	echo "Execute a SPARQL DESCRIBE query on Strabon."
    3.41 +	echo
    3.42 +	echo "	DESCRIBE_QUERY	: the SPARQL DESCRIBE query to execute"
    3.43 +	echo "	RESULT_FORMAT	: the format of the result. Possible values are \`N-Triples', "
    3.44 +	echo "			  \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
    3.45 +	echo "			  (defaults to N-Triples)"
    3.46 +}
    3.47  
    3.48  # read configuration script first
    3.49  if test -e "${STRABON_CONF}"; then
    3.50 @@ -320,6 +330,9 @@
    3.51  				store)
    3.52  					help_store
    3.53  					;;
    3.54 +				describe)
    3.55 +					help_describe
    3.56 +					;;
    3.57  				*)
    3.58  					help
    3.59  					;;
    3.60 @@ -416,6 +429,31 @@
    3.61  		# handle the case of storing multiple files afterwards
    3.62  		# QUERY="${@}"
    3.63  		;;
    3.64 +	describe)
    3.65 +		CLASS="DescribeOp"
    3.66 +		shift
    3.67 +		if ! test $# -ge 1; then
    3.68 +			help_describe
    3.69 +			exit 1
    3.70 +		fi
    3.71 +		QUERY="${1}"
    3.72 +		shift
    3.73 +
    3.74 +		# check for format of result
    3.75 +		if test $# -gt 0; then
    3.76 +			RESULT_FORMAT="${1}"
    3.77 +			shift
    3.78 +			case "${RESULT_FORMAT}" in
    3.79 +				N-Triples|RDF/XML|N3|TURTLE|TRIG|TRIX|BinaryRDF)
    3.80 +				;;
    3.81 +			*)
    3.82 +				echo "${CMD}: invalid result format \"${RESULT_FORMAT}\""
    3.83 +				echo "${CMD}: valid formats are \`N-Triples', \`RDM/XML', \`N3', \`TURTLE', \`TRIG', \`TRIX', and \`BinaryRDF'"
    3.84 +				exit 2
    3.85 +				;;
    3.86 +			esac
    3.87 +		fi
    3.88 +		;;
    3.89  	"")
    3.90  		help
    3.91  		exit 1